Keeping a copy of your iTunes library up-to-date with rsync

Let's say you have an iTunes library in which you organise all your music, and maybe you synchronise it with your iPod. But your iTunes library is on a Powerbook or iBook, and so it's not always awake. What you'd like to do is have your iTunes library backed up and kept synchronised with an always-on machine on your LAN, so that machines in your house with big speakers can always have access to your music, perhaps via a system using DAAP.

Here, we'll use rsync to keep your always-on server synchronised with your mac's iTunes collection. It achieves this by checking file size and modification date, and only copying files across when they are new, or have been changed. Thus most backups should only take seconds, after the initial copy.


On the mac

If you'd like to be able to run backups without having to type on the mac, make sure you have `remote login' enabled under System Preferences-->sharing.

On the destination machine

Preparation depends on the operating system you are running - I'm using Debian. In general, you'll need a copy of rsync, and an SSH client (also an SSH server if you wish to initiate the backup from your mac).


First, create a directory on the target computer (server) where a backup of your iTunes directory will be made. For this example, we'll call it music-backup:

mkdir music-backup
cd music-backup

There are two styles of backup: Backup where everything is saved including old files that no longer exist on the mac, and backup where an exact copy of the mac's music is maintained on the server.

To be able to run this command without being in the music-backup directory, change the "." to an absolute path. For example, rsync -avz yourmac:Music/iTunes/"iTunes\ Music" /home/you/music-backup

Avoiding disasters

Especially while using the --delete option, you can accidentally destroy a lot of stuff, or waste a lot of bandwidth and time with this system. To test what will happen without actually doing it, add the flag -n to the command, so that it becomes rsync -avzn...

Valid XHTML 1.0!