22 March 2008

Using Unsion to sync iTunes

Update: I accidentally used forward slashes instead of back slashes for the backup dir, preventing the iTunes Library file from being synchonised. I did warn you!

I recently purchased a new Mac laptop to replace my rather aging Ubuntu laptop. Ubuntu's a great operating system but of course the Mac is often considered the best of both worlds. It's got the Unix and (somewhat) open source foundations but it's packaged into a great looking and widely supported interface.

Part of the advantage of this is that many of the most popular software applications are available natively. iTunes, for example, is the app I have been using to manage my music on my Windows machine for years now. Everyone knows iTunes (love it or hate it) but generally it's a great app for managing playlists etc. It sort of works on Ubuntu through Wine but now that I've got the Mac it's native - the same app using the same folder structure on two different computers running two different operating systems.

The obvious next question is why can't these two be in sync? What a pain to have to manage playlists on two separate computers and have to watch as my play counts get further and further apart and podcasts get infinitely downloaded again and again. I've been evaluating solutions to get this working. PowerFolder is a free app that synchronises stuff but it's java and only is really integrated into Windows (by the way even though it's open source they seem to have implemented a stupid 3 folder / 10 GB limit. What? Someone fork that sucker!). At the proprietary end of the spectrum we've got SugarSync. This is a very nice sounding service (which I haven't tried yet - it's brand new) and it has the advantage of storing your stuff online too. But it costs quite a bit, especially for the quantity of stuff I want to sync.

So in the end it's Unix to the rescue! Unison is a tool born in the Unix world that does one thing and does it well - sync! Unison can be used directly on the command line or by creating so called 'profile' files which contain all the information. Here's the profile I've created for iTunes. You only need to create it on one end.

# Synchronise iTunes library
# roots
root = D:/My Music/iTunes
root = ssh://

#Ignore funny mac files
ignore = Name .DS_Store
ignore = Name ._*

# Keep backups of the iTunes library (itl) file
backuplocation = central
backupdir = D:\My Music\iTunes\Library Backup
backup = Name *.itl
backupprefix = $VERSION.
backupsuffix =
maxbackups = 20

# ask no questions
auto = true
batch = true

# favour newer files
times = true
force = newer

# there are a lot of files here so we need it quick
fastcheck = true

I saved this as C:\Documents and Settings\\.unison\itunes.prf and I can run it from my Windows pc by running 'unison itunes'.

Warning! Warning!
So far this seems to work. But I still need to test it. I wouldn't recommend running this yourself until either I've tested it or you've tested it. You have been warned.

Let's step through from the beginning.
We want to synchronise the iTunes music folder on the Windows PC at D:/My Music/iTunes/Library Backup (this is probably different for you. Think C:/Documents and Settings//My Documents/My Music/iTunes/Library Backup). On the mac (which has a static IP of we want to synchonise to ~/Music/iTunes.
We want to ignore those files the Mac likes to store.
We want to keep backups of the itl iTunes Library file - the delicate file that stores everything about your library. I'm going to keep 20 backups because I don't want to lose this. Consider having other backups of your library as well through an external drive or something like Mozy.
We want Unison to run without bothering us with questions.
We want newer versions of files to replace old automatically.
And we want Unsion to compare files by looking at their modified dates. Doing checksums would take a *long* time with so many files. After comparing times and finding a difference, Unison checksums first anyway to be safe.

There are issues though.
- We need to have SSH successfully set up so the PC can talk to the Mac.
- Perhaps we should make sure iTunes is closed at both ends before doing anything.
- It would be good to have an easy way to initiate the sync at either end.
- Automatic sync every few hours or so would be good too.

I'm going to try to work through all of these as I get the time. Stay tuned.

1 comment:

Anonymous said...

Jono, this is exactly what I've been looking for.

Have you had any breakthroughs on the issues you listed?


Post a Comment