1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

Implemented --numeric-owner

This commit is contained in:
Jonas Borgström 2012-02-29 23:59:17 +01:00
parent 3a70789b35
commit 4ddbf0d02a
2 changed files with 23 additions and 7 deletions

View file

@ -30,7 +30,8 @@ class DoesNotExist(Exception):
class AlreadyExists(Exception): class AlreadyExists(Exception):
pass pass
def __init__(self, store, key, manifest, name, cache=None, create=False, checkpoint_interval=300): def __init__(self, store, key, manifest, name, cache=None, create=False,
checkpoint_interval=300, numeric_owner=False):
self.key = key self.key = key
self.store = store self.store = store
self.cache = cache self.cache = cache
@ -41,6 +42,7 @@ def __init__(self, store, key, manifest, name, cache=None, create=False, checkpo
self.stats = Statistics() self.stats = Statistics()
self.name = name self.name = name
self.checkpoint_interval = checkpoint_interval self.checkpoint_interval = checkpoint_interval
self.numeric_owner = numeric_owner
if create: if create:
if name in manifest.archives: if name in manifest.archives:
raise self.AlreadyExists raise self.AlreadyExists
@ -246,8 +248,12 @@ def restore_attrs(self, path, item, symlink=False):
os.lchmod(path, item['mode']) os.lchmod(path, item['mode'])
elif not symlink: elif not symlink:
os.chmod(path, item['mode']) os.chmod(path, item['mode'])
uid = user2uid(item['user']) or item['uid'] uid = gid = None
gid = group2gid(item['group']) or item['gid'] if not self.numeric_owner:
uid = user2uid(item['user'])
gid = group2gid(item['group'])
uid = uid or item['uid']
gid = gid or item['gid']
try: try:
os.lchown(path, uid, gid) os.lchown(path, uid, gid)
except OSError: except OSError:
@ -306,6 +312,8 @@ def stat_attrs(self, st, path):
'gid': st.st_gid, 'group': gid2group(st.st_gid), 'gid': st.st_gid, 'group': gid2group(st.st_gid),
'mtime': st.st_mtime, 'mtime': st.st_mtime,
} }
if self.numeric_owner:
item['user'] = item['group'] = None
try: try:
xa = xattr(path, XATTR_NOFOLLOW) xa = xattr(path, XATTR_NOFOLLOW)
xattrs = {} xattrs = {}

View file

@ -72,7 +72,8 @@ def do_create(self, args):
manifest = Manifest(store, key) manifest = Manifest(store, key)
cache = Cache(store, key, manifest) cache = Cache(store, key, manifest)
archive = Archive(store, key, manifest, args.archive.archive, cache=cache, archive = Archive(store, key, manifest, args.archive.archive, cache=cache,
create=True, checkpoint_interval=args.checkpoint_interval) create=True, checkpoint_interval=args.checkpoint_interval,
numeric_owner=args.numeric_owner)
# Add darc cache dir to inode_skip list # Add darc cache dir to inode_skip list
skip_inodes = set() skip_inodes = set()
try: try:
@ -170,7 +171,8 @@ def cb(_, __, item):
store = self.open_store(args.archive) store = self.open_store(args.archive)
key = Key(store) key = Key(store)
manifest = Manifest(store, key) manifest = Manifest(store, key)
archive = Archive(store, key, manifest, args.archive.archive) archive = Archive(store, key, manifest, args.archive.archive,
numeric_owner=args.numeric_owner)
dirs = [] dirs = []
archive.iter_items(extract_cb) archive.iter_items(extract_cb)
store.flush_rpc() store.flush_rpc()
@ -206,8 +208,8 @@ def callback(item):
extra = ' link to %s' % item['source'] extra = ' link to %s' % item['source']
else: else:
extra = '' extra = ''
print '%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item['user'], print '%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item['user'] or item['uid'],
item['group'], size, mtime, item['group'] or item['gid'], size, mtime,
item['path'], extra) item['path'], extra)
store = self.open_store(args.src) store = self.open_store(args.src)
@ -347,6 +349,9 @@ def run(self, args=None):
subparser.add_argument('--do-not-cross-mountpoints', dest='dontcross', subparser.add_argument('--do-not-cross-mountpoints', dest='dontcross',
action='store_true', default=False, action='store_true', default=False,
help='Do not cross mount points') help='Do not cross mount points')
subparser.add_argument('--numeric-owner', dest='numeric_owner',
action='store_true', default=False,
help='Only store numeric user and group identifiers')
subparser.add_argument('archive', metavar='ARCHIVE', subparser.add_argument('archive', metavar='ARCHIVE',
type=location_validator(archive=True), type=location_validator(archive=True),
help='Archive to create') help='Archive to create')
@ -361,6 +366,9 @@ def run(self, args=None):
subparser.add_argument('-e', '--exclude', dest='patterns', subparser.add_argument('-e', '--exclude', dest='patterns',
type=ExcludePattern, action='append', type=ExcludePattern, action='append',
help='Include condition') help='Include condition')
subparser.add_argument('--numeric-owner', dest='numeric_owner',
action='store_true', default=False,
help='Only obey numeric user and group identifiers')
subparser.add_argument('archive', metavar='ARCHIVE', subparser.add_argument('archive', metavar='ARCHIVE',
type=location_validator(archive=True), type=location_validator(archive=True),
help='Archive to create') help='Archive to create')