MacOS – How to setup an iTunes library to use between two Macs


As you can tell this is no where near work related. I have an iMac G5 where my itunes is currently hosted, I have also just got a new MacBook Pro. What I want to be able to do is sync my itunes library from my iMac to my MacBook Pro, that way it can be accessible away from my home network, then if I make any changes to the itunes library (like change a track name) it will sync these changes back once I connect back to the home network.

My current itunes contains music, videos, podcasts, playlists and iPhone apps, I would also like iTunes to track play counts collectively between the iMac and the MacBook Pro.

Best Answer

This is pretty tricky, as there are several files containing iTunes metadata in addition to live running instances of iTunes. The trickiest of these to overcome is the fact that the running instance of iTunes does not write out data until it quits, so if you have running instances on both your iMac and MBP and you update the files underneath them, they will get lost. Further, paths are contained within the files, so this will not work unless you have identical paths on both machines (assuming you have not changed the defaults and have the same username, this would put the music in /Users/username/Music/iTunes/iTunes Music/ and the metadata in /Users/username/Music/iTunes/{iTunes Library,iTunes Music Library.xml}).

You can keep the music folder up to date on both by using rsync, but this only works cleanly if you either always add or delete items on one of the machines or if you only add items. If so, the two lines on the MBP would work:

% rsync -a /Users/<username>/Music/iTunes/iTunes\ Music <G5hostname>:/Users/<username>/Music/iTunes
% rsync -a <G5hostname>:/Users/<username>/Music/iTunes/iTunes\ Music /Users/<username>/Music/iTunes

You'll probably want to set up automatic authentication using public keys auth in SSH and put this in a cronjob.

To accomplish moving the metadata, I suggest you have a script running on both machines under cron which first determines if iTunces is running on the local machine and if it is not, it rsyncs the metadata files from the other server if the content on the other server is newer than that locally. Something like:

if [ `ps -ax | grep -v grep | grep -c iTunes` -ne 0 ] ; do
   rsync -au <otherhostname>:/Users/<username>/Music/iTunes/{iTunes\ Library,iTunes Music\ Library.xml} /Users/<username>/Music/iTunes

This still assumes that you don't make mods both instances with both instances being up continuously. Also, I have not tested this out, so there are probably some syntax errors or subtleties I'm missing.