my new root server host offers—as part of the base package—a 100 GB backup package. access to that space is via SMBFS/CIFS, WebDAV, or FTP. as we don’t really want to have our data lying around in the clear, i needed a solution to encrypt the data before storing it on the backup server. also, i really wanted to use rsnapshot to do the job.
after a bit of mucking around, this is what i came up with (all as root obviously).
set up an encrypted backup image
-
mount the backup server via smbfs/cifs at
/mnt/backup-server
. -
create a sparse disk image:
# truncate -s 90G /mnt/backup-server/backup.image
-
make it available as a loopback device:
# losetup /dev/loop0 /mnt/backup-server/backup.image
-
set up
/dev/loop0
as a LUKS partition:# cryptsetup luksFormat /dev/loop0
-
open the LUKS partition and make it available as
/dev/mapper/backupfs
:# cryptsetup luksOpen /dev/loop0 backupfs
-
create an ext4 filesystem on the opened LUKS partition:
# mkfs -t ext4 /dev/mapper/backupfs
-
and mount it as
/backups
:# mkdir /backups # mount /dev/mapper/backupfs /backups
-
set up
rsnapshot
and run it.
once rsnapshot has done its job, umount the backup image, release the loopback device, unmount the backup server.
automating it
to automate the whole setup:
-
to mount the backup server and the contained LUKS image, the
mount-backup
script[gist:id=1b23be3534cf23b35796]
-
along with it’s companion to umount the whole stack, the
umount-backup
script[gist:id=5922b77506c16dc5cfda]
-
finally, a wrapper around rsnapshot to mount the backup image, run rsnapshot, capture stats, and unmount the backup image, the
rsnapshot-local
script[gist:id=d98b950dcc6506891c74]