iDEVICE BACKUP EXTRACTION

Background

Recently, a friend of mine needed to get some voice mails off their iPhone and into a digital format they could share with others. She asked me if I could lend a hand. The first thing I thought of was to connect the iPhone to the mic jack on a laptop then play the voicemails and record them using a sound recorder. That would have worked except for the fact that the sound quality was tolerable at best. Next I looked for an app that could extract the voice mails. There are plenty of those, but I really didn't feel like paying $30 or more for something I might only use once or twice. So I did some more research and discovered I didn't need an app at all. Just a little patience and some typing skills. What follows is the info I collected during my work...just in case anyone may be in a similar situation.

iTunes Backups

All the stuff on your iDevice (iPhone, iPod, etc) is managed through iTunes. Whenever you backup your iDevice the photos, videos and a whole lot more are stored on your computer. Even voice mails. Unlike a lot of things Apple does, these items are not stored in some form of proprietary format within the application. Instead, they are saved in their original state in a folder buried on the file system of the computer running iTunes. More specifically, each time you backup your iDevice, the backup is stored in the following location: Each backup is given its own directory with a ridiculously long name that makes no sense, for instance

4800a953edea62394342c602a9a1a7db0591b337

Not much you can tell from that. However, the date and time listed will be when the directory was last modified. In general, once a backup is made this date won't change unless you restore from it. So you can consider the last modified date and time shown as the date and time the backup was created.

Within each directory will be a host of files. One file for every type of item backed up. Again, these files will have stupidly long names consisting of random letters and numbers. There will be no file extensions regardless of the OS iTunes is running on. However, on OS X you can run the file command to determine the file type. For example, within a terminal typing

file ff90caad71edfae1d60017e2c98008fa399a7e9a

will return something like

JPEG image data, JFIF standard 1.02

Again, all types of files are stored in the backup directories. For my purpose, I was looking for two voic emails. These would have the file type of Adaptive Multi-Rate Codec, otherwise known by its file extension of amr (if they had one).

This is all well and good for a backup directory that contains only a handful of files. But if you are like my friend, you rarely backup your iDevice. Therefore, your backup directories may contain hundreds, even thousands, of files. How do you go through that haystack looking for your needle? In my case, I ran the ls command in a for loop, piped it through the file command and sent the results to a text file. Still, it was tedious searching through the file looking for the AMR files. There had to be a better way. So naturally, I scripted a solution.

A BASH Script

My solution, which you can see and copy here, was to list each available backup directory, allow me to choose which one to extract the files from, make a series of directories on my desktop for each file type (audio, video, etc) then determine each backup file's type and copy it to the correct directory while giving it the proper file extension. By doing that, I could run through each backup then look in the audio directory for the AMR files. It took a bit of trial and error, but in the end was handy. And it saved me from spending $30 on an app that basically does the same thing.

Yes, this script is ugly. I threw it together quickly to get the job done. And I have no plan to go back and make it all pretty. If someone wants to take it and run, feel free. However, I ask that you at least 1) credit me in your work and 2) send me a copy of it.

Now for you users of the Windows version of iTunes. The script won't work since it is Unix-based. And Windows doesn't have a built in facility for determining file types via the command line. But don't despair. Cygwin includes a file command; so you can whip up your own DOS batch file to do the same thing if you are so inclined.