Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluding updates from backups #118

Open
natewalck opened this issue Sep 19, 2014 · 12 comments · May be fixed by #984
Open

Excluding updates from backups #118

natewalck opened this issue Sep 19, 2014 · 12 comments · May be fixed by #984

Comments

@natewalck
Copy link
Contributor

From hjuutila...@mac.com on October 03, 2011 00:25:16

This is just a minor enhancement request...

The contents of /Library/Managed Installs/ should probably be excluded from time machine backups. Apple is already excluding /Library/Updates/ by default (in /System/Library/CoreServices/backupd.bundle/Contents/Resources/StdExclusions.plist) and I think it would be nice for munki to automatically mark files as excluded.

I'm not sure how to implement this in python but in cocoa the way to exclude a path is defined in BackupCore.h and found in CoreServices framework. For example:

NSURL *someURL = [NSURL fileURLWithPath:@"/path/to/file"];
Boolean exclude = TRUE; // exclude item from backups
Boolean excludeByPath = FALSE; // this item is excluded regardless of its location
CSBackupSetItemExcluded((CFURLRef)someURL, exclude, excludeByPath);

Is there something in /Library/Managed Installs/ that needs a backup or should we just exclude the whole directory?

BTW. CrashPlan respects this exclusion too.

Hannes

Original issue: http://code.google.com/p/munki/issues/detail?id=118

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on February 23, 2012 15:29:59

I don't know how to implement that in Python, either. If you can do this in C, can you check to see if it's as simple as a new extended attribute added to the item? If so, we can do that with xattr...

@natewalck
Copy link
Contributor Author

From hjuutila...@mac.com on March 01, 2012 05:05:24

Doing a quick test it seems that you can exclude with:
xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd /path/to/item

Verified with /usr/bin/tmutil

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on March 01, 2012 09:19:41

tmutil addexclusion /path/to/item writes a different value to the com.apple.metadata:com_apple_backup_excludeItem attribute; it looks like a binary-encoded plist. But it does look like xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd /path/to/item works as well.

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on March 01, 2012 10:22:46

The value of the attribute when generated by tmutil addexclusion is a binary version of this plist:

com.apple.backupd

-Greg

@natewalck
Copy link
Contributor Author

From hjuutila...@mac.com on March 01, 2012 11:46:44

Yes, you're correct. I'm not sure but I think tmutil is Lion only? I don't have any older systems available right now but I'll check the xattr functionality tomorrow with 10.5 and 10.6. systems too.

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on March 01, 2012 11:49:20

Yes, tmutil is new in Lion.

So to clarify, when you said "Doing a quick test it seems that you can exclude with:
xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd /path/to/item"

How did you come up with that?

-Greg

@natewalck
Copy link
Contributor Author

From hjuutila...@mac.com on March 01, 2012 12:26:53

By some extensive googling :) Took a while but stumbled on this: http://www.entropy.ch/blog/Mac+OS+X/2008/06/14/Exclude-Items-From-Time-Machine-Backup-With-Contextual-Menu.html

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on March 01, 2012 12:39:27

I just worry that although

sudo xattr -w com.apple.metadata:com_apple_backup_excludeItem com.apple.backupd /Library/Managed\ Installs

works now, since it doesn't write the same attribute value as

sudo tmutil addexclusion /Library/Managed\ Installs

that it might break in the future.

@natewalck
Copy link
Contributor Author

From hjuutila...@mac.com on March 01, 2012 22:31:56

I'm concerned about this too. Would it be the safest bet to do something like:

#!/usr/bin/env python

encoding: utf-8

import subprocess
import platform

currentRelease = platform.release()

def excludeFromBackups(aPath):
tmutil = ["/usr/bin/tmutil", "addexclusion", aPath]
retcode = subprocess.call(tmutil)
return retcode

def excludeFromBackupsWithXattr(aPath):
xattrProcess = ["/usr/bin/xattr",
"-w", "com.apple.metadata:com_apple_backup_excludeItem",
"com.apple.backupd",
aPath]
retcode = subprocess.call(xattrProcess)
return retcode

Mac OS 10.7.x

if currentRelease.startswith('11.'):
retcode = excludeFromBackups("/Library/Managed Installs")

Mac OS 10.6.x

elif currentRelease.startswith('10.'):
retcode = excludeFromBackupsWithXattr("/Library/Managed Installs")

Mac OS 10.5.x

elif currentRelease.startswith('9.'):
retcode = excludeFromBackupsWithXattr("/Library/Managed Installs")

if retcode == 0:
print "Succeeded"
else:
print "Failed"

@natewalck
Copy link
Contributor Author

From gregnea...@mac.com on March 02, 2012 06:55:37

Not bad, though for forward compatibility, maybe something more like:

TMUTIL = "/usr/bin/tmutil"
if os.path.exists(TMUTIL):
# use TMUTIL to set exclusion
else:
# use xattr to set exclusion

-Greg

@natewalck
Copy link
Contributor Author

From Evi.Vano...@gmail.com on August 21, 2013 15:47:48

The binary vs. non-binary setting is a non-issue. The plist interpreter reads both. If you use MCX you can override settings in plists that are typically in binary with non-binary XML, the plists work the same. You can also convert the binary XML to human-readable XML and vice versa.

Apple seems to be going towards the binary XML probably because it is smaller and faster to read/write within the OS but they're both valid XML and will thus be parsed validly.

However I do think that using tmutil would be the best option vs xattr just in case that later on Apple decides to change how to exclude items and where to store that metadata.

@Artoria2e5
Copy link

Sorry for the necro, but just a huge FYI: the plain string com.apple.backup is also interpreted by the plist parser because it is PERFECTLY VALID PLIST. Old style (OpenStep) plists allow strings to look like that.

Artoria2e5 added a commit to Artoria2e5/munki that referenced this issue Mar 6, 2020
This commit closes munki#118 by sticking the xattr on the directory and telling pkgbuild to keep it.
@Artoria2e5 Artoria2e5 linked a pull request Mar 6, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants