Keep­ing iTunes li­braries in sync

itunes-sync-banner

Introduction

Last fri­day, my new Mac­Book Air ar­rived and as it's got 512 GB of disk space, I wanted to have my iTunes li­brary on it, so I can hear my mu­sic every­where. Af­ter search­ing for a so­lu­tion on the in­ter­net, I found out that it's pretty sim­ple to keep my iTunes li­braries in sync us­ing Au­toma­tor and a sys­tem app called rsync. Set­ting every­thing up is very sim­ple and takes only a few steps.

Step 1: Sharing your iTunes folder in your network

To be­gin, you will have to en­able file shar­ing in the sys­tem pref­er­ences of the com­puter that con­tains the orig­i­nal iTunes li­brary. Go to shar­ing and ac­ti­vate the sec­ond en­try in the list of pos­si­ble net­work shares. In Ger­man, it's called "Dateifreigabe", so in Eng­lish it should be called "file shar­ing" or sim­i­lar. Af­ter that is done, you need to add your iTunes folder to the list of shared fold­ers. This folder is nor­mally called iTunes and lo­cated in your Mu­sic folder. When you've done that, you'll see that a list of users ap­peared. If you want to, you can re­strict your net­work share, so that it is read-only. Bildschirmfoto 2013-06-23 um 11.19.09

Step 2: Creating the Automator script

The first thing I should tell you be­fore you con­tinue is that you can only sync your iTunes li­brary in one di­rec­tion us­ing rsync. How­ever it is pos­si­ble to cre­ate this Au­toma­tor script on both com­put­ers and run both to sync your li­brary in both di­rec­tions, if you want to, but I don't rec­om­mend you to do it. Now, to get started, open Au­toma­tor on your tar­get com­puter and cre­ate a new Work­flow. Your win­dow should look like this: Bildschirmfoto 2013-06-23 um 11.47.00The first thing you want to do is to con­nect to the com­puter that con­tains the orig­i­nal li­brary. To do that, search for "Get spec­i­fied servers" and drag that en­try into your work­flow. In the box that ap­pears, click on "Add..." and se­lect your source com­puter. You'll now see a URI, like "afp://​192.168.1.2:548" in the text field over your com­put­er's list. Add a slash and the name of the iTunes folder on your source com­puter (in most cases "/​iTunes") and click "OK". Bildschirmfoto 2013-06-23 um 11.52.30Next, search for "Con­nect to servers" and drag that into your work­flow, un­der "Get spec­i­fied servers". The iTunes li­brary of your source com­puter is now mounted in your (tar­get) com­puter. Now, we have to run our rsync com­mand. To do that, search for "Run Shell Script" and drag that into your work­flow. In the box that ap­peared now, in­sert the fol­low­ing code:

rsync -av --force --delete --size-only \
--exclude "Mobile Applications" \
--exclude "Previous iTunes Libraries" \
--exclude "Audiobooks" \
/Volumes/iTunes ~/Music/> ~/Documents/iTunesSync.log
The --exclude commands tell rsync which directories shouldn't be synced. If you, for example, don't want to exclude your audiobooks, just remove that line. If you want to exclude an additional folder, just add another line right after the last --exclude command:

--exclude "Your folder name" \
Your library will now be synced from your source computer to your target computer. Remember, that it only syncs in one direction right now and that files that aren't on the source computer will also be deleted on the target computer. After everything synced, you may want to eject the network share. To do that, search for "Eject disk" and drag that into your workflow. Now, you're done. Your workflow should now look like this: Bildschirmfoto 2013-06-23 um 12.05.42And that's it. Now, if you start this workflow, your iTunes library should be synced over to the target computer. You can see the current status by opening the file iTunesSync.log in your Documents folder. If this is the first time you sync your library, the process could take a long time depending on how large your library is. Mine is about 40 GB large and it took about 1.5 hours to sync everything over. Now, if you want to, you can save the workflow and put it somewhere so you can access it quickly.

Pro Tip:

This work­flow is­n't only lim­ited to sync­ing iTunes li­braries. You can sync any folder from your source to your tar­get com­puter us­ing this method. Just change the folder names so that they cor­re­spond to the folder you want to sync and you're done. As al­ways, if you've got any ques­tions or ideas, just leave them in the com­ments be­low and I'll try to an­swer them.