Monday, October 10, 2011

Excluding files or directories from Time Machine

There are a number of places that talk around excluding files or directories from Time Machine backups, but I thought I'd share the most direct way.  The global exclude list can be opened using
$ open /Library/Preferences/com.apple.TimeMachine.plist
but if you want finer-grained control, you can use extended attributes.  The following commands exclude several directories where I have experimental VirtualBox VM's that I don't need backed up:
$ xattr -w com_apple_backup_excludeItem com.apple.backupd VirtualBox\ VMs/Windows\ 7/
$ xattr -w com_apple_backup_excludeItem com.apple.backupd VirtualBox\ VMs/OpenBSD/
To remove an extended attribute, use xattr thus:
$ xattr -d com_apple_backup_excludeItem VirtualBox\ VMs/
To see which extended attributes are set on a file or directory, use the '@' argument to ls:
ls -l@ VirtualBox\ VMs/
total 0
drwxr-xr-x@ 6 beaty-admin  staff  204 Jun  1 13:53 OpenBSD/
    com_apple_backup_excludeItem     17 
drwxr-xr-x  6 beaty-admin  staff  204 Oct  5 15:46 Ubuntu/
drwxr-xr-x@ 7 beaty-admin  staff  238 Oct  6 21:22 Windows 7/
    com_apple_backup_excludeItem     17 
drwxr-xr-x@ 6 beaty-admin  staff  204 Sep 29 21:38 XP/
    com_apple_backup_excludeItem     17 
And: Let Time Machine backup File Vault while logged in