Excluding folders and files from Time Machine, Spotlight, and iCloud Drive
Backups, indexing for search, and cloud storage are each very useful when and where you want them. But there are occasions when you want to exclude folders and files from their reach. This article is a short reference to how you can exclude items from being backed up, indexed and searched, and stored in iCloud Drive.
Time Machine backups
Time Machine has several mechanisms for excluding items from its backups. The first of those used to be its Standard Exclusions list, at /System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist, but that has long since disappeared from there. Currently the best way to inspect that list is by viewing the hidden file .exclusions.plist at the top level of any backup.
This lists several categories of exclusions, of which the first are apiExclusionPaths, added by individual third-party apps. The equivalent of what used to appear in StdExclusions.plist is now given under the standardExclusionPaths key, containing:
.DocumentRevisions-V100 – the version database on each volume, added in Big Sur,
.Spotlight-V100 – Spotlight metadata,
.Trashes – contents of Trash folders,
.fseventsd – the File System Events database,
/Library/Logs – traditional text log files,
/Users/Guest – guest user files,
/private/var (partial) – various transient files,
among many other ephemeral items.
Of those, only one results in any significant loss of data, the version database. Although this was dutifully copied by Time Machine into backups for several years, the current structure of that database appears to make it impossible to restore successfully, even when restoring a complete volume. By the middle of the Catalina cycle, it had become a frequent cause of Time Machine choking, so was added to the standardExclusionPaths for Big Sur. As far as I’m aware this was never fixed in Catalina.
Following those are stickyExclusionPaths, excluding various Photos Library contents. The key systemFilesExcluded is set to true to ensure that the whole System volume is always excluded, following which are any userExclusionPaths you have set using tmutil or in Time Machine settings, using the Options… button.
By default, volumes on external storage are automatically added to this exclusion list; if you want an external volume to be backed up by Time Machine then you will need to remove it from the exclusion list manually.
In addition to the rules given in the Standard Exclusion list, any file or folder can have an extended attribute of type com.apple.metadata:com_apple_backup_excludeItem attached to it as a ‘sticky’ exclusion, which should add it to the stickyExclusionPaths list and prevent it from being backed up by Time Machine. If you then remove that extended attribute, it should be backed up normally again.
Mike Bombich gives a thorough and detailed account of what CCC doesn’t copy on this page. Other backup utilities should also provide full lists on their support site.
Note that no folders or files can be excluded from APFS snapshots, whether made by Time Machine, CCC or any other app, as snapshots always capture the entire volume.
Spotlight search
There have been three general methods of excluding folders from Spotlight’s indexing and search, although only two of them still work reliably:
appending the extension .noindex to the folder name (this previously worked using .no_index instead);
making the folder invisible to the Finder by prefixing a dot ‘.’ to its name;
putting an empty file named .metadata_never_index inside the folder; that no longer works in recent macOS.
System Settings offers Spotlight Privacy settings in two sections. Search results won’t normally prevent indexing of those items, but does block them from appearing in search results. Spotlight’s indexing exclusion list is accessed from the Spotlight Privacy… button, where you can add items that you don’t want indexed.
iCloud Drive storage
This works primarily by inclusion, in that you copy or move items to the iCloud Drive folder when you want them to be copied up to iCloud Drive. There are occasions, though, when you want to exclude specific folders and files that need to be in a folder in iCloud Drive, but you don’t want those items to be stored in the cloud. iCloud won’t sync items with the extensions .nosync or .tmp, so putting files inside folders whose name ends in either of those extensions will ensure that they’re not stored in iCloud Drive.
Other items intended for local housekeeping and similar purposes that are excluded from syncing include:
.DS_Store files
files whose name starts (A Document Being Saved
.ubd files
items with names containing .weakpkg
desktop.ini files
items with names starting with ~$
items named $RECYCLE.BIN, which are trash folders
items named iconr, which are custom folder icons.
Files and folders with purposes that make iCloud syncing inappropriate include those:
named iPhoto Library, and presumably now Photos Library too
named Dropbox, .dropbox, or .dropbox.attr
with the extension .photoslibrary, .photolibrary, .aplibrary, .migratedaplibrary, .migratedphotolibrary, or .migratedaperturelibrary
named Microsoft User Data
named ~ with an extension of 3 or more characters.
The only setting in System Settings gives control over Desktop & Documents folders, and those of individual apps; there’s no exclusion list available.
Simple reference to folder controls
Time Machine: add to settings with the Options… button, or using tmutil;
Spotlight indexing: add to settings with the Spotlight Privacy… button, or append the extension .noindex to the folder name;
iCloud Drive: append the extension .nosync or .tmp to the folder name.