Webreakstuff's blog on design, development and strategy. Click here to subscribe.

Backing up with rsync on OSX

Fred Oliveira on April 16, 2005

Today I had to get a lot of work done on the Powerbook, and during that time, it occurred to me that if I somehow screwed up my hard-drive I’d have no real complete backup of everything I’ve been doing lately. So I decided to whip back some of my old Unix tricks and fix that problem on my Tiger install. The good old Rsync backup is back.

If you don’t know what rsync is or what it does, here’s something that should give you the idea (from the manpage):

The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection, using an efficient checksum-search algorithm described in the technical report that accompanies this package.

In plain english, it creates a backup of your files, and whenever you re-backup, it transfers only the differences between your backup-files and your changed-files so the whole process is faster. It is a solid way to create backups of any kind of file, and is the usual way mirror sites use to, well, mirror other sites.

So, using rsync is pretty easy (its actually a single line - if you like simplicity as much as I do, you’ll like this):

rsync -av –delete SOURCE DESTINATION

An example: lets say you’re backing up your home directory (like I will be doing), and that you have an external hard-drive plugged in. You’d run this command to backup your home:

rsync -av –delete ~/ /Volumes/backup/

And voilá! Your files would be backed-up into your external hard-drive. But with that done, you’re probably wondering how to get your files back if you ever need to restore your home directory to the way it was. That’s pretty easy too. All you have to do is reverse the directories in the command and remove the delete command because we don’t need it (explanation below), so to restore the example backup above, we’d run:

rsync -av –delete /Volumes/backup/ ~/

Your files would be back to the way they were, just like that. No real reason to lose any of your files now, with a live copy and a stored backup.

The –delete option: what this does is it removes from the target, the files that don’t exist in the source. Meaning, lets say you have your backup files, and on your live copy you delete some stuff you don’t really need. You probably want those files off of your backup too so when you restore they don’t come back.

So, there are two reasons why you probably won’t need it when restoring: 1) you wont have any extra files, and 2) if you DO have files on the directory you’re restoring, you probably need them, so, you maintain them by not using the –delete option


Comments on this post

Benjamin

The last time I tried doing this (on Panther), I ran into one hell of a bug when I tried to restore: rsync doesn’t do resource forks. I lost eight disk images, a ton of fonts, and quite a few documents that way. I know that Apple has modified several standard Unix commands on Tiger to handle resource forks (among them scp, cp, mv, and a few others), but I don’t know whether rsync is one of them. You probably should check that before relying too much on an rsync backup.

Kenny

Looks like it works on Tiger but you need to use the -E flag to make sure it copies resource forks (or alias rsynch in your .profile to do this automatically).

Sorry, the comment form is closed at this time.