Syncing your iTunes library with rsync (Mac version)
A couple of months ago I bought a Mac mini to act as Media Center. The mini is connected to a plasma TV and also to my music stereo, so it makes a lot of sense to have my iTunes library there. But it’s not my primary machine, and connecting my iPhone and iPods there is not the best of the ideas because, you know, it’s not exactly a desktop.
So, the best and most comfortable way to manage my iTunes library, sync my iPods and add new songs is doing it from my MacBook Pro. But sometimes the lid is just closed or the laptop is inside my backpack, so it’d be nice to have all the music it has also copied in my always-on Mac mini. Clearly, both iTunes libraries have to be synchronized. And for manageability’s sake, better be it one-way sync (from MacBook Pro to Mac mini) than two-way.
After doing a bit of google research turns out the best and simplest solution is using the UNIX rsync utility included in Mac OS X. rsync does incremental copies remotely, it’s easy to automate, and the incremental copying is so fine-grained that it’s even capable of just synchronizing the part of your files that has changed and not the actual whole file.
This is the process I’ve followed to sync my MacBook Pro iTunes library with my Mac mini:
- First of all, clean up your destination computer iTunes folder: Go to your destination computer (the Mac mini for me), close iTunes if it was already running, and delete all the contents that are inside your
Music/iTunesfolder. Now you should have this very folder, but empty. - Also, activate the Remote Login. Go to System Preferences > Sharing and check the Remote Login checkbox.
Now configure your primary computer to use rsync. In my case this is my MacBook Pro. Go there, and perform the following steps to write a small script you can launch every time you want to remotely update your destination computer iTunes library with the latests changes you’ve done in your primary computer:
- Create a directory in your home folder to store your script. For me a good location is always
bin/, so just open a terminal a write:$ cd $ mkdir bin
- Now inside the
bin/directory, create a new file called iTunesSync.sh with the following content:#!/bin/bash rsync --archive --verbose --rsh=ssh --delete /Users/javier/Music/iTunes/ DestinationComputerName.local:Music/iTunes
The
--archiveoption tellsrsyncto use a combination of useful syncing options (recursive, copy symlinks as symlinks, preserve permissions, preserve times, preserve group, preserve owner and omit directories when preserving times),--verboseadds more logging,--rsh=sshtells it to use ssh to establish the connection and--deleteto delete anything in the destination computer that’s not in the primary computer (this way we’re making sure no differences remain between the two iTunes libraries).Also Do not remember to change your primary computer’s source directory to the one you’re actually using (mine is showing my username), and put the destination computer’s name instead of DestinationComputerName followed by
.local (for example, in my case, it’d be Soyuz.local) - Give the right permissions to the file you just created to make it executable:
$ chmod 755 ~/bin/iTunesSync.sh
- Execute it to do the first synchronization:
$ ~/bin/iTunesSync.sh
The first time you do it it’ll copy the whole library. The process will take more or less time depending on your connection speed and library size.
That’s it. Now open your iTunes in your media center or your always-on computer and enjoy your music! Just don’t forget to run the script every time you add music to your iTunes or from time to time to be able to listen to your freshest acquisitions.
