A daily cron script that backs things up into /backup/YYYY-MM-DD/
.
Quick start:
sudo add-apt-repository ppa:pov sudo apt-get update sudo apt-get install pov-simple-backup
Things you want to back up are configured in /etc/pov/backup
, which
is actually a shell file that is sourced from the cron script. If this
file is missing, pov-simple-backup
does nothing.
Example configuration file:
back_up /etc back_up /root back_up /usr/local back_up /var/cache/debconf/config.dat back_up_dpkg_selections back_up_postgresql generate_checksums clean_up_old_backups 14 copy_backup_to user@otherserver:/backup/myhostname/ -i /path/to/ssh-key.rsa
You can also run a backup manually by running pov-simple-backup
. The
following command-line options are available:
-h | show a brief help message |
-v | print things that are being backed up |
-n | only print things that are being backed up, don't actually back them up |
-o | overwrite existing backup files |
-s | skip existing backup files |
-S | instead of taking a backup, estimate the size of backups |
-g | instead of taking a backup generate a config file and print it to the standard output |
-f CONFIG-FILE | use CONFIG-FILE instead of /etc/pov/backup |
- back_up <pathname> [<tar options>]
Back up a directory or a single file
Creates <filename>.tar.gz, where the <filename> is constructed from the <pathname> by stripping leading slashes and replacing all other slashes with hyphens.
Examples:
back_up /var/cache/debconf/config.dat back_up /opt/myapp --exclude opt/myapp/var/zdaemonsock
would create var-cache-debconf-config.dat.tar.gz and opt-myapp.tar.gz
Note: when using tar's
--exclude
, be sure to omit both the leading and the trailing slash! Otherwise it will be ignored.Note: <pathname> will be passed as the last argument to tar (otherwise --exclude would have no effect!).
- back_up_to <name> [<pathname>] [<tar options>]
Back up a directory or a file.
Creates <name>.tar.gz.
Examples:
back_up_to backup-skeleton --no-recursion backups/host1 backups/host2
Note: when using tar's
--no-recursion
, be sure to specify it before the directory you don't want to recurse into. Otherwise it may be ignored, depending on the version of tar.Note: when using tar's
--exclude
, be sure to omit both the leading and the trailing slash! Otherwise it will be ignored.Note: you can back up multiple files/directories, but you'll have to omit leading slashes to avoid warnings from tar.
Note: <pathname> is considered to be present when it starts with a /
Note: <pathname> will be passed as the last argument to tar (otherwise --exclude would have no effect!). The leading slash will be automatically stripped from it.
Note: <pathname> must not have spaces in it, for silly reasons.
- back_up_uncompressed <pathname> [<tar options>]
Back up a directory or a single file
Creates <filename>.tar, where the <filename> is constructed from the <pathname> by stripping leading slashes and replacing all other slashes with hyphens.
Examples:
back_up_uncompressed /git/myrepo.git
would create git-myrepo.git.tar
Note: when using tar's
--exclude
, be sure to omit both the leading and the trailing slash! Otherwise it will be ignored.- back_up_uncompressed_to <name> [<pathname>] [<tar options>]
Back up a directory or a file.
Creates <name>.tar.
Examples:
back_up_uncompressed_to backup-skeleton --no-recursion /backups/host1 backups/host2
Note: when using tar's
--no-recursion
, be sure to specify it before the directory you don't want to recurse into. Otherwise it may be ignored, depending on the version of tar.Note: when using tar's
--exclude
, be sure to omit both the leading and the trailing slash! Otherwise it will be ignored.Note: you can back up multiple files/directories, but you'll have to omit leading slashes to avoid warnings from tar.
Note: <pathname> is considered to be present when it starts with a /
Note: <pathname> will be passed as the last argument to tar (otherwise --exclude would have no effect!). The leading slash will be automatically stripped from it.
Note: <pathname> must not have spaces in it, for silly reasons.
- back_up_dpkg_selections
Back up dpkg selections (i.e. list of installed packages)
Creates dpkg--get-selections.gz and var-lib-apt-extended_states.gz
- back_up_postgresql
Back up all PostgreSQL databases in the main cluster
Creates postgresql-dump.sql.gz
Bugs:
- a single dump file for all databases is unwieldy
- a text dump file is inefficient
- back_up_mysql
Back up all MySQL databases
Creates mysql-dump.sql.gz
Bugs:
- a single dump file for all databases is unwieldy
- a text dump file is inefficient
- back_up_svn <pathname>
Back up a single SVN repository
Creates <filename>.svndump.gz, where the <filename> is constructed from the <pathname> by stripping leading slashes and replacing all other slashes with hyphens.
Bugs:
- does not back up hooks/ and conf/ subdirectories
Example:
back_up_svn /var/lib/svn/myrepo back_up /var/lib/svn/myrepo/conf back_up /var/lib/svn/myrepo/hooks
- encrypt_dir [<suffix> [<new-suffix>]]
Encrypt a backup directory using GPG
Creates a parallel backup directory with each backup file will be gpg-encrypted to the recipients specified in $GPG_RECIPIENTS.
Note: root's GPG keyring should already have the public keys of the specified recipients.
<suffix> defaults to $BACKUP_SUFFIX.
<new-suffix> defaults to <suffix>-gpg.
Do this after all the backup commands, and before all the rsync/scp commands.
Example:
[email protected],[email protected] back_up ... back_up ... clean_up_old_backups 14 encrypt_dir generate_checksums -gpg clean_up_old_backups 1 $BACKUP_ROOT -gpg BACKUP_SUFFIX=-gpg copy_backup_to remote:/backup/encrypted-stuff
Example:
[email protected],[email protected] back_up ... clean_up_old_backups 14 BACKUP_SUFFIX=-git back_up ... clean_up_old_backups 7 BACKUP_SUFFIX= encrypt_dir encrypt_dir -git generate_checksums -gpg generate_checksums -git-gpg clean_up_old_backups 1 $BACKUP_ROOT -gpg clean_up_old_backups 1 $BACKUP_ROOT -git-gpg BACKUP_SUFFIX=-gpg copy_backup_to remote:/backup/encrypted-stuff BACKUP_SUFFIX=-git-gpg copy_backup_to remote:/backup/encrypted-stuff
- generate_checksums [<suffix>]
Generate a SHA256SUMS file in the backup directory
Do this after all the backup commands, and before all the rsync/scp commands.
Example:
generate_checksums generate_checksums -git
- clean_up_old_backups <number> [<directory> [<suffix>]]
Remove old backups, keep last <number>
Example:
clean_up_old_backups 14 clean_up_old_backups 14 /backup/otherhost/ clean_up_old_backups 14 /backup/ -git
to keep just two weeks' backups
- copy_backup_to [<user>@]<server>:<path> [<ssh options>]
Copy today's backups to a remote server over SSH, using rsync
Alias for
rsync_backup_to
.Example:
copy_backup_to [email protected]:/backup/myhostname/ -i key.rsa
See also: rsync_backup_to, scp_backup_to
- rsync_to <pathname> [<user>@]<server>:<path> [<ssh options>]
Mirror a file or directory to a remote server over SSH, using rsync
It means a lot to rsync whether or not you have a trailing slash at the end of <pathname>, when it's a directory. No trailing slash: it will create a new directory with the same basename on the server side, under <path>. Trailing slash: it will make the contents of <path> on the server the same as contents of <pathname> here.
Example:
rsync_to /var/www/uploads [email protected]:/backup/myhostname/uploads -i key.rsa
- rsync_backup_to [<user>@]<server>:<path> [<ssh options>]
Copy today's backups to a remote server over SSH, using rsync
Example:
rsync_backup_to [email protected]:/backup/myhostname/ -i key.rsa
See also: scp_backup_to, copy_backup_to
- scp_backup_to [<user>@]<server>:<path> [<scp options>]
Copy today's backups to a remote server over SSH, using scp
Destination directory must exist on the remote host.
Example:
copy_backup_to [email protected]:/backup/myhostname/ -i key.rsa
Bugs:
- if the remote directory already exists, creates a second copy, as a subdirectory (e.g. /backup/myhostname/2013-08-29/2013-08-29)
See also: rsync_backup_to, copy_backup_to