Run `tmutil isexcluded` recursively

786 Views Asked by At

I'd like to use tmutil recursively to list all of the files currently excluded from Time Machine backups. I know that I can determine this for a single file with

tmutil isexcluded /path/to/file

but I can't seem to get this to run recursively. I have tried grepping for the excluded files and outputting to a file like this:

tmutil isexcluded * | grep -i excluded >> ~/Desktop/TM-excluded.txt 

but this only outputs data for the top level of the current directory. Can I use find or a similar command to feed every file/directory on the machine to tmutil isexcluded and pull out a list of the excluded files? What is the best way to structure the command?

I'm aware that most of the exclusions can be found in

/System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist

and that some app-specific exclusions are searchable via

sudo mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'" 

but I am looking for a way to compare the actual flags on the files to these lists.

2

There are 2 best solutions below

0
On BEST ANSWER

This should do it:

find /starting/place -exec tmutil isexcluded {} + | grep -F "[Excluded]" | sed -E 's/^\[Excluded\][[:space:]]*//'

This takes advantage of the fact that tmutil allows you to pass multiple filenames, so I use + at the end of the find instead of ; then I don't have to execute a new process for every single file on your machine - which could be slow. The grep looks for the fixed (F) string [Excluded] and the sed removes the [Excluded] and following 4 spaces.

0
On

You can get all the files in any subdirectory of /path/to/master/dir with

find /path/to/master/dir -type f

Now you cannot pipe the output to tmutil, so what you can do is

find /path/to/master/dir -type f -exec tmutil isexcluded {} \;

What this does is:

  • We know what find /path/to/master/dir -type f does.
  • -exec will execute anything after it.
  • {} will use each file from find's output separately with tmutil isexcluded.
  • \ ends the -exec so the -exec knows what command should execute (in case you would want to do something else after it).