Fixing Time Machine Permission Errors

January 29, 2011

This morning I inadvertently switched git repositories before committing my changes to git — several days of work were instantly wiped out. No problem, I told myself, I’ll use Time Machine on my Mac. I backup regularly. I launched the Star Wars view, selected my directory, and clicked the restore button.

It failed.

Time Machine complained about write permissions. Nothing was restored. My heart skipped a beat. After Googling around for a few hours and trying all sorts of things, I finally got it to work. The result is documented here just in case you run into the same issue. I hope it saves you time!

Fixing a busted Time Machine

First, go to the very top of your directory tree where all disks are mounted. Make sure your backup drive is attached and alive.

% cd /Volumes

Look for the volume that represents your backup drive. cd to that:

%cd ScottBackup
%cd Backups.backupdb

Now start looking through the mount point, shown here as /Volumes/ScottBackup/Backups.backupdb. You’ll notice that the directory tree begins with the name of your computer, followed by a set of directories, each of them named with a timestamp. Mine look like this:

2011-01-11-003733/            2011-01-29-030503/

These are in the format of YYYY-MM-DD-time. Pick one that you want to restore, and cd to that directory. Here I choose a backup at 3:05am on January 29th:

% cd 2011-01-29-030503

The top level directory should look like your hard drive:

% ls
Macintosh HD/

Surf through these directories. It should mirror your existing drive. Under the covers, however, Mac OS/X seems to be hacking the file system. The files don’t actually exist in multiple copies. Instead, they’re layered into a database and made to appear as though they’re in one piece. No matter.

Find the directory you want to restore. Now comes the tricky part.

First, create a tarball of your disk and place it on ~/Desktop. Let’s assume for this example that my directory is /Users/spenberthy/myapp/lostdir:

% cd Users/spenberthy/myapp
% tar cfvz ~/Desktop/lostdir.tar.gz lostdir

This will take a bit of time for a large directory. You’ll hear your backup disk grind as OS/X reassembles all the files, reads them, and stuffs them into the tarball.

Now get out of there. Move to your desktop:

% cd ~/Desktop

Decide where you want to restore the files, then move there:

% cd ~/myapp

For the first pass, unload the tarball onto your hard drive:

% tar xfvz ~/Desktop/lostdir.tar.gz

You’ll be greeted with numerous permission errors. Ignore them. We’re almost there. If you list the files that you restored using “ls -l”, you’ll notice something odd:

% ls -l
total 22800
-rw-r--r--+   1 spenberthy  staff    56B Aug  5 17:17 README
drwxr-xr-x+  10 spenberthy  staff   340B Jan 29 06:46 Reachability/
drwxr-xr-x+  14 spenberthy  staff   476B Jan 29 06:46 Twitter-OAuth-iPhone/
drwxr-xr-x+   8 spenberthy  staff   272B Jan 29 06:46 certs/

See those plus signs on the left? Well, they were new to me. These are called extended permissions and use an elaborate, English-like syntax. To see these use the command “ls -lE@”:

% ls -le@
total 22800
-rw-r--r--+   1 spenberthy  staff    56B Aug  5 17:17 README
 0: group:everyone deny write,delete,append,writeattr,writeextattr,chown
drwxr-xr-x+  10 spenberthy  staff   340B Jan 29 06:46 Reachability/
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown
drwxr-xr-x+  14 spenberthy  staff   476B Jan 29 06:46 Twitter-OAuth-iPhone/
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown
drwxr-xr-x+   8 spenberthy  staff   272B Jan 29 06:46 certs/

Those permissions are the problem. Let’s get rid of them.

% chmod -R -a# 0 *

If you list the contents again, your extended permissions should be gone, as well as that mysterious plus sign:

% ls -l
total 22800
-rw-r--r--    1 spenberthy  staff    56B Aug  5 17:17 README
drwxr-xr-x   10 spenberthy  staff   340B Jan 29 06:46 Reachability/
drwxr-xr-x   14 spenberthy  staff   476B Jan 29 06:46 Twitter-OAuth-iPhone/
drwxr-xr-x    8 spenberthy  staff   272B Jan 29 06:46 certs/

You’re done! In case you’re wondering, these files are for a new app I’m building with some friends and relatives at DX Agency. More on that later.

Leave a Reply