Laptop sync script

August 6th, 2008

UPDATED: fixed a typo that meant directories with spaces weren't syncing (arrrgghhhh); changed example dirs/files

I've needed this sorting for ages - I've spent too long copying files adhoc between my iMac and MacBook. Tonight I wrote a simple ruby script to easily push changes to my laptop and pull them back again. Note that everything is driven from the desktop end - I don't push changes from my laptop to my desktop.

The script is easy enough to modify if you want to use it. Just bear in mind it comes with no warranty of any sort, and I'm not responsible if it deletes everything on your hard drive. It's fairly safe, the -u option to rsync stops it overwriting newer files if you sync in the wrong direction (that won't stop it deleting stuff, though). I ran it just and nothing important disappeared, that I noticed anyway...

All you need to do it is put the file in your path as sync_to_laptop (I used ~/bin), create a symbolic link called sync_from_laptop and make sure they are executable (you knew all this, right?):

    cd ~/bin
    ln -s sync_to_laptop sync_from_laptop
    chmod +x sync_to_laptop sync_from_laptop

Then modify the constants at the top to suit your needs.

I'm sure there's a more elegant way to build the rsync command, but, meh... it works, and I need it for this weekend.

Code follows. Feedback or "why didn't you use XYZ that does all this and more?"-style comments welcome.

Read the rest of this entry