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
sudo make install
sudo cp /etc/rsnapshot.conf.default /etc/rsnapshot.conf
sudo open /etc/rsnapshot.conf
# This should open the configuration in your text editor
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.
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
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
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]
Download my launchd and rsnapshot configuration files.