Alpine local backup: Difference between revisions

From Alpine Linux
(Formatting, and expand/refine some text)
m (add space)
 
(125 intermediate revisions by 13 users not shown)
Line 1: Line 1:
When you boot Alpine Linux in a run-from-RAM configuration, Alpine itself only loads a few required packages. But you probably want to do some personal adjustments (e.g [[Alpine_package_management|installing a package]] or doing some configuration). Since everything in RAM will get lost next time the box is rebooted or shut down, you will need to permanently save your modifications and adjustments to Alpine. This is where <code>lbu</code> comes in handy!
Local backup utility ({{ic|lbu}}) is the Alpine Linux tool to manage [[Diskless Mode]] installations. For these installations, {{ic|lbu}} tool must be used to [[#Committing changes|commit the changes]] whenever [[Alpine Package Keeper]] is used.


__TOC__
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. installing a package or adjusting the configuration files in {{path|/etc}}. The modifications can be saved with {{ic|lbu}} tool to an overlay file i.e [[Diskless Mode#Apkovl|apkovl]] file  that can be automatically loaded when booting, to restore the saved state.


{{Note|If you installed Alpine on HDD you don't need to use <code>lbu</code>. All your modifications have already been directly written to your HDD. However, <code>lbu</code> can still be useful for some maintenance tasks.}}
By default, an {{ic|lbu commit}} only stores modifications below {{Path|/etc}}, with the exception of the {{Path|/etc/init.d/}} directory. If a user was created during the {{ic|setup-alpine}} script, that user's home directory is also added to the paths that <code>lbu</code> will backup up. However, [[#Include_special_files.2Ffolders_to_the_apkovl|lbu include]] enables modifying that set of included files, and can be used to specify additional files or folders.


The first thing you need to know is this: '''By default <code>lbu</code> only cares about modifications in {{Path|/etc}} and its subfolders, with the exception of {{Path|/etc/init.d}}!''' <BR>
== Overview ==
Please have a look at [[#Include_special_files.2Ffolders_to_the_apkovl|lbu include]] to save files/folders located elsewhere than in {{Path|/etc}}.


Alpine has the following tools for permanently storing your modifications:
The <code>lbu</code> tool has several subcommands to manage the .apkovl:
* lbu
{|
* lbu commit ''(Same as 'lbu ci')''
|-
* lbu exclude ''(Same as 'lbu ex' or 'lbu delete')''
| lbu commit
* lbu include ''(Same as 'lbu inc' or 'lbu add')''
| lbu ci
* lbu status ''(Same as 'lbu st')''
| Create a backup of config to writeable media
* lbu list-backup ''(Same as 'lbu lb')''
|-
* lbu revert
| 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: {{Codeline|lbu package -v /dev/null}}
|-
| lbu diff
|
| Run a diff against last commit
|-
| lbu include
| lbu inc or lbu add
| Add filename(s) to include list{{Path|/etc/apk/protected_paths.d/lbu.list}}
|-
| lbu exclude
| lbu ex or lbu delete
| Add filename(s) to exclude list {{Path|/etc/apk/protected_paths.d/lbu.list}}
|-
| lbu list-backup
| lbu lb  
| Show old commits
|-
| lbu revert
|
|Revert to older commit
|-
|}


In the below examples you will find some characters with special meaning:
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')''
* '''|''' = '''or''' ''('lbu commit|ci' means that you can type ether 'lbu commit' or 'lbu ci')''
* '''[ ]''' = '''optional''' ''(In 'lbu commit|ci [-nv]' you can just skip the '-n', '-v' or '-nv' part if you don't want it)''
* '''[ ]''' = '''optional''' ''(In 'lbu commit|ci [-nv]' you can skip the '-n', '-v' or '-nv' part if you don't want it)''
 
== Committing changes ==


== Committing your changes ==
When you "commit" or save changes you've made to your system, <code>lbu</code> will generate a file named something like {{Path|<var>myboxname</var>.apkovl.tar.gz}} ''('myboxname' will be the same as the hostname)''.
When you "commit" or save changes you've made to your system, <code>lbu</code> will generate a file named something like {{Path|<var>myboxname</var>.apkovl.tar.gz}} ''('myboxname' will be the same as the hostname)''.
This file (that contains your modifications) is called your "apkovl".
The file (which contains your modifications) is called your "apkovl".
You will need to save your apkovl on some suitable media (floppy, usb, cf, other).
You will need to save your apkovl on suitable media (floppy, usb, cf, etc.).
<pre>
<pre>
usage: lbu commit|ci [-nv] [<media>]
usage: lbu commit|ci [-nv] [<media>]
Line 35: Line 67:
   -v Verbose mode.
   -v Verbose mode.


The following values for <media> is supported: floppy usb
The following values for <media> are supported: floppy usb
If <media> is not specified, the environment variable LBU_MEDIA will be used.
If <media> is not specified, the environment variable LBU_MEDIA will be used.


Line 42: Line 74:
For possible ciphers, try: openssl -v
For possible ciphers, try: openssl -v


The password used to encrypt the file, can either be specified with the -p
The password used to encrypt the file, can be specified with the -p
option or using the PASSWORD environment variable.
option or by using the PASSWORD environment variable.


The environment variables can also be set in /etc/lbu/lbu.conf
The environment variable can also be set in /etc/lbu/lbu.conf
</pre>
</pre>


== Include special files/folders to the apkovl ==
== Creating an .apkovl "package" elsewhere than on the configured media ==
Assume that you have some files that you want to permanently save, but they are located somewhere else than in {{Path|/etc}}.<BR>
 
It could be {{Path|/root/.ssh/authorized_keys}} (used by <code>sshd</code> to authenticate ssh-users).<BR>
To "commit" changes, but override the destination of the generated apkovl file, use <code>lbu package</code> instead of <code>lbu commit</code>:
Such files/folders can be added to the {{Path|/etc/lbu/include}} list by manually editing that file or using the following command:
 
<pre>
<pre>
usage: lbu include|inc|add [-rv] <file> ...
usage: lbu package|pkg -v [<dirname>|<filename>]
      lbu include|inc|add [-v] -l


Options:
Options:
   -l List contents of include list.
   -v  Verbose mode.
  -r Remove specified file(s) from include list instead of adding.
 
  -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.
</pre>
</pre>


{{Note| This command only modifies some lbu-related config files. You will need to run <code>lbu commit</code> to actually create/modify your apkovl.}}
To create an apkovl from a client on a remote server, it's possible to use <code>lbu package</code> via SSH with {{Path|-}} as the apkovl name on the server:{{Cmd|ssh root@client "lbu package -" > client.apkovl.tar.gz}}


Note that removing a file from the ''include'' list is different from adding a file to the ''exclude'' list, discussed below (though the final effects are similar). The ''include'' list specifies locations that <code>lbu</code> should track outside its default list. The ''exclude'' list specifies locations that <code>lbu</code> should not track, that would otherwise be included.
== Checking what will be added to your apkovl ==


<code>lbu status</code> lists what will be saved the next time you run <code>lbu commit</code>. Its default output is incremental, that is, it shows
only the files that have changed since the last commit. <br>
This can be overridden with the <code>-a</code> flag:


== Exclude specific files/folders from the apkovl ==
Assume that you have some files located in {{Path|/etc}} or one of its subfolders that you ''do not'' want to permanently save.
It could be some log file or status file that for some reason isn't in {{Path|/var/log/}} but in some location that would otherwise be tracked by <code>lbu</code>.
Such files/folders can be added to the {{Path|/etc/lbu/exclude}} list by manually editing that file or using the following command:
<pre>
<pre>
usage: lbu exclude|ex|delete [-rv] <file> ...
usage: lbu status|st [-av]
      lbu exclude|ex|delete [-v] -l


Options:
Options:
   -l List contents of exclude list.
   -a    Compare all files, not just since last commit.
   -r Remove specified file(s) from exclude list instead of adding.
   -v    show include and exclude lists.
  -v Verbose mode.
</pre>
</pre>
{{Note| This command only modifies some lbu-related config files. You will need to run <code>lbu commit</code> to actually create/modify your apkovl.}}


== Execute a script as part of a backup ==
Another option is <code>lbu list</code>. This works like <code>lbu status -a</code> but the format of the output is a bit different. (It's strictly equivalent to <code>lbu package -v /dev/null</code>).


Sometimes it is necessary to run a script before or after a backup. Scripts in two optional directories allow for this:
  usage: lbu list|ls


/etc/lbu/pre-package.d
A third option is <code>lbu diff</code>. This shows the same incremental changes that <code>lbu status</code> (without <code>-a</code>) does, but in a different format.
/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": {{Path|runme}} works, but {{Path|runme.sh}} does not.)
  usage: lbu diff


The scripts in {{Path|pre-package.d}} are run before the apkovl is created; scripts in {{Path|post-package.d}} are run after the apkovl is created.
== Include special files/folders to the apkovl ==


=== Example ===
Assume you have some files you want to save permanently, but they are not located in {{Path|/etc}}.<BR>
e.g. {{Path|/root/.ssh/authorized_keys}} (used by <code>sshd</code> to authenticate ssh-users). Such files/folders can be added to lbu's ''include'' list with the following command:


Rather than adding the raw database directories to {{Path|/etc/lbu/include}}, you can do a "database dump".    For purposes of example, we use {{Pkg|postgresql}}:
<pre>
usage: lbu include|inc|add [-rv] <file> ...
      lbu include|inc|add [-v] -l


* Add the database dump file to the list of files to back up: <code>lbu include root/pgdatabases.gz</code>
Options:
* Create {{Path|/etc/lbu/pre-package.d/sqldump}} with the following contents: <pre>pg_dumpall -U postgres | gzip -c >/root/pgdatabases.gz</pre>
  -l List contents of include list.
* Mark the file executable: <code>chmod +x /etc/lbu/pre-package.d/sqldump</code>
  -r Remove specified file(s) from include list.
* Create {{Path|/etc/lbu/post-package.d/sqldumpdelete}} with the following contents: <pre>rm -f /root/pgdatabases.gz</pre>
  -v Verbose mode.
* Mark the file executable: <code>chmod +x /etc/lbu/post-package.d/sqldumpdelete</code>
</pre>


Now whenever you do a <code>lbu commit</code>, the sql databases are dumped and gzipped to {{Path|/root/pgdatabases.gz}}, and then the temporary file is deleted at the end of the lbu commit.
{{Note|This information used to be maintained in {{Path|/etc/lbu/include}}. Now it's maintained together with the ''exclude'' list in {{Path|/etc/apk/protected_paths.d/lbu.list}}. Either way, the command <code>lbu include</code> only modifies lbu's configuration. You will need to run <code>lbu commit</code> to actually create/modify your apkovl.}}


On a catastrophic restore, the databases are not automatically restored (that's not lbu's responsibility), but you will find a complete database dump in the {{Path|/root}} directory, where it can be restored manually.
== Exclude specific files/folders from the apkovl ==
 
 
== Check what will be added to your apkovl ==
Sometimes it would be handy to know what files will be permanently saved next time you run <code>lbu commit</code>. Here you have your help:
usage: lbu list|ls
 
== Create a apkovl elsewhere than on some specific media ==


Assume you have some files located in {{Path|/etc}} 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 {{Path|/var/log/}} but in a location that would otherwise be tracked by <code>lbu</code>.
Such files/folders can be added to lbu's ''exclude'' list by manually editing the file or using the following command:
<pre>
<pre>
usage: lbu package|pkg -v [<dirname>|<filename>]
usage: lbu exclude|ex|delete [-rv] <file> ...
      lbu exclude|ex|delete [-v] -l


Options:
Options:
  -l List contents of exclude list.
  -r Remove specified file(s) from exclude list.
   -v Verbose mode.
   -v Verbose mode.
</pre>
{{Note|As stated above, this information is now maintained in {{Path|/etc/apk/protected_paths.d/lbu.list}}. The command <code>lbu exclude</code> also only modifies lbu's configuration. You will need to run <code>lbu commit</code> to actually create/modify your apkovl.}}


If <dirname> is a directory, a package named <hostname>.apkovl.tar.gz will
== Multiple backup versions ==
be created in the specified directory.
 
Lbu can keep multiple backups so you can revert back to older configurations. Set BACKUP_LIMIT in {{Path|/etc/lbu/lbu.conf}} to the number of backups you want to keep. Based on BACKUP_LIMIT, the previously active .apkovl will be renamed before creating the new file.
 
You can list the currently available backups and revert to an older one with the following commands:{{Cmd|<nowiki># lbu list-backup [<media>]
# lbu revert <filename> [<media>]</nowiki>}}


If <filename> is specified, and is not a directory, a package with the
Nothing is changed on your running system when "reverting", it only affects which apkovl is loaded at the next boot.
specified name will be created.


If neither <dirname> nor <filename> is specified, a package named
== Saving and loading ISO image customizations ==
<hostname>.apkovl.tar.gz will be created in current work directory.
<!-- This heading is retained here as certain bug reports refer this heading. -->
</pre>
ISO boot images can save running states to [[Diskless Mode#Using an internal disk for persistent storage|system partitions]] and automatically loaded when booting the ISO boot image.  


== Use SSH to create an apkovl on a different host ==
== Execute a script as part of a backup ==


To create an apkovl of client on a centralized server, use {{Path|-}} as the apkovl name:
Sometimes it's necessary to run a script before or after a backup.  Scripts in two optional directories enable that:


On the server:
/etc/lbu/pre-package.d
<pre>
/etc/lbu/post-package.d
ssh root@client "lbu package -" >client.apkovl.tar.gz
</pre>


== Check what files have been changed since last commit ==
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. {{Path|runme}} works, but {{Path|runme.sh}} does not. Also the shebang line on the first line should be indicated, e.g. #!/bin/sh .)
<pre>
usage: lbu status|st [-av]


Options:
The scripts in {{Path|pre-package.d}} are run before apkovl is created. Scripts in {{Path|post-package.d}} are run after apkovl is created.
  -a Compare all files, not just since last commit.
  -v Also show include and exclude lists.
</pre>


== Multiple Backups ==
=== Example ===
Lbu can now keep backups so you can revert to older, good known config.
Set BACKUP_LIMIT in {{Path|/etc/lbu/lbu.conf}} to the number of backups you want
to keep.


You can list the current backups with:
Rather than adding the raw database directories to {{Path|/etc/lbu/include}}, you can do a "database dump".  e.g. {{Pkg|postgresql}}:


{{Cmd|lbu list-backup [<media>]}}
* Create {{Path|/etc/lbu/pre-package.d/sqldump}} with the following contents: <pre>pg_dumpall -U postgres | gzip -c >/root/pgdatabases.gz</pre>
* Mark the file executable: <code>chmod +x /etc/lbu/pre-package.d/sqldump</code>
* Create {{Path|/etc/lbu/post-package.d/sqldumpdelete}} with the following contents: <pre>rm -f /root/pgdatabases.gz</pre>
* Mark the file executable: <code>chmod +x /etc/lbu/post-package.d/sqldumpdelete</code>
* Finally, add the database dump file to the list of files to back up: <code>lbu include root/pgdatabases.gz</code>


and you can revert to an older with:
Now when you do a <code>lbu commit</code>, the sql databases are dumped and gzipped to {{Path|/root/pgdatabases.gz}}.
The temporary file is deleted at the end of the lbu commit.


{{Cmd|lbu revert <filename> [<media>]}}
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 {{Path|/root}} directory, where it can be restored manually.


Note that when you revert, the current apkovl on media will be backed
P.s. These scripts are also launched when starting the commands: diff, list-backup, package, revert, status.
up.


== See also ==
== See also ==
* [Diskless Mode]]
* [[Back Up a Flash Memory Installation]]
* [[Back Up a Flash Memory Installation]]
* [[Manually editing a existing apkovl]]
* [[Manually editing a existing apkovl]]


[[Category:Installation]]
[[Category:Installation]]
[[Category:Storage]]
[[Category:Booting]]
[[Category:Booting]]
[[Category:Package Manager]]
[[Category:Package Manager]]
[[category: Diskless]]

Latest revision as of 19:05, 30 July 2025

Local backup utility (lbu) is the Alpine Linux tool to manage Diskless Mode installations. For these installations, lbu tool must be used to commit the changes 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. installing a package or adjusting the configuration files in /etc. The modifications can be saved with lbu tool to an overlay file i.e apkovl file that can be automatically loaded when booting, to restore the saved state.

By default, an lbu commit only stores modifications below /etc, with the exception of the /etc/init.d/ 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 package -v /dev/null
lbu diff Run a diff against last commit
lbu include lbu inc or lbu add Add filename(s) to include list/etc/apk/protected_paths.d/lbu.list
lbu exclude lbu ex or lbu delete Add filename(s) to exclude list /etc/apk/protected_paths.d/lbu.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.apkovl.tar.gz ('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.

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

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 /etc.
e.g. /root/.ssh/authorized_keys (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.
Note: This information used to be maintained in /etc/lbu/include. Now it's maintained together with the exclude list in /etc/apk/protected_paths.d/lbu.list. Either way, the command lbu include only modifies lbu's configuration. You will need to run lbu commit to actually create/modify your apkovl.

Exclude specific files/folders from the apkovl

Assume you have some files located in /etc 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 /var/log/ 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.
Note: As stated above, this information is now maintained in /etc/apk/protected_paths.d/lbu.list. The command lbu exclude also only modifies lbu's configuration. You will need to run lbu commit to actually create/modify your apkovl.

Multiple backup versions

Lbu can keep multiple backups so you can revert back to older configurations. Set BACKUP_LIMIT in /etc/lbu/lbu.conf to the number of backups you want to keep. Based on BACKUP_LIMIT, the previously active .apkovl will be renamed before creating the new file.

You can list the currently available backups and revert to an older one with the following commands:

# lbu list-backup [<media>] # lbu revert <filename> [<media>]

Nothing is changed on your running system when "reverting", it only affects which apkovl is loaded at the next boot.

Saving and loading ISO image customizations

ISO boot images can save running states to system partitions and automatically loaded when booting the ISO boot image.

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. runme works, but runme.sh does not. Also the shebang line on the first line should be indicated, e.g. #!/bin/sh .)

The scripts in pre-package.d are run before apkovl is created. Scripts in post-package.d are run after apkovl is created.

Example

Rather than adding the raw database directories to /etc/lbu/include, you can do a "database dump". e.g. postgresql:

  • Create /etc/lbu/pre-package.d/sqldump 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 /etc/lbu/post-package.d/sqldumpdelete 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 /root/pgdatabases.gz. 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 /root directory, where it can be restored manually.

P.s. These scripts are also launched when starting the commands: diff, list-backup, package, revert, status.

See also