Something geeky: Unison

Lately, all I’ve been posting about, it seems, is my cat and my running.

Now I want to post about something geeky.

At home, I have a desktop (a Mac mini) and a laptop (3+ year old G3 iBook). Most of the time I use my iBook, occasionally I’ll use the Mac mini if it’s something that requires a (tiny little) bit more horsepower; the difference in processor power and memory is slight but sometimes noticeable. (I know, I know, I should upgrade. Someday…) But mainly I use the Mac mini as a file server for my iBook. My music collection is on the mini, for example.

Lately, though, I’ve realized that I don’t have a backup strategy. I mean, my music collection is on both my mini and my iPod, so the chances that both drives would fail is small. But I don’t have anything else backed up. My Quicken data, going back years and years, exists in only one place. All of my personal writing – again, pretty much only in one place. Archived email, again, going back years… only in one place (not counting the stuff stored on my IMAP server, but that’s on a burly RAID system so I’m not too worried about it).

So I thought that a good partial solution would be to mirror the home directories of my mini and my iBook. I figured I could write a simple shell script that ran nightly and copied files back and forth depending on which files were new. That way, both machines would have copies of all my important files.

But… I’m a newbie when it comes to shell scripts. I goofed around writing pseudo-code but never got around to figuring out the actual scripting.

Then, poking around for examples, I found a program called unison. It’s essentially a mirroring tool – it does all the hard work of comparing files by date and differences and deciding which to keep. It will report if conflicts exist – for example, a file on both machines was modified in different ways. It’s like rsync in that it will only propagate the updates instead of the whole file and will use compression. It can be run either as a direct connection or tunneled over ssh.

So now, instead of writing a script, I can just invoke a simple command to mirror the specific directories I want. It’s perfect for my needs – simple mirroring over my local network. Although there are some other files I do want to make copies of (like my iTunes preference files and some other important preferences) so I’ll probably end up scripting the whole shebang anyway. But now the mirroring part is essentially done.

With the -path and -ignore switches, I can direct unison to only the directories I want, and leave alone the ones I don’t, like my ~/Music/iTunes/ directory. I’ve got over 20 GB of music and only have a 30 GB hard drive on my laptop. Like I said above, my iPod is my backup for my music.

And the best part is, unison was available as a package in Fink, the package manager I use. It’s in the “Unstable” group but that doesn’t worry me. So it was easy to install (almost a requirement for a Mac OS X program, even a command-line utility!).