Backups with RSYNC in OS X Tiger

OS X made a big improvement to some of their command line utilities in OS X 10.4 Tiger. CP, MV, TAR, and RSYNC can handle multipart Mac files with no problem. Read on for an awesome way to back up your files.

rsync, as you might have guessed, is a program to remotely sync files. I won't go over its many options here, I'll just cover one: how to back up files from one machine to another over a network. I'll flesh this out later, but for now, here's the basics.

  • Install Tiger on two Macs, referred to here as your main Mac and the backup server.
  • Create an SSH key on your main Mac. Copy the public key to the backup server. (Details to follow.) rsync, by default, uses SSH as its transport.
  • Create a user on the backup Mac. To keep things simple, give it the same name as the account you use on your main Mac.
  • Now, launch Terminal and issue this one command:
    rsync -avz ~/* remote.ip:~/
  • Now watch as your entire home directory is copied to the remote server.
  • Once it's done, issue this command:
    touch temp-test-file
  • Now, press the up arrow twice and press return. This will run the previously-entered 'rsync' command again. Watch: after building the file list, it will determine what's new and copy just that new file. Awesome! Good bye, long copy-everything-every-time backups! Hello, incrementals!

Running the same rsync command over and over (say, each night at 4am) will copy only files that are new or have changed. But, it won't delete old files on the backup server if you've deleted them from your main machine. You say you accidentally deleted something that was on your desktop a week ago? It'll be on the backup server, no matter how many times you've run rsync in the meantime. Is that cool or what?

Update: according to this, you need to say '-E' for rsync to copy resource forks in Tiger. For non-Tiger users, look at RsyncX to save your resource forks, but note that you'll need it installed on both Macs.

Update 2: MacDevCenter has created a whole article on backing up with rsync. It uses iCal to schedule an AppleScript, and of course using a shell script and cron would be much neater (doesn't need to do anything special to handle output and messages; doesn't require iCal to be running--hell, doesn't even require anyone to be logged in!) but it's a good overview and it has lots of good info in the comments.

sample