Basically, I've created a script that creates snapshots of volumes on Mac OS X. The idea is adapted from Mike Rubel's excellent writeup. Being a lazy ass, I'm not going to be nearly as thorough as he was. If you're really interested in how all this stuff works, I suggest a read through his page. In a nutshell, it lets you create what looks like multiple copies of your data at different points in time, without actually having to have multiple copies on your disk. This is done by creating hard links from each snapshot to the files. Only when files are added or modified will you increase the amount of data you're storing. (you'll need at least an equal amount of space as your live data occupies, the extra depends on the amount of churn on your volumes).

There are two problems with running Mr. Rubel's setup on OS X. First, unix tools like cp and rsync don't handle Mac resource forks very well. Second, the version of cp supplied with OS X doesn't support hard links, which are necessary for this whole thing to work.

Rather than cp, I've used cpio. In place of the standard rsync I'm using psync. Panther users make note that you'll need to patch the psync source before compiling to get it to run. Psync is limited in that it can't copy across networks. This wasn't a problem for me as we're syncing data to another drive on the same host, but if you need the ability to sync to another host, you might want to try rsyncx, which is an HFS compatible version of rsync. I've not tried this, but it should be an easy substitution.

What the script does is

1) Rotate hourly, daily or weekly snapshots, deleting the oldest, and shifting each set back one position.mv "/path/to/backup/hourly.1""/path/to/backup/hourly.2"

2) Make a hard link copy of the last snapshot (which is a mirror of the live data)cd "/path/to/backup/hourly.0"&& find . -print| cpio -dplm "/path/to/backup/hourly.1"

3) Use psync to sync the live data with the first snapshot. The -d option tells psync to delete files from the snapshot that are no longer on the live volume. Since we're using hard links in step 2, these files aren't actually deleted - until you delete every link back to it (i.e., every snapshot).psync -d "/path/to/live/data""/path/to/backup/hourly.0"

The same concept applies for daily and weekly snapshots, except rather than using psync, we're just making a hard-link copy of the day's or week's last snapshot.cd "/path/to/backup/hourly.1"&& find . -print| cpio -dplm "/path/to/backup/daily.1"

Here's the finished script. You'll need to change the LIVEBASE and BACKBASE paths to match the paths to your live data and backup directory, respectively.