Musings and discoveries while navigating life. Mostly python, perl, sql, R, linux, os x, linguistics, cooking, bread, and food.

About Me

My Photo
Jonathan Keane
Chicago, IL, United States

07 March 2011

Towards a less thought, robust backup solution

As everyone knows, backups are critical. Unfortunately, robust backup solutions often require ongoing thought to be sustained. Apple's TimeMachine revolutionized no thought backups and it's relatively easy to use an existing ubuntu server/desktop system with free space to act as a timecapsule (see the many tutorials on the web). This allows my macbook (or any other mac for that matter) to backup to my server at home whenever I'm on the local network. Unfortunately it's not very robust, there is a single backup in a single location. It's difficult to take snapshots of this backup and copy them elsewhere because it is saved as a sparse disk image. There is simply no way to get a non-OS X system to manipulate these images (hdiutils which mounts sparse disk images isn't released back to the BSD community). TimeMachine: no thought – check; robust – not really.

CrashPlan is a service similar to services like Carbonite. They charge to store your backups on their server, but they will provide you with the infrastructure to backup to local drives, as well as remote computers. The interface is not quite as nice as TimeMachine, but so far it seems to replace most of the functionality. CrashPlan: no thought – check; robust – for money.



The best way to cover all of my backup bases that I've found is to use a combination of both. TimeMachine backsup to my server at home as a single, large backup, and then CrashPlan backsup to removable hard drives that are stored outside of my house shuffled at regular intervals to avoid total dataloss in the case of a disaster. CrashPlan isn't setup to play well with removable media in linux (cf CrashPlan forum discussion). In order to overcome this limitation and allow for times when the removable media is not connected, I have written a bash script that unlocks the encrypted block device, mounts it, and then starts the CrashPlan service only after the media is available. It also turns CrashPlan off when the media is unmounted. To use this you need to just change the variables $ENCRYPT_VOLUME to the name of the volume, and $VOLUME_PATH to the path for this volume to mount to. Finally configure CrashPlan to backup to this directory. Finally you need to disable the CrashPlan engine from starting on boot, which can be accomplished by running the following as a super user.

$ update-rc.d -f crashplan remove

 Time Machine + CrashPlan on removable media: no thought – mostly; robust – check

sbmounter.sh

#!/bin/bash -e

##############################
##
## Author: Jonathan Keane
## License: Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
## http://creativecommons.org/licenses/by-sa/3.0/
## Date: 7March2011
##
## Description: A script to mount or unmount a removable hard drive
## that has been LUKS encrypted; it also turns the CrashPlan
## backup engine on when the drive is mounted, and off when
## unmounted. In order to disable CrashPlan starting on boot
## as admin run:
## $ update-rc.d -f crashplan remove
## This deletes the link to the /etc/init.d/crashplan from all
## runlevels, while keeping the init.d script.
##
## Usage: -m /foo/bar to mount the encrypted block device that is located at
## /foo/bar (on many systems: /dev/sdX) to $VOLUME_PATH below
## -u unmounts the volume specified by $ENCRYPT_VOLUME below
##
##############################

## the name for your encrypted drive
ENCRYPT_VOLUME=SecureDevice

## the location you want the drive to be mounted to
VOLUME_PATH=/foo/bar

while getopts ":m:u" opt; do
case $opt in
m)
echo "Mounting: $OPTARG" >&2
sudo cryptsetup luksOpen $OPTARG $ENCRYPT_VOLUME
sudo mount /dev/mapper/$ENCRYPT_VOLUME $VOLUME_PATH
sudo /etc/init.d/crashplan start
exit 0
;;
u)
sudo /etc/init.d/crashplan stop
echo "Unmounting: $ENCRYPT_VOLUME" >&2
sudo umount /dev/mapper/$ENCRYPT_VOLUME
sleep 5
sudo cryptsetup luksClose $ENCRYPT_VOLUME
echo "Unmounted."
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done

echo "Need at least one option either -m /foo/bar to mount and start CrashPlan or -u to stop CrashPlan and unmount your encrypted volume."
exit 1

No comments: