3

I'm writing some code that produces a kind of package file, however it includes a kind of working database that isn't strictly necessary (as it can be re-computed) but is best kept bundled with the package file.

Anyway, the problem is that the database can get quite large, and often changes are fairly small, this means that these databases are always being backed up by Time Machine, which is very wasteful as they don't really add anything important to back-ups.

I can't really ask the end-users to mark these databases manually for every package in their Time Machine preferences, especially if they move the package file around and forget. But I also don't want these databases to be waisting a bunch of space in their Time Machine backups, as it could cause premature pruning of old backups with no useful benefits.

I've already considered moving the databases into the user's ~/Library/Caches folder but this is a lot more complicated to manage. The database is also useful within the package as it eliminates a somewhat lengthy pre-compute step.

So; is there any other means by which I can tell Time Machine to ignore a file or folder? Ideally something I can do via script, but if it requires a small program it's not a huge issue.

7
  • 2
    Do you mean '~/Library/Caches'? Commented Nov 26, 2014 at 12:17
  • Does this file change as the app is run - if so then it should not be in the package and must be elsewhere
    – mmmmmm
    Commented Nov 26, 2014 at 12:20
  • 1
    there's sudo tmutil addexclusion ~/myFolder though idk if you can do any variation on that from shellscript etc.
    – Tetsujin
    Commented Nov 26, 2014 at 12:24
  • 1
    As written right now the question revolves primarily about design and coding issues, both of which are off-topic on AD (which focuses on end user problems). OTOH having a scripting solution to exclude files from TM might be of general interest, so if you can rewrite the question to focus on the scripting approach this would be great.
    – nohillside
    Commented Nov 26, 2014 at 12:50
  • 1
    Use sticky exclusion via tmutil addexclusion <file> (without -p) seem not work if files are inside a package/bundle. You can check with exclusion state with tmutil isexcluded <file> (should return "[Excluded] <file>")
    – mems
    Commented May 27, 2016 at 12:00

1 Answer 1

5

There is a C function 'CSBackupSetItemExcluded' you can use to tell Time Machine to exclude a file.

You can find it documented here...

https://developer.apple.com/library/mac/documentation/MacOSX/Reference/Backup/#//apple_ref/c/func/CSBackupSetItemExcluded

1
  • Thanks a lot Alistair. Is anything else of the Time Machine Backup system exposed to the developer ? Is it possible to programmatically retrieve the contents of a folder at a given date ? Thanks Commented Jan 30, 2019 at 18:25

Not the answer you're looking for? Browse other questions tagged .