Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude temporary Xcode files from Time Machine?

I write a lot of code using Xcode. I know Xcode creates temporary files when it builds. These seem to be quite large (GB's), and I would like to exclude them from Time Machine backups.

How can I exclude them ? Where are they located? Is the location always the same?

like image 362
Rahul Iyer Avatar asked Oct 27 '25 14:10

Rahul Iyer


1 Answers

For the most part, these items are already excluded from Time Machine backups, through the use of the HFS+/APFS com.apple.metadata:com_apple_backup_excludeItem extended attribute bit that is set for build-related directories in these folders.

Take, for instance, the following:

mdouma46@MacBookPro15 ~ % ls -l@e ~/Library/Developer/CoreSimulator        
total 0
drwxr-xr-x@  4 mdouma46  staff   128 Mar  6  2021 Caches
    com.apple.metadata:com_apple_backup_excludeItem   61 
drwxr-xr-x  65 mdouma46  staff  2080 Jan  2 10:38 Devices
drwxr-xr-x   3 mdouma46  staff    96 Nov 28  2020 Temp

This shows the CoreSimulator/Caches directory has the com.apple.metadata:com_apple_backup_excludeItem extended attribute set with the binary plist version of the following XML plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>com.apple.backupd</string>
</plist>

This effectively excludes this folder and contents from Time Machine backups. Likewise, the directories inside ~/Library/Developer/CoreSimulator/Devices all have the same com.apple.metadata:com_apple_backup_excludeItem extended attribute set. Most stuff in the DerivedData is also excluded (save Unsaved_Xcode_Documents).

Note that ~/Library/Developer/Xcode/UserData contains your CodeSnippets, Custom Key bindings, font and color themes, and other data that you'd likely want backed up.

Apple's pretty good about excluding that kind of stuff from backups automatically.

Also of note is that I believe the .nobackup suffix can be used on directories to prevent the contents from being backed up, and similarly, .noindex to prevent the contents from being indexed by Spotlight.

like image 187
NSGod Avatar answered Oct 29 '25 06:10

NSGod