Backing up your iTunes / iPhone / iPad universe on Windows 7

Although I've never owned a Mac, I'm about as deep into the iUniverse as one can get. My entire life is crammed into this iPhone and has been for nearing 4 years now. I'm not the only one in this situation. Losing the device isn't that big of a deal since you can go buy another one, plug it into iTunes and drop the last backup of your life on it without skipping a beat. But what happens when your computer goes up in flames? Or what if you switch computers? You want to be able to get iTunes back up and running exactly as you left it, complete with all the apps, iPhone & iPad backups, playlists, and music libraries. Unfortunately, Apple has chosen to make the back-end happenings quite complicated. The following is what I've figured out from snooping around my machine and from the intarwebs and how to automate the process of backing all of this up.

Before we get started, note that this post applies to Windows 7 and iTunes 10.1.1.4. Future versions of iTunes may not be organized the same way, and could ruin Christmas. Previous versions of iTunes and Windows may have the same difficulties. I'll try to keep up with changes to iTunes in future posts.

Couldn't care less about what these files are and just want the backup script? Fine, here it is. Your browser may interpret it as just a text file (Chrome did). Save it as such, then change the extension to .bat to make it executable. Replace 'Kevin' with your Windows 7 user name and 'Z:\iTunes_Backup' with a backup directory of your choice. I do recommended you read on though...

Backing up the iTunes folder in your user directory

There are two important files located here: C:\Users\UserName\Music\iTunes\
Apple explains what they do here, but I'll regurgitate it here as well. (Interesting note: That knowledge base page I linked to shows the files as 'iTunes Library' but mine are named 'iTunes Music Library'.)

iTunes Music Library.xml. - This file is pretty long (mine was 104,373 lines long!) and contains all sorts of information about the tracks, like where they live, play counts, etc. Other applications use this file, but it looks like only iLife-related ones care. This is more important on Mac OS.

iTunes Music Library.itl - This is the important one! It's a database that contains song-specific data like ratings and comments. Most importantly, it contains your playlists. Sadly, it's not something that's human readable. We want to hang on to this one.

If you've never changed your iTunes media folder, it lives here and is aptly named 'iTunes Media'. We'll discuss that folder later.

What else is in this folder? In my installation, it looks like the rest of the stuff here is a graveyard of old files and apps from iTunes-es of yesteryear. It's better to be safe than sorry, so I back up the entire business.

Backing up iTunes local application data

The next folder we want to hang on to is: C:\Users\UserName\AppData\Local\Apple Computer\iTunes
iPodDevices.xml looks like it keeps track of what devices iTunes has found in the past.
Not going to lie to you, I have no idea what the rest of these files are for. The only reason I recommend hanging on to them is because the timestamp is always recent on them, so iTunes is actively using them. 

Backing up iTunes roaming application data

Hang on to this guy: C:\Users\UserName\AppData\Roaming\Apple Computer\iTunes

There are several more files and folders in this directory, but again I'm not too sure what they're for. We'll keep them though. 

Also, this guy: C:\Users\UserName\AppData\Roaming\Apple Computer\MobileSync

This is where your iPhone and iPad backups live. They're named incoherently, but these are the backups you choose from in iTunes when restoring from an old image of your device. There should be a few gigs of data here.

Let's also hang on to these other folders since they seem to also be related:
C:\Users\UserName\AppData\Roaming\Apple Computer\SyncServices
C:\Users\UserName\AppData\Roaming\Apple Computer\Preferences
C:\Users\UserName\AppData\Roaming\Apple Computer\Logs

Backing up Music, Video, Books, Apps, and everything else

Find your iTunes media folder location by opening up iTunes, then selecting 'Edit' - 'Preferences' - 'Advanced' (tab). iTunes defaults to C:\Users\UserName\Music\iTunes\iTunes Media

This is where iTunes keeps your apps, downloaded music, videos, podcasts, movies, TV shows, books, etc. That said, this is a pretty important directory. I don't recommend keeping it in the default location; instead I'd rather see it on a separate hard drive so it's not tied into your user account and with the rest of the OS. As a rule I always keep data separate from the operating system drive in case it goes down. Since we're backing this stuff up, it may be a moot point, but a good practice nonetheless. 

Backing up pictures and videos taken on your iPhone

Unfortunately, I haven't figured out how to automate this part yet. When Windows finds your phone after you've plugged it in, it shows up in Windows Explorer and you can manually copy those files out of it.

Automating this process with a script

I use a script to back up my data, and you can download it here. Unless you happen to be me, you'll need to change it slightly.
  1. Change all instances of 'Kevin' to whatever your Windows 7 user name is. If you're name is Kevin, you just saved yourself nearly 8 seconds of work.
  2. Change all instances of 'Y:\iTunes_Backup' to the path where you want to back all this stuff up to. 
  3. Change 'J:\iTunes' to your iTunes media directory. If you keep it in the default location, C:\Users\UserName\Music\iTunes\, you can comment this line out since it will be included in the first robocopy command. Add two colons '::' to the beginning of the line to comment it out.
  4. Don't be alarmed when launching this script opens a command prompt; people get scared of DOS-looking things. Nothing shady is going on, with the exception of sending your bank account and credit card information to Wikileaks. 
Every time I sync my phone, download music, or do anything else iTunes related, I always launch the script after I close the application. It just takes a second to kick off, then you can walk away and let it do its thing. Just make sure you close iTunes before you run it. Putting an icon on your desktop helps too. 

Recovering from a disaster with your backup

Simply install the latest version of iTunes, copy your backup files to their original locations, and pray that this version of iTunes hasn't changed where it wants to see these things. Since we kept the folder structure the same in the backup as it is in your user directory, you can simply copy all of the backup data from its safe haven into your user directory once you get your computer fixed/installed/revived/etc. If you are able to maintain the same paths that you had before, when you open up iTunes after restoring all of these files, everything will be exactly as you left it. If the path to your iTunes media folder has changed, you'll have to create a new library and the associated playlists, comments, ratings, etc will be wiped out. Bummer aye? That's iTunes for ya. Hey, at least you've got your iPhone backups, right?


Hit up the comments below this post if you have any questions or corrections.