Friday, August 10, 2012

Hack Time Machine Backup with Linux

If you need to get your files out of a Time Machine backup but you don't have a Mac, look no further. Get a computer with Linux on it. I'm using Ubuntu 12.04 but mostly you will just need to use the standard Linux shell terminal. It will be a painful experience, but hopefully a few things I've learned will help ease the pain a bit.
I started with Carson Baker's very helpful blog post on this which draws the basic map very clearly and succinctly. I needed to do a little research to clarify what he meant by cd'ing to the /media/Time Machine/.HFS+ Private Directory Data folder because you can't just type that in the terminal and get anywhere. In his comments he explains the use of tab-completion, which is amazingly helpful to know about.
In my case I cd'ed to the root level of my external drive, then typed .H, hit tab, and the rest filled itself in. That's voila for you! You can see it does mess with the spacing on the terminal command line, overwriting itself. But you get used to it.
Following his directions to figure out the hard link codes I found my backed up Pictures folder, which contained a Shoebox folder, for the app I had been using to store photos. Inside that is a folder for each year I've been using it for photo storage.
Listing the folders I discovered a huge problem. The photos for 2012 were there but the other years were simply more hard links! I had to find their hidden directory codes and cd to their folders. One thing I did to make the task a little easier is to write those codes to a file: ls -ls > /home/usr/Desktop/dirs.txt.
Looking further into the sub-folders for each year, my next problem was some contained a mixture of actual folders and hard links, which I had to get codes for, etc.
The above was the result of listing the contents of 2011, the folders being the months. So I needed to write those to a file for reference.
What a mess. Now the intact folders could be copied directly over very easily:
cp -rv . /home/usr/Pictures/2011. The copied hard links had to be deleted: rm -v /home/usr/Pictures/2011/01, etc.
Now one more level down are the folders for each day there were pictures. Inside those are the actual image files. These were also mixed folders and hard links. Rather than going through these one by one, finding the code, copying each day's folder, I made a script to automate at least this part. It creates the directories in the target drive for each missing folder (represented by a hard link), cd's to the coded directory for each, and copies the pictures over. All of that data has to be hard coded so that's a pain, but here's what it looked like.
The folders for July, 2011 looked like the above. Only 2 folders could be copied straight over. I saved the long form data to a text file: ls -ls > /home/usr/Desktop/dirs.txt.
That revealed the codes for each missing folder. I used that to write the following script and run it from the terminal in the top level of the .HFS+ Private Directory Data folder.
When it's moving all those files it's a beautiful thing to see, but it sure is a pain to create.


vjt said...


I've written a script to automate this process.

Find it on

Erik N. said...

That's amazing. So concise! Thanks for posting it.