5 October 2006

Easy iTunes library synchronisation

Using rsync, I have a very simple way of synchronising my iTunes libraries on two Macs.

To keep things simple, one Mac is the master, with the complete and most up-to-date copy of the music, and the other is the slave, updated from the master periodically. In my case, the master is my laptop (guava) and the slave is my Mac Mini (papaya).

You need to set up SSH key-based authentication between the two computers. Then on the slave computer, create a shell script with the following content, changing the host and username to match your master computer login:


/usr/bin/killall -SIGQUIT iTunes
/usr/bin/ssh matt@guava "/usr/bin/killall -SIGQUIT iTunes"
/usr/bin/rsync -aqz matt@guava:Music/iTunes/ $HOME/Music/iTunes

You need to change the username and host to match your master computer.

Running the script will shut down iTunes on both computers (necessary to commit any changes to disk) then synchronise the iTunes libraries from the master to the slave. Only file differences are transmitted over the network, so it will take only a few minutes to run if you do it regularly.

There are two limitations with this configuration: it only works for replicating a full copy of your music, and only in one direction (although using the -u option and running rsync at both ends would send updates in both directions). But on the plus side, it copies all your ratings, playlists, album art and music, and is very simple to get running.