Alpine local backup

Local backup utility(lbu) is the Alpine Linux tool to manage Diskless Mode installations. For these installations, lbu tool must be used whenever Alpine Package Keeper is used.
When Alpine Linux boots in diskless mode, it initially only loads a few required packages from the boot device. However, local adjustments to what-gets-loaded-into-RAM are possible, e.g. by installing a package or adjusting the configuration files in . The modifications can be saved to an overlay file (.apkovl) that can be automatically loaded when booting, to restore the saved state.
The .apkovl file that contains the custom configuration can be saved to writable storage with Alpine's local backup utility lbu. By configuring a local package cache the additional packages the configuration depends on, can also be kept available on local, writable storage.
By default, an lbu commit only stores modifications below , with the exception of the directory. If a user was created during the setup-alpine script, that user's home directory is also added to the paths that lbu will backup up. However, lbu include enables modifying that set of included files, and can be used to specify additional files or folders.
== Overview ==
The lbu tool has several subcommands to manage the .apkovl:
lbu commit 	lbu ci 	Create a backup of config to writeable media
lbu package 	lbu pkg 	Create backup package
lbu status 	lbu st 	Check what files have been changed since last commit
lbu list 	lbu ls 	Lists files that would go to tar package. Same as:
lbu diff 	 	Run a diff against last commit
lbu include 	lbu inc or lbu add 	Add filename(s) to include list
lbu exclude 	lbu ex or lbu delete	Add filename(s) to exclude list
lbu list-backup	lbu lb 	Show old commits
lbu revert 	 	Revert to older commit
In the examples below, you will find some characters with special meaning:
* | = or ('lbu commit|ci' means that you can type ether 'lbu commit' or 'lbu ci')
* [ ] = optional (In 'lbu commit|ci [-nv]' you can skip the '-n', '-v' or '-nv' part if you don't want it)
== Committing changes ==
When you "commit" or save changes you've made to your system, lbu will generate a file named something like ('myboxname' will be the same as the hostname).
The file (which contains your modifications) is called your "apkovl".
You will need to save your apkovl on suitable media (floppy, usb, cf, etc.).
usage: lbu commit|ci [-nv] [<media>]
Options:
 -d	Remove old apk overlay files.
 -e	Protect configuration with a password.
 -n	Don't commit, just show what would have been committed.
 -p <password>	Give encryption password on the command-line
 -v	Verbose mode.
The following values for <media> are supported: floppy usb
If <media> is not specified, the environment variable LBU_MEDIA will be used.
Password protection will use aes-256-cbc encryption. Other ciphers can be
used by setting the DEFAULT_CIPHER or ENCRYPTION environment variables.
For possible ciphers, try: openssl -v
The password used to encrypt the file, can be specified with the -p
option or by using the PASSWORD environment variable.
The environment variable can also be set in /etc/lbu/lbu.conf
== Creating an .apkovl "package" elsewhere than on the configured media ==
To "commit" changes, but override the destination of the generated apkovl file, use lbu package instead of lbu commit:
usage: lbu package|pkg -v [<dirname>|<filename>]
Options:
 -v Verbose mode.
If <dirname> is a directory, a package named <hostname>.apkovl.tar.gz will
be created in the specified directory.
If <filename> is specified, and is not a directory, a package with the
specified name will be created.
If neither <dirname> nor <filename> is specified, a package named
<hostname>.apkovl.tar.gz will be created in the current working directory.
=== Creating and saving an apkovl from a remote host ===
To create an apkovl from a client on a remote server, it's possible to use lbu package via SSH with as the apkovl name:
On the server:
ssh root@client "lbu package -" >client.apkovl.tar.gz
=== Saving and loading ISO image customizations ===
The content from this section has been moved here. 
== Checking what will be added to your apkovl ==
lbu status lists what will be saved the next time you run lbu commit. Its default output is incremental, that is, it shows
only the files that have changed since the last commit. 
This can be overridden with the -a flag:
usage: lbu status|st [-av]
Options:
 -a Compare all files, not just since last commit.
 -v show include and exclude lists.
Another option is lbu list. This works like lbu status -a but the format of the output is a bit different. (It's strictly equivalent to lbu package -v /dev/null).
 usage: lbu list|ls
A third option is lbu diff. This shows the same incremental changes that lbu status (without -a) does, but in a different format.
 usage: lbu diff
== Include special files/folders to the apkovl ==
Assume you have some files you want to save permanently, but they are not located in .<BR>
e.g. (used by sshd to authenticate ssh-users). Such files/folders can be added to lbu's include list with the following command:
usage: lbu include|inc|add [-rv] <file> ...
 lbu include|inc|add [-v] -l
Options:
 -l	List contents of include list.
 -r	Remove specified file(s) from include list.
 -v	Verbose mode.
== Exclude specific files/folders from the apkovl ==
Assume you have some files located in or one of its subfolders you do not want to save.
It could be a log file or status file that for some reason isn't in but in a location that would otherwise be tracked by lbu.
Such files/folders can be added to lbu's exclude list by manually editing the file or using the following command:
usage: lbu exclude|ex|delete [-rv] <file> ...
 lbu exclude|ex|delete [-v] -l
Options:
 -l	List contents of exclude list.
 -r	Remove specified file(s) from exclude list.
 -v	Verbose mode.
== Execute a script as part of a backup ==
Sometimes it's necessary to run a script before or after a backup. Scripts in two optional directories enable that:
 /etc/lbu/pre-package.d
 /etc/lbu/post-package.d
Files in those directories are run using run-script rules (meaning they must have the executable bit set, they are run in alphabetical order, and cannot contain an extension. e.g. works, but does not. Also the shebang line on the first line should be indicated, e.g. #!/bin/sh .)
The scripts in are run before apkovl is created. Scripts in are run after apkovl is created.
=== Example ===
Rather than adding the raw database directories to , you can do a "database dump". e.g. :
* Create with the following contents: pg_dumpall -U postgres | gzip -c >/root/pgdatabases.gz
* Mark the file executable: chmod +x /etc/lbu/pre-package.d/sqldump
* Create with the following contents: rm -f /root/pgdatabases.gz
* Mark the file executable: chmod +x /etc/lbu/post-package.d/sqldumpdelete
* Finally, add the database dump file to the list of files to back up: lbu include root/pgdatabases.gz
Now when you do a lbu commit, the sql databases are dumped and gzipped to .
The temporary file is deleted at the end of the lbu commit.
On a catastrophic restore, the databases are not automatically restored (that's not lbu's job), but you will find a complete database dump in the directory, where it can be restored manually.
P.s. These scripts are also launched when starting the commands: diff, list-backup, package, revert, status.
== Multiple backup versions ==
Lbu can now keep multiple backups so you can revert back to older configurations.
Set BACKUP_LIMIT in to the number of backups you want
to keep.
If you've set BACKUP_LIMIT, then the previously active .apkovl will be renamed before creating the new file.
You can list the currently available backups with:
and you can revert to an older one with:
NOTE: Nothing is changed on your running system when "reverting", it only affects which apkovl is considered active at the next boot.
== See also ==
* Back Up a Flash Memory Installation
* Manually editing a existing apkovl
Category:Installation
Category:Booting
Category:Package Manager
category: Diskless