diff --git a/src/borg/archive.py b/src/borg/archive.py index 93e90b194..6d8e4e04d 100644 --- a/src/borg/archive.py +++ b/src/borg/archive.py @@ -928,9 +928,12 @@ def restore_attrs(self, path, item, symlink=False, fd=None): Does not access the repository. """ backup_io.op = "attrs" - uid, gid = get_item_uid_gid(item, numeric=self.numeric_ids) - # This code is a bit of a mess due to os specific differences + # This code is a bit of a mess due to OS specific differences. if not is_win32: + # by using uid_default = -1 and gid_default = -1, they will not be restored if + # the archived item has no information about them. + uid, gid = get_item_uid_gid(item, numeric=self.numeric_ids, uid_default=-1, gid_default=-1) + # if uid and/or gid is -1, chown will keep it as is and not change it. try: if fd: os.fchown(fd, uid, gid)