Checkpointed Backups in OS X with rsnapshot
By Jason Harwig
Mar 06, 2007
Starting a backup routine is hard. I wanted a backup solution that did the following:
- Runs automatically every night
- Backup OS X resource forks correctly
- Maintain creation/modification times for backup files
- Make checkpointed-incremental backups
The key for me is incremental checkpoint backups, and by than I mean that every time the backup runs it creates a folder that only contains the changes since the last backup. See image on right, and how the file shares an inode. We can do one better using unix hard links to show all files, while still not using any more space. Read about hard links on wikipedia.
The unix utility rsync that comes with OS X 10.4 solves bullets 2-4 according to the man page. But, in practice, I could never get the checkpoints working correctly with "rsync --link-dest". Apparently that parameter doesn't always work. I tested it by running some test backups and checking the inode of the files using "ls -li". If a file doesn't change across backups it should share an inode number.
After more digging on the net I ran across rsnapshot, which is a perl front-end to rsync. It can make incremental checkpoints without link-dest. This blog shows some steps to getting rsnapshot installed on OS X. I'm going to augment those steps because I didn't want to install darwinports or fink, and I wanted to use launchd instead of cron.
Download and Installation
First, go to rsnapshot.org and download the "Generic UNIX" gzip, rsnapshot-1.3.0.tar.gz. Now, open terminal and type the following:
tar -xzvf rsnapshot-1.3.0.tar.gz
cd rsnapshot-1.3.0
./configure --sysconfdir=/etc
sudo make install
[enter password]
sudo cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf
sudo open /etc/rsnapshot.conf
# This should open the configuration in your text editor
Configuration
See this blog and the rsnapshot docs for the options to specify in the config file. The file is very well documented. You can download my configuration files here. At the minimum, you need to change the snapshot root and the backup points.
Automation
The blog uses crontab, but Mac OS X 10.4 deprecated cron for launchd. For information on launchd, see Apple's documentation. My configuration is included in the resources zip below. It goes in /Library/LaunchDaemons. If you want other intervals besides daily, make sure they are uncommented in the rsnapshot.conf and create new launchd plist's for them. Once the launch configuration is complete, load the configuration with the launchctl command or just restart:
sudo launchctl load /Library/LaunchDaemons/com.nearinfinity.backup.plist
Testing
For initial testing you might want to change your backup points to be smaller, otherwise this could take a while. When your ready, run a backup by typing:
sudo rsnapshot daily
[enter password]
This will create a daily.0 folder in your snapshot root directory. If you run the command again, the daily.0 will be renamed to daily.1 and daily.0 will represent the new backup. You can verify that inodes of files haven't changed using this command in your snapshots directory:
ls -li daily.0/localhost/[someFile] daily.1/localhost/[someFile]
That's it, now I just need to get these offsite, for a solid backup solution. Rsnapshot supports using ssh to backup to a remote server. See the rsnapshot documentation for more information.
Resources
Download my launchd and rsnapshot configuration files.