Making backups on a Linux server

For our server we needed a “push type” backup, supporting incremental backups, transport over SSH and encrypted repositories. After evaluating a dozen of open-source backup tools, I chose duplicity. Although it doesn’t have too many bells and whistles, it does its job pretty well.

The way I run it is: export PASSPHRASE='' duplicity $@ --encrypt-key <keyid> --include-globbing-filelist /root/backup/dobackup.list --exclude '**' / ssh://<where>/<dir> && duplicity --remove-older-than 3D --force ssh://<where>/<dir>

For the encryption it uses a PGP key, which you need to generate (root needs to generate, unless you want to use a special key) and backup separately. The last one is quite important, as when your disk breaks down, the last thing you want to test is how difficult to break your 2048bit gpg key is ;-)

Other than that we dump the content of two our databases (not trusting file-level backups of “live” databases): mysqldump -A -C > $BACKUPDIR/mysql-alldatabases.dump su postgres pg_dumpall > $BACKUPDIR/pgsql-alldatabases.dump

We also generate a list of Debian packages: dpkg --get-selections | diff - $BACKUPDIR/dpkg-selections.log > /dev/null || dpkg --get-selections > $BACKUPDIR/dpkg-selections.log And autocommit and add entries to our SVN repository (a neat perl one-liner): SVNAUTOCOMMIT="/etc" NEWFILES=svn status $SVNAUTOCOMMIT | perl -ne '/\?\s*(.*)/ && print "$1 "' if [ -n "$NEWFILES" ]; then svn add $NEWFILES fi svn commit -m "Autocommit from a backup script" $SVNAUTOCOMMIT

Leave a Reply