rsync is your friend.

Say you need to keep multiple copies of a directory full of data on multiple computers, so that all of them have an up-to-date bit-for-bit copy of the same data. For me, the prime example of this is my mp3 library. I maintain the master copy of the library on my desktop computer, and I want at least one or two entire backup copies of that library on other computers, so that if my hard drive crashes, I’ve got something to recover from.

This process is called “making backups.” Backups are your friend. And the perfect UNIX tool for this particular task is rsync. Rsync is also your friend.

rsync -rav /path/to/your/master/copy/of/Music/ username@otherhost:/path/to/your/backup/copy/of/Music

You can also get much fancier with this, and exclude particular file types if, say, you only want audio files, and no copies of movies. Simply add an “--exclude '*.m4v' (or whatever suffix you want to exclude) to the command, and boom, rsync keeps everything except m4v files up to date between the two.

rsync -rav --exclude '*.m4v' /path/to/your/Music/ username@otherhost:/path/to/backup/of/your/Music

Naturally, you’d want to set up public keys on the host in question, so you don’t have to type your password all the time, but we’ll get to that later. For now, you can type the command, substituting the appropriate paths for the source and destination you want to copy from/to, type the password that one time, and then marvel at the automated syncing.

As is, this is only going to execute when you manually run the command. However, wrap it in a shell script, and add a crontab entry for it, and presto, you’ve got nightly backups going on. And yeah, I’ll probably write up a brief “crontab for beginners” here, as well, in the event you’ve never used that. Or you could google it for yourself. For now, here’s an example of what the output will look like in your shell:

mns$ rsync -rav --exclude '*.m4v' --exclude '*.mov' /Volumes/shellfish/Music/ mns@myserveraddress:/Volumes/ashurbanipal/Music
building file list ... done
Chris Bell/
Chris Bell/I Am the Cosmos (Deluxe Version)/
Compilations/Essential Irish Drinking Songs & Sing Alongs - Whiskey In the Jar/
Compilations/Sea Shanties/
Compilations/The Essential Kris Kristofferson/
Danu/Up In the Air/
Downloads/You and Your Sister (Single Version) _ I Am the Cosmos (Deluxe Version) _ Chris Bell.tmp/
Flying Column/Four Green Fields/
Home Videos/
Luke Kelly/The Best Of Luke Kelly/1-04 The Gartan Mother's Lullaby.m4a
Luke Kelly/The Best Of Luke Kelly/1-06 Alabama '58.m4a
Luke Kelly/The Best Of Luke Kelly/2-06 For What Died the Sons of Roisin.m4a
Luke Kelly/The Best Of Luke Kelly/2-08 The Town I Loved So Well.m4a
Luke Kelly/The Best Of Luke Kelly/2-10 Maids When You're Young Never Wed an Old Man.m4a
Matthew N. Sharp/
Podcasts/Ridiculous Dialogue/34 - Swimming in Denim.mp3
Podcasts/Ridiculous Dialogue/35 - Milk Sandwiches.mp3
Podcasts/Ridiculous Dialogue/36 - The General Leak.mp3
Ronnie Drew/The Best Of Ronnie Drew/1-02 Donegal Danny.m4a
Seamus Ennis/Forty Years of Irish Piping/17 Piper of the Embers _ Down the Back Lane _ Sixpenny Money _ Paudeen O'Rafferty.m4a
Seawolves/Seawolves/02 Chemin de Francois.m4a
Seawolves/Seawolves/10 Gaspe Reel.m4a
Seawolves/Seawolves/11 John Kanakanaka.m4a
Shane MacGowan/The Snake/02 Nancy Whiskey.m4a
Shane MacGowan/The Snake/03 The Song With No Name.m4a
Shane MacGowan/The Snake/16 Donegal Express.m4a
The Dubliners/50 Years/09 Raglan Road (feat. Luke Kelly).m4a
The Dubliners/50 Years/14 Scorn Not His Simplicity (feat. Luke Kelly).m4a
The Dubliners/50 Years/43 McAlpine's Fusiliers (feat. Ronnie Drew) [Live].m4a
The Men of No Property/This Is Free Belfast!/13 The Bogside Man.m4a
The Men of No Property/This Is Free Belfast!/15 Ballymurphy.m4a
[long list of files deleted]
Willie Nelson/The Essential Willie Nelson/2-19 One Time Too Many (with Steven Tyler).m4a

sent 522820836 bytes received 498124 bytes 6666483.57 bytes/sec
total size is 492744977453 speedup is 941.58


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s