OSX Command line exclusion of folders from Indexing or Backup

Build folders contains tons of files (built PCL, for example, is 7k files) and it is not typically needed to make Spotlight index them or Time Machine to backup them.

For both services it is possible to control exclusion from the User Interface but sometime we want to control them from the command line.

Indexing

The fastest way to prevent indexing  of a directory tree is to add a file called ".metadata_never_index", for example via touch.

Time Machine

OSX provides a sticky way to set exclusion for the folder meaning that it works even if the folder is moved around. The operation is performed with:

tmutil addexclusion PATH

The sticky capability is obtained by writing a special attribute in the folder as it is visible with the xattr command. The attribute is "com.apple.metadata:com_apple_backup_excludeItem" with a special value.

Listing Exclusions

Using mdfind it is possible to find all excluded paths:

mdfind "com_apple_backup_excludeItem = 'com.apple.backupd'"
In addition there is a list of standard exclusions in the file: /System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist

The listing of TM exclusions can be found using the following:

sudo defaults read /.Spotlight-V100/VolumeConfiguration.plist Exclusions

Finally the list of exclusions is stored in the backup in the file .exclusions.plist

Conclusion

The following simple script does the job:

#!/bin/bash
touch $1/.metadata_never_index
tmutil addexclusion $1


Update

Found some additional material here about obtaining the exclusion listing.
Also here.




Comments

Popular Posts