Thursday, June 12, 2014

Backing up with obnam

A couple of months ago my beloved Gentoo Linux told me that rdiff-backup is dead and even suggested some alternatives for backing up. After some experimenting, I am very happy with obnam.

I really like that it supports encryption and you can access all snapshots over network using "obnam mount" as if they were on your local machine.

It works perfectly for my parents whose computer has multiple hard-drives. Backing up of a 4 GiB home folder is done in 2 minutes every day. On my laptop I back up my 2.5 GiB home folder over network, which takes about 4 minutes on a wired connection and 7 using Wi-Fi. It's a quite long time but it runs nicely in the background and it doesn't impact my user experience. Here is my configuration file:

repository = sftp://lukas@secret-server/secret-folder

keep = 21d,5w,12m

log = /var/log/obnam/obnam-lukas.log
log-level = info
log-max = 1000000
log-keep = 10
log-mode = 0600

# These numbers optimize the time to upload new backup
# over network. Experiment with different numbers to find
# the optimal setting for you.
upload-queue-size = 1536
lru-size = 512

exclude = /home/lukas/.config/chromium/Default,

encrypt-with = 53F908A7

The exclude option contains regular expressions matching filepaths that you want to exclude. I don't want to back up my SVN/Mercurial/Git repositories plus various other directories containing unimportant information like cache.

The keep option says which snapshots you want to keep. From the first 21 days it will keep all daily snaphots, from the next 5 weeks it will keep weekly snapshots and finally it will keep another 12 monthly snapshots after that.

Here is my backup script that I run from cron every day in the evening with DISPLAY=:0 (because it asks for password to the encryption key in a graphical dialog). It needs gpg-agent started with "--write-env-file ${HOME}/.gnupg/gpg-agent-info" as argument.

. "${HOME}/.gnupg/gpg-agent-info"

if ((RANDOM % 6 == 0))
    obnam force-lock
    obnam forget

obnam backup ${HOME} 
When you lose network connection, the repository might stay locked, so the script plays Russian roulette to decide whether to ignore the lock or not. Also, once in a while you shold clean up the repository from old data using the forget command.

1 comment:

  1. This comment has been removed by a blog administrator.