Sunday, March 31, 2013

Using Raspberry Pi for backups

Very annoyed with myself for shutting down my RPi without synching to "disk" i.e. SD card. So it corrupted the disk image and I have to do yet another install from scratch. (Yes, yes, I know: "backup the image when it's stable". I'll learn eventually.)

So once again I followed Naich's great tutorial for setting up a headless RPi. The main improvement I made is to configure DHCP on my router to give the RPi the same IP address every time it requests one.

And the latest Raspian wheezy image seems to enable sshd at boot time, a very useful setting which saves my having to connect a keyboard and monitor to configure it.

In a previous blog I listed the arduous tasks involved in setting up an automatic backup of my ReadyNAS to a largely obsoleted Drobo 1 networked via an Apple Airport Extreme Base Station.

But it turned out that the load on the ReadyNAS was too big. The ReadyNAS is already handling my BitTorrent downloads and music and video streamings. Duplicity broke the camel's back.

The Rpi was sitting around doing nothing so why not make it the backup machine. Because RPi is using the latest Debian it seemed likely that installs of all the apps would be more straightforward.

I decided that duply was a much simpler way to invoke Duplicity so installed both. Also now need to NFS mount ReadyNAS filesystem on RPi as well as mounting Drobo using afpfs-ng.

So using apt-get:

apt-get install duplicity
apt-get install duply
apt-get install afpfs-ng

All installed with no problems. The trick with afpfs is that the userfilesystem device (/dev/fuse) has group 'fuse' and I needed to change my primary group to 'fuse' so I don't get permission errors when I try to mount the Drobo filesystem. Thus:

sudo su
usermod -g fuse myusername

Then I had to reboot the RPi to get this change to stick:

shutdown -r now

Can now mount the Drobo as an AFP filesystem:
mount_afp afp://user:password@ /mnt/drobo

Also followed Raspian FAQ to mount NFS filesystem:
sudo apt-get install nfs-common portmap
sudo service rpcbind start
sudo update-rc.d rpcbind enable

ReadyNAS is already set up to NFS export /media and /temp so I added the following to /etc/fstab:

nas:/media /mnt/media nfs rsize=8192,wsize=8192,timeo=14,intr 0 0
nas:/temp /mnt/temp nfs rsize=8192,wsize=8192,timeo=14,intr 0 0

Then mounted the filesystems with:
sudo mount -a

I then followed the duply man page to setup the duply config file in ~/.duply/nasbak:

duply nasbak create

Edit the ~/.duply/nasbak/conf file to set config options. The most important are:
DUPL_PARAMS="$DUPL_PARAMS --exclude-globbing-filelist $HOME/.duply/nasbak/exclude "

/mnt/temp is an NFS-mounted temp directory on the ReadyNAS. I don't have enough storage on the RPi SD card and Drobo is way too slow for temp files.

exclude file contains:


I don't want to backup Movies, TV shows or anything currently being downloaded by Transmission.

Check syntax of config file:
duply nasbak backup --preview

If syntax is OK run the backup (first time will be a full backup):
duply nasbak backup

No comments: