mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 01:06:50 +00:00
Implemented --numeric-owner
This commit is contained in:
parent
3a70789b35
commit
4ddbf0d02a
2 changed files with 23 additions and 7 deletions
|
@ -30,7 +30,8 @@ class DoesNotExist(Exception):
|
|||
class AlreadyExists(Exception):
|
||||
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.store = store
|
||||
self.cache = cache
|
||||
|
@ -41,6 +42,7 @@ def __init__(self, store, key, manifest, name, cache=None, create=False, checkpo
|
|||
self.stats = Statistics()
|
||||
self.name = name
|
||||
self.checkpoint_interval = checkpoint_interval
|
||||
self.numeric_owner = numeric_owner
|
||||
if create:
|
||||
if name in manifest.archives:
|
||||
raise self.AlreadyExists
|
||||
|
@ -246,8 +248,12 @@ def restore_attrs(self, path, item, symlink=False):
|
|||
os.lchmod(path, item['mode'])
|
||||
elif not symlink:
|
||||
os.chmod(path, item['mode'])
|
||||
uid = user2uid(item['user']) or item['uid']
|
||||
gid = group2gid(item['group']) or item['gid']
|
||||
uid = gid = None
|
||||
if not self.numeric_owner:
|
||||
uid = user2uid(item['user'])
|
||||
gid = group2gid(item['group'])
|
||||
uid = uid or item['uid']
|
||||
gid = gid or item['gid']
|
||||
try:
|
||||
os.lchown(path, uid, gid)
|
||||
except OSError:
|
||||
|
@ -306,6 +312,8 @@ def stat_attrs(self, st, path):
|
|||
'gid': st.st_gid, 'group': gid2group(st.st_gid),
|
||||
'mtime': st.st_mtime,
|
||||
}
|
||||
if self.numeric_owner:
|
||||
item['user'] = item['group'] = None
|
||||
try:
|
||||
xa = xattr(path, XATTR_NOFOLLOW)
|
||||
xattrs = {}
|
||||
|
|
|
@ -72,7 +72,8 @@ def do_create(self, args):
|
|||
manifest = Manifest(store, key)
|
||||
cache = Cache(store, key, manifest)
|
||||
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
|
||||
skip_inodes = set()
|
||||
try:
|
||||
|
@ -170,7 +171,8 @@ def cb(_, __, item):
|
|||
store = self.open_store(args.archive)
|
||||
key = Key(store)
|
||||
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 = []
|
||||
archive.iter_items(extract_cb)
|
||||
store.flush_rpc()
|
||||
|
@ -206,8 +208,8 @@ def callback(item):
|
|||
extra = ' link to %s' % item['source']
|
||||
else:
|
||||
extra = ''
|
||||
print '%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item['user'],
|
||||
item['group'], size, mtime,
|
||||
print '%s%s %-6s %-6s %8d %s %s%s' % (type, mode, item['user'] or item['uid'],
|
||||
item['group'] or item['gid'], size, mtime,
|
||||
item['path'], extra)
|
||||
|
||||
store = self.open_store(args.src)
|
||||
|
@ -347,6 +349,9 @@ def run(self, args=None):
|
|||
subparser.add_argument('--do-not-cross-mountpoints', dest='dontcross',
|
||||
action='store_true', default=False,
|
||||
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',
|
||||
type=location_validator(archive=True),
|
||||
help='Archive to create')
|
||||
|
@ -361,6 +366,9 @@ def run(self, args=None):
|
|||
subparser.add_argument('-e', '--exclude', dest='patterns',
|
||||
type=ExcludePattern, action='append',
|
||||
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',
|
||||
type=location_validator(archive=True),
|
||||
help='Archive to create')
|
||||
|
|
Loading…
Reference in a new issue