Using rsync to sync iTunes on two computers

Oct 04, '04 08:55:00AM

Contributed by: Anonymous

At home I have a laptop, and at work a desktop. I usually surf and do email and load music on my laptop (either iTunes store, or from CDs), but occasionally I'll shop the iTunes store at work. This means that, if I want to sync my songs to each machine, I can't simply copy my laptop's iTunes directory from the laptop to the desktop, since I'd lose some purchases. The process I use involves four steps, so it's not the simplest, but it works well...

Before starting, you must be able to ssh from either machine to the other, so the keys are set up and rsync can use ssh. Then I rsync from the laptop to the desktop, then the desktop to the laptop. If files are copied to the desktop, I run iTunes on that machine and choose "Add to Library" on the iTunes directory, which scans the entire iTunes directory and adds the new songs to iTune's library. Similarly on the laptop.

The rsync command, which is a single line is:

 rsync --ignore-existing --progress --recursive --perms  --times \
--size-only --whole-file --rsh=ssh --exclude='.*' \
--dry-run Music/iTunes/  DesktopMachine.local:Music/iTunes
The dry-run argument is to test and make sure everything is setup properly before attempting it. If it seems to be doing what you want, eliminate the dry-run argument and let it go. From the desktop machine, I'd rsync to LaptopMachine instead -- use the appropriate system names, of course.

Note that there are some sync solutions that work bi-directionally. But they all seem to make the reasonable assumption that if you have the same file (name) on two machines, but the last-modified date is different, sync over the most recent one. With iTunes, this doesn't make sense, since file contents don't change (unless you re-encode your library). This results in many more files being copied than necessary -- at least the first time. That and a couple of other minor issues are why I use rsync.

Be careful in playing with rsync options. If you're not careful, you can have it deleting files on the other machine which don't exist on the source machine while attempting to make the two directories look the same.

Comments (12)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040927151426616