Diggin' Disk Images

by Jason Deraleau


Recently, I became frustrated with the selection of backup tools available for the Mac. At the time, I wanted to use a tape drive to backup user data. I had an Exabyte VXA-1 kicking around the office. I'm not sure if the drive itself was broken or if Retrospect's Mac OS X drivers for the tape drive were defective. Either way, I couldn't get it to work. Shamefully, I admit that implementing a good backup scheme went on the backburner for a few months. Then, I thought of a way to use disk images to make incremental backups.


At the time, I was using Mike Bombich's Carbon Copy Cloner to make a daily clone of the server's drive to a portable FireWire hard disk. This worked quite well, but I only had one FireWire drive to use. So, while I could get a daily backup, I couldn't get it off site in case of a disaster. Being that I'd recently started re-reading Unix Power Tools, I was in a scripting mood and decided to use the find command and hdiutil to roll my own backup system.


The basic idea is that I call my bash script each night (easily accomplished with cron). When the script starts up, it calls find to search through a couple of folders for any files that have had their ctime or atime modified within the past day. Files meeting those criteria are copied to a staging location in /tmp.


Once all of the files are collected, I use hdiutil to create a read-only disk image of the staging folder. That disk image is then moved to a Backups folder in /Library. The next morning, I use Disk Utility to burn the latest disk image. Once a month, I burn a complete backup of the data folders using .Mac Backup (because it's convenient. You could easily use the Finder if you so desired). I throw the DVDs in a binder and bring them home. Then, I bring each day's disk image home and add it to the binder. Rinse, repeat.


One nice little bonus is that I have about a month's worth of disk images in /Library/Backups to work with. So when one of my users accidentally deletes last week's TPS report, I can easily open up the past Friday's disk image in the Finder and drag the file back into place. Quite convenient and saves me a trip home to bring in that day's CD. If you'd like to see my handy work, you can find the script here.



What kind of tricks are you doing with disk images? Have a piece of Mac backup software you prefer?


7 Comments

mechanist
2004-12-15 10:13:38
Ouch! Don't ever miss a day!
It's all god fun and games until someone loses an eye.


Or in this case, misses a day. Given the 'find' command in the script, if you ever miss a single day of this, you won't get backups of any files modified on that day until your next full backup. Given your plan of doing full backups once a month, this leaves you with as much as a 30-day window in which those files are not backed up, despite the daily regimen. Seems nice while it works, but this detail makes it seem extremely error-prone.

jldera
2004-12-15 11:15:21
RE: Ouch! Don't ever miss a day!
Well, the script is run automatically by cron every night. So, the backups go off without a hitch, unless some external force interferes (e.g. power outage). If that happens, I'm usually aware of it and can force the backup to run at another time.


However, I could also revise the script slightly. Have it touch at the end of each run. Then, I can use find's -newer switch to look for files that have been modified/accessed since the last time the script was run.

Visigothe
2004-12-15 13:51:25
rsync
Why not use rsync? It will find out for you what you should back up (incremental backups). Point it to the directories you care about, then hit the "make it so" button.


jldera
2004-12-15 13:54:05
RE: rsync
Correct me if I'm wrong, but rsync will overwrite the destination if it already exists, right? With this, I can have several different versions of a file, corresponding with when the file was modified or accessed. For example, I can get last Tuesday's version of a file as easily as I can get the Tuesday prior's version. With rsync, I don't think that would be possible.
balhoff
2004-12-15 20:06:10
you might like rdiff-backup
I am using rdiff-backup to do incremental backups, and it is wonderfully easy to use. I highly recommend it. I'm using the latest stable version, which ignores resource forks, but they're working on resource support for the next version.
leejoramo
2004-12-16 09:48:22
TidBits has great Mac OS X Backup ebook
You might want to take a look at the ebook just published by the TidBits folks as part of their Take-Control series. This is a excellent overview of most of the available GUI backup solutions.


http://www.tidbits.com/takecontrol/backup-macosx.html


Lee Joramo

P0000L
2005-03-18 08:53:13
rsync or any other...
With all the options available, common backup programs are still designed for GENERAL users.
Sometimes it is not enough, for ex. I couldn't find one to meet my demands: I need to monitor several files, to back them up (particularly to make a copy with a name like: name_of_file_(yy/mm/dd/hh/mm/ss).ext) immediatly after any change, which is not periodic and can happen at any moment.

Arthur
Augustine
Augustus
Aveline
Barbara
Barnabas
Barnard
Bartholomew
Basil
Beatrice
Bellingham
Benedict
Benjamin
Bennett
Bertram
Blaise
Blanche
Botolph


P.S. I do understand that such a task would take up quite of system resources.