Sunday, November 18, 2012

Backing up Ubuntu using Deja-Dup (inc. system files)

When I got the NAS set up on the network, I started playing around with Deja-Dup, the backup utility for Ubuntu. Previously I'd never backed up my Ubuntu installation but with the NAS now online it made sense to try it out. Note that Deja-Dup is a file-based back-up utility. If you want low-level backups of your partitions then you would consider using dd together with the relevant device files as described here. Be cautious with these low-level techniques as you really need to know what you're doing and can do untold damage if you don't.

Initially I ran the utility under my own account but noticed that there were a number of (system) files that didn't back up successfully due to a lack of permissions so determined that running the backup in two parts was the way to go: one as root for purely system files (NB: edit at end of post), and the other under my regular user account for anything of personal import.

Deja-dup needs to be set up for the root user. You can either do this by logging in as root if you've enable such a login in Gnome. More likely you haven't done this (Ubuntu doesn't do this for you by default), so use gksu as follows (either should work):

user@host: gksu gnome-control-center deja-dup
or
user@host: gksu deja-dup-preferences

Then configure the storage location. Mine is NFS mounted like this:

/mnt/nas/Backup/DejaDup.hostname.user

Then add/remove directories as required. To keep this as a system-specific backup I've pruned a few directories from the generic file system layout, but you can always refine this further:

Included:
/
/root


Excluded (this list includes some kernel file systems for interrogating certain kernel data structures that we don't want to back up, as well as stuff that wouldn't ever need to be restored or will be covered by non-system user backups):
/dev
/home
/mnt
/media
/proc 
/run
/sys
/tmp


A frequency of weekly and retention period of 6 months should be fine considering how often changes occur to the OS through the Ubuntu software updater and LTS releases. On my vanilla Ubuntu 12.10 desktop installation with NFS mounted backup dir running over gigabit ethernet, the backup took about 7 minutes and generated 1.2GB of backup files.

You can now run the Backup utility under your regular user account to cover off any personal files that you care about.

A final note regarding NFS mounts of your backup location. I encountered permission issues during backup writing to the backup target. You may need to investigate how the NFS server has set permissions at the target end to ensure everything works smoothly. In my case, root on the NFS client host was mapped to a different id on the NFS server. You may need to override this on the NFS server.

REDACTION: This doesn't automate backups for root or other users. Backups only seem to run for users when logged in.

I logged in to double-check the back-ups were working as expected for root (per the description given above). Whilst the configuration I had created was all still there, the backups weren't actually running automatically - presumably since you need to be logged in for the backup to get triggered. The Deja-Dup dialogue basically said something like "Last backup: 57 days ago". Anways, the back-end to Deja-Dup is duplicity, a command line utility. Depending on the selected options, Deja-Dup's auto-generated duplicity command line could look like this:

/usr/bin/python /usr/bin/duplicity --exclude=/mnt/nas/Backup/DejaDup.goat-lin.root --include=/root/.cache/deja-dup/metadata --exclude=/proc --exclude=/sys --exclude=/run --exclude=/dev --exclude=/home --exclude=/media --exclude=/tmp --exclude=/mnt --exclude=/sys --exclude=/proc --exclude=/tmp --exclude=/root/.gvfs --exclude=/root/.cache/deja-dup --exclude=/root/.cache --include=/ --include=/root --exclude=** --gio --volsize=50 / file:///mnt/nas/Backup/DejaDup.goat-lin.root --verbosity=4 --gpg-options=--no-use-agent --archive-dir=/root/.cache/deja-dup

Now you can go put something similar to the above in cron. Edit 7/7 to remove some uneccessary options and reduce verbosity.

No comments:

Post a Comment