Using the Terminal to restore from a Time Machine backup

I recently had to restore some Application Data from a Time Machine backup and since Finder in OS X 10.7 (Lion) now hides the Library folder in your home directory I thought it easiest to just cp the files from the mounted volume to the right place. It turned out that this it was not as straightforward as that because the restored files retained the read only permissions that prevent you from modifying a backup.

The ACL does not appear in the Finder, but can be seen using ls -le:

0: group:everyone deny write,delete,append,writeattr,writeextattr,chown

and also metadata:

com.apple.metadata:_kTimeMachineNewestSnapshot 50

The ACL can be removed using chmod -a #n filename where n is replaced by the number at the front of the ACL description (0 in this case). Applying it recursively is possible but potentially dangerous 1 unless you know this is the only ACL applied to the files in the directory. The metadata can be removed using xattr, like this:
xattr -d com.apple.metadata filename

  1. and consequently left as an exercise to the reader[]