Monday, December 11, 2006
If you've been reading your Slashdot, etc, you'll know that you can protect yourself from drive failure by setting up a RAID1 system. RAID1 is where you have 2 (or more perhaps) drives of identical size and they have the identical data on them. So if one fails you can pull it out, put a new one in and re-build the image. This, it needs to be repeated, is not a back up. If the Big One does hit, both drives are probably toast.
So I set one up. CompUSA had the right price on Maxtor 500 Gig drives and I got myself a pair of them. Then I got a nice dual-drive Firewire enclosure and set up the RAID1.
iTunes has a cool feature in the Advanced menu item: Consolidate Library... If you set the library location to a particular folder (say, one on your new RAID1 drive) and select Consolidate Library... it will copy every song from its old location to its new home in the new folder. Or at least it's supposed to. I think (WARNING! I'm making this part up) that writing to RAID1 drives is slower than writing to a single drive, and that iTunes expects things to happen at a particular rate and if they don't then there is a problem. iTunes refused to copy more than about 10% of the library to the new drive no matter how I begged and pleaded.
One solution to this problem is to copy everything by hand and then rebuild the library. This would work great except that I would lose all my metadata (play counts, ratings, etc) and I didn't want that to happen.
In my day-job I write Python code and one of the super-cool things available for Python on the Mac is a module called Appscript. It allows the Programmer to send AppleScript commands to programs via Python. My next idea was to copy everything over by hand and then use Appscript to programmatically set the location attribute of each song to its new home. Alas! The location attribute of the file_track is read-only. Dang.
But then, prompted by a comment on the MacPython mailing list and heartened by some Google results, I hit upon Hank's Foolproof Library Migration Schemetm:
- Copy all the songs over to the new drive (one way to do this if some songs are already there because of a failed attempt at Consolidation is to open the terminal and type cp -R -n -p /Volumes/oldDrive/path/components/iTunes/ /Volumes/RAID/iTunes/) Note in the parenthetical command that the file structure is going to be the same from iTunes/ on down; this is critical to HFLMS.
- Now copy the iTunes Music Library.xml file to some happy place.
- Edit this file using your favorite editor. I used vi in a terminal window.
- Do a global substitution of oldDrive/path/component to RAID. This will have the effect of changing the location attribute of every song to the new drive. (in vi you can type :1,$s/oldDrive\/path\/component/RAID/)
- Save the file.
- Now delete (or copy to a safe place) the iTunes Library file (this a binary version of the xml file you just finished editing).
- Start up iTunes, select Import... and open the xml file you just finished editing. This will rebuild your library and iTunes will know how to find all your songs in their new home.
Links to this post: