I want to delete some files/directories from my Time Machine Partition using rm, but am unable to do so. I'm pretty sure the problem is related to some sort of access control extended attributes on files in the backup, but do not know how to override/disable them in order to get rm to work. An example of the error I'm getting is:
% sudo rm -rf Backups.backupdb/MacBook/Latest/MacBook/somedir
rm: Backups.backupdb/MacBook/Latest/MacBook/somedir: Directory not empty
rm: Backups.backupdb/MacBook/Latest/MacBook/somedir/somefile: Operation not permitted
There are a number of reasons I do not want to use either the Time Machine GUI or Finder for this. If possible, I'd like to be able to maintain the extended protection for all other files (I'd like not to disable them globally, unless I can re-enable once I've done my work).
Answer
To work around "operation not permitted" errors, use the Time Machine Safety Net "bypass" program:
sudo /System/Library/Extensions/TMSafetyNet.kext/Contents/MacOS/bypass rm -rfv /Volumes/[disk]/Backups.backupdb/[path]
In 10.8 Mountain Lion, bypass moved into 'Helpers':
/System/Library/Extensions/TMSafetyNet.kext/Helpers/bypass
In 10.10 Yosemite, bypass moved here:
/System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass
Beware when using this to delete specific snapshots: as Time Machine uses hard links, using rm -r
on folders might also affect older and newer snapshots of the same machine. (See other answers referring to tmutil delete
to safely delete a specific snapshot.) Using rm
to delete all snapshots for a single machine is okay though. And so is using rm
to delete a specific file, which will only remove that hard-linked file from the snapshot(s) you specify, assuming the file is not in a hard-linked directory as then you'd actually remove the file from all those hard-linked directories.
No comments:
Post a Comment