Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jw2002

macrumors 6502
Original poster
Feb 23, 2008
392
59
I have seen in several places online that you can set the extended attribute of file or directory to keep it from being backed up. This would be a useful feature for me in preventing various .targets directories in my many Subversion snapshots from being backed up. These .targets directories just hold .o and .a files and are not worth backing up because they are easily regenerated during compile time and do nothing but waste space in a back up.

So anyways as an experiment I set a .targets directory to not back up according to what is claimed online:

Code:
% cd /data
% ls -ld .targets
drwxr-xr-x@ 4 jw2002  wheel  136 Sep 29 19:50 .targets
% /usr/bin/xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd .targets
% /usr/bin/xattr -l .targets
com.apple.metadata:com_apple_backup_excludeItem: com.apple.backupd

Then I went into Time Machine, pointed the window to the right directory, and deleted all backups of .targets. (Note that I set my Finder options to show hidden files). I then performed a Time Machine backup, and the .targets directory still got backed up!

Code:
% cd "/Volumes/Backup of blort/Backups.backupd/blort/Latest/Macintosh HD/data"
% ls -ld .targets
drwxr-xr-x@ 4 jw2002  wheel  136 Sep 29 19:50 .targets
% xattr -l .targets
com.apple.metadata:_kTimeMachineNewestSnapshot:
0000   62 70 6C 69 73 74 30 30 33 42 2D 63 C3 7F 00 00    bplist003B-c....
0010   00 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00    ................
0020   00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0030   00 11                                              ..

com.apple.metadata:_kTimeMachineOldestSnapshot:
0000   62 70 6C 69 73 74 30 30 33 41 AE B6 F2 9A 00 00    bplist003A......
0010   00 08 00 00 00 00 00 00 01 01 00 00 00 00 00 00    ................
0020   00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
0030   00 11                                              ..

com.apple.metadata:com_apple_backup_excludeItem: com.apple.backupd

So not only did Time Machine ignore the metadata that I added, but it added its own with respect to backup times.

Can anyone suggest what I might be doing wrong here? Do I have the metadata keywords spelled wrong? Or are the metadata not consulted for hidden files?

I would really like to exclude these directories from backups because they amount to several gigs of constantly changing files that are simply not worth backing up. I was hoping to go the metadata route rather than manually adding these via the Time Machine preferences. I guess I could have a script add them to the com.apple.TimeMachine.plist...

Thanks.
 
I used:

Code:
xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd somefilename

My testing indicates that this prevents all files from being backed except for files that started with a ".".

S-
 
Thanks for the help. My guess is that this has to do with spotlight not cataloging files beginning with a "." dot. The backup process probably performs the equivalent of

Code:
% mdfind "com_apple_backup_excludeItem == 'com.apple.backupd'"

to determine the additional excluded files/directories. And mdfind of course can never return a hiddne file as a result. It looks like my only recourse is to add the desired .targets directories to the .plist file.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.