Difference between revisions of "Alpine local backup"

From Alpine Linux
Jump to: navigation, search
m (Create a apkovl elsewhere than on some specific media)
(Formatting, and expand/refine some text)
Line 1: Line 1:
Alpine itself only loads a few required packages when you boot a clean Alpine Linux.<BR>
+
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!
But you probably want to do some personal adjustments (e.g [[Alpine_package_management|installing a package]] or doing some configuration).<BR>
 
Because Alpine runs on RAM (normally), and 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 'lbu' comes in handy!
 
  
 
__TOC__
 
__TOC__
  
{{Note | If you installed Alpine on HDD you don't need to use 'lbu'. All your modifications would be permanently stored on your HDD.}}
+
{{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.}}
  
First thing you need to know is this: '''As default 'lbu' only cares about modifications in ''/etc/'' and it's subfolders, with the exception of /etc/init.d/!''' <BR>
+
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>
Please have a look at '[[#Include_special_files.2Ffolders_to_the_apkovl|lbu include]]' to save files/folders located elsewhere than in ''/etc/''.
+
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:
 
Alpine has the following tools for permanently storing your modifications:
 
* lbu
 
* lbu
 
* lbu commit ''(Same as 'lbu ci')''
 
* lbu commit ''(Same as 'lbu ci')''
* lbu exclude ''(Same as 'lbu ex')''
+
* lbu exclude ''(Same as 'lbu ex' or 'lbu delete')''
* lbu include ''(Same as 'lbu inc')''
+
* lbu include ''(Same as 'lbu inc' or 'lbu add')''
 
* lbu status ''(Same as 'lbu st')''
 
* lbu status ''(Same as 'lbu st')''
 
* lbu list-backup ''(Same as 'lbu lb')''
 
* lbu list-backup ''(Same as 'lbu lb')''
 
* lbu revert
 
* lbu revert
  
In the below examples you will find some characters with special meaning
+
In the below examples 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 just skip the '-n', '-v' or '-nv' part if you don't want it)''
  
== Saving your changes ==
+
== Committing your changes ==
When you save your changes you will get a file that is named like 'myboxname.apkovl.tar.gz' ''('myboxname' will be the same as the hostname)''.<BR>
+
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 'apkovl'.<BR>
+
This file (that 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 some suitable media (floppy, usb, cf, other).
 
<pre>
 
<pre>
 
usage: lbu commit|ci [-nv] [<media>]
 
usage: lbu commit|ci [-nv] [<media>]
Line 51: Line 49:
  
 
== Include special files/folders to the apkovl ==
 
== Include special files/folders to the apkovl ==
Assume that you have some files that you want to permanently save, but they are located somewhere else than in ''/etc/''.<BR>
+
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 ''/root/.ssh/authorized_keys'' (used by 'sshd' to authenticate ssh-users).<BR>
+
It could be {{Path|/root/.ssh/authorized_keys}} (used by <code>sshd</code> to authenticate ssh-users).<BR>
Such files/folders can be added to the ''/etc/lbu/include'' list by manually editing the file or using the following command:
+
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 include|inc|add [-rv] <file> ...
Line 63: Line 61:
 
   -v Verbose mode.
 
   -v Verbose mode.
 
</pre>
 
</pre>
{{Note| This command only modifies some lbu-related config files. You will need to run 'lbu commit' to actually create/modify your apkovl.}}
+
 
 +
{{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.}}
 +
 
 +
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.
 +
 
  
 
== Exclude specific files/folders from the apkovl ==
 
== Exclude specific files/folders from the apkovl ==
Assume that you have some files located in ''/etc/'' or one of it's subfolders that you '''do not''' want to permanently save.<BR>
+
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 is elsewhere than in ''/var/log''.<BR>
+
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 ''/etc/lbu/exclude'' list by manually editing the file or using the following command:
+
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 exclude|ex|delete [-rv] <file> ...
Line 78: Line 80:
 
   -v Verbose mode.
 
   -v Verbose mode.
 
</pre>
 
</pre>
{{Note| This command only modifies some lbu-related config files. You will need to run 'lbu commit' to actually create/modify your apkovl.}}
+
{{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 ==
 
== Execute a script as part of a backup ==
Line 87: Line 89:
 
  /etc/lbu/post-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, ''runme.sh'' does not.)
+
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.)
  
The scripts in pre-package.d are run before the apkovl is created; scripts inpost-package.d are run after the apkovl is created.
+
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.
  
 
=== Example ===
 
=== Example ===
  
Rather than adding the raw database directories to /etc/lbu/include, you can do a "database dump".    For purposes of example, we use postgresql:
+
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}}:
  
* Add the database dump file to the list of files to back up: lbu include root/pgdatabases.gz
+
* Add the database dump file to the list of files to back up: <code>lbu include root/pgdatabases.gz</code>
* Create /etc/lbu/pre-package.d/sqldump with the following contents: <code>pg_dumpall -U postgres | gzip -c >/root/pgdatabases.gz</code>
+
* 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: chmod +x /etc/lbu/pre-package.d/sqldump
+
* Mark the file executable: <code>chmod +x /etc/lbu/pre-package.d/sqldump</code>
* Create /etc/lbu/post-package.d/sqldumpdelete with the following contents: <code>rm -f /root/pgdatabases.gz</code>
+
* Create {{Path|/etc/lbu/post-package.d/sqldumpdelete}} with the following contents: <pre>rm -f /root/pgdatabases.gz</pre>
* Mark the file executable: chmod +x /etc/lbu/post-package.d/sqldumpdelete
+
* Mark the file executable: <code>chmod +x /etc/lbu/post-package.d/sqldumpdelete</code>
  
Now whenever you do a ''lbu commit'', the sql databases are dumped and gzipped to /root/pgdatabases.gz, and then the temporary file is deleted at the end of the lbu commit.
+
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.
  
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 /root directory, where it can be restored manually.
+
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.
  
  
 
== Check what will be added to your 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 'lbu commit'. Here you have your help:
+
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
 
  usage: lbu list|ls
  
Line 130: Line 132:
 
== Use SSH to create an apkovl on a different host ==
 
== Use SSH to create an apkovl on a different host ==
  
To create an apkovl of client on a centralized server, use "-" as the apkovl name:
+
To create an apkovl of client on a centralized server, use {{Path|-}} as the apkovl name:
  
 
On the server:
 
On the server:
Line 148: Line 150:
 
== Multiple Backups ==
 
== Multiple Backups ==
 
Lbu can now keep backups so you can revert to older, good known config.
 
Lbu can now keep backups so you can revert to older, good known config.
Set BACKUP_LIMIT in /etc/lbu/lbu.conf to the number of backups you want
+
Set BACKUP_LIMIT in {{Path|/etc/lbu/lbu.conf}} to the number of backups you want
 
to keep.
 
to keep.
  

Revision as of 00:35, 22 January 2015

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 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 lbu comes in handy!

Note: If you installed Alpine on HDD you don't need to use lbu. All your modifications have already been directly written to your HDD. However, lbu can still be useful for some maintenance tasks.

The first thing you need to know is this: By default lbu only cares about modifications in /etc and its subfolders, with the exception of /etc/init.d!
Please have a look at lbu include to save files/folders located elsewhere than in /etc.

Alpine has the following tools for permanently storing your modifications:

  • lbu
  • lbu commit (Same as 'lbu ci')
  • lbu exclude (Same as 'lbu ex' or 'lbu delete')
  • lbu include (Same as 'lbu inc' or 'lbu add')
  • lbu status (Same as 'lbu st')
  • lbu list-backup (Same as 'lbu lb')
  • lbu revert

In the below examples 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 just skip the '-n', '-v' or '-nv' part if you don't want it)

Committing your 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). This file (that contains your modifications) is called your "apkovl". You will need to save your apkovl on some suitable media (floppy, usb, cf, other).

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> is 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 either be specified with the -p
option or using the PASSWORD environment variable.

The environment variables can also be set in /etc/lbu/lbu.conf

Include special files/folders to the apkovl

Assume that you have some files that you want to permanently save, but they are located somewhere else than in /etc.
It could be /root/.ssh/authorized_keys (used by sshd to authenticate ssh-users).
Such files/folders can be added to the /etc/lbu/include list by manually editing that file or using 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 instead of adding.
  -v	Verbose mode.
Note: This command only modifies some lbu-related config files. You will need to run lbu commit to actually create/modify your apkovl.

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 lbu should track outside its default list. The exclude list specifies locations that lbu should not track, that would otherwise be included.


Exclude specific files/folders from the apkovl

Assume that you have some files located in /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 /var/log/ but in some location that would otherwise be tracked by lbu. Such files/folders can be added to the /etc/lbu/exclude list by manually editing that 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 instead of adding.
  -v	Verbose mode.
Note: This command only modifies some lbu-related config files. You will need to run lbu commit to actually create/modify your apkovl.

Execute a script as part of a backup

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

/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": runme works, but runme.sh does not.)

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

Example

Rather than adding the raw database directories to /etc/lbu/include, you can do a "database dump". For purposes of example, we use postgresql:

  • Add the database dump file to the list of files to back up: lbu include root/pgdatabases.gz
  • 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

Now whenever you do a lbu commit, the sql databases are dumped and gzipped to /root/pgdatabases.gz, and then 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 responsibility), but you will find a complete database dump in the /root directory, where it can be restored manually.


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 lbu commit. Here you have your help:

usage: lbu list|ls

Create a apkovl elsewhere than on some specific media

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 current work directory.

Use SSH to create an apkovl on a different host

To create an apkovl of client on a centralized server, use - as the apkovl name:

On the server:

ssh root@client "lbu package -" >client.apkovl.tar.gz

Check what files have been changed since last commit

usage: lbu status|st [-av]

Options:
  -a	Compare all files, not just since last commit.
  -v	Also show include and exclude lists.

Multiple Backups

Lbu can now keep backups so you can revert to older, good known config. Set BACKUP_LIMIT in /etc/lbu/lbu.conf to the number of backups you want to keep.

You can list the current backups with:

lbu list-backup [<media>]

and you can revert to an older with:

lbu revert <filename> [<media>]

Note that when you revert, the current apkovl on media will be backed up.

See also