2

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?

Rahul Iyer
  • 19,924
  • 21
  • 96
  • 190

2 Answers2

2
  1. Launch System Preferences
  2. Select Time Machine
  3. Click Options...
  4. Add ~/Library/Developer to exclusion list
  5. Click Save

demo

Asperi
  • 228,894
  • 20
  • 464
  • 690
  • But won't that exclude other useful stuff like simulators etc ? I just want to exclude just the data generated when I build a project in Xcode..... – Rahul Iyer Jan 03 '22 at 09:11
  • 1
    It is my settings just for demo, but U can select any separated subfolders from that location, like *DerivedData*, etc. – Asperi Jan 03 '22 at 09:15
  • 1
    You can add just DerivedData: `Library/Developer/Xcode/DerivedData`, but I wouldn't say that simulators are useful to backup. – EmilioPelaez Jan 03 '22 at 09:16
  • I would like to backup anything which otherwise Xcode would have to download from the internet. Things which can be generated by just doing a build, I don't need to backup. – Rahul Iyer Jan 03 '22 at 09:18
  • 1
    Note that most of those items are already excluded from Time Machine backups; see my answer for more details. – NSGod Jan 03 '22 at 21:23
2

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.

NSGod
  • 22,699
  • 3
  • 58
  • 66