Is it possible to use `tmutil delete` or another command to delete one file from all backup intervals?

I'm having problems clearing our a backup drive. I want to get rid of a couple large files so I can preserve the other incremental backups.

I can't use the tmutil delete command on entire backups since I'd lose all files from that interval and not just the offending file I want to purge. Additionally, having a script would mean I could recover space from a whole lab's worth of computers by scripting this from the command line. I also expect that script would let me discover which file in the package the GUI is refusing to prune since I can debug a script easier than I can Finder and the Time Machine interface.

In case this is a simple permissions issue - the library package file/folder:

Mac:~ bmike$ ls -laeO  /Volumes/Backups/Backups.backupdb/Mac/2015-04-09-072338/Macintosh\ HD/Users/bmike/Pictures/Photos\ Library.photoslibrary 
total 0
drwxr-xr-x@ 10 bmike staff  - 340 Apr  8 20:05 .
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown
drwx------@ 28 bmike staff  - 952 Apr  9 09:38 ..
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown
 1: group:everyone deny delete
drwxr-xr-x+  2 bmike staff  -  68 Apr  8 09:07 Attachments
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown
drwxr-xr-x+  2 bmike staff  -  68 Apr  8 09:07 Masks
 0: group:everyone deny add_file,delete,add_subdirectory,delete_child,writeattr,writeextattr,chown

When I use the Time Machine interface, it errors out and I don't know which file or instance has errors:

unhelpful finder error

I'm looking for a way to delete these protected files from all backup intervals in a similar manner to the Finder Gear icon action of Delete All Backups of "Photos Library"

Delete All Backups of "Photos Library"

Is this selective pruning of a file/folder possible across all time intervals with Apple's built in tools, a custom script and/or other tool?


Solution 1:

Yes, you can use the "TM Safety Net" helper bypass to bypass the ACL restrictions allow you to use rm the way you normally would. Except, of course, Time Machine uses "hard links" so rm does not entirely work the way you normally expect it to work.

The bypass program is not meant for people to use and can be hard to find, and it has moved around in various versions of OS X. I find it using this command:

locate TMSafetyNet.kext | grep bypass

Then you use it to authorize rm

sudo /System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass rm -rf /Volumes/Backups/Backups.backupdb/Mac/2015-04-09-072338/Macintosh\ HD/Users/bmike/Pictures/Photos\ Library.photoslibrary

Keep in mind, as mentioned, that because of the way Time Machine uses hard links of directories, this rm command can remove the file from other backups. I would not recommend using it unless you are trying to remove the file from all backups.

In fact, in general, I would not recommend using hidden commands like this. Use the GUI as Apple intended. Of course in this specific case, where you have a lot of computers to execute the same command on and you fully understand the impact of hard links, then go ahead.

If you are going to script this, your script should make sure that Time Machine is (a) disabled and (b) not currently running a backup (because unfortunately (a) does not guarantee (b)) before running commands using bypass. You probably should do that when running commands manually, too.

Solution 2:

Here is a way to exclude folders from timemachine.

  • Hold the command key and type the space bar to bring up Spotlight.

  • Type Time Machine and open the system preference (not the application).

  • Click the Options... button in the lower right corner of the Time Machine system preference panel.

  • Click the plus button then navigate to the folder you want to exclude.

  • Click on the Exclude button.

  • Click on Save.

https://www.imore.com/how-exclude-files-time-machine-backups