2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 13:17:42 +00:00

Merge pull request #878 from middelink/fix-825

Fix restoring files ownership as non-root user
This commit is contained in:
Alexander Neumann 2017-03-12 18:20:28 +01:00
commit bf30b2831b
2 changed files with 24 additions and 16 deletions

View File

@ -103,8 +103,10 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error {
Exitf(2, "creating restorer failed: %v\n", err)
}
totalErrors := 0
res.Error = func(dir string, node *restic.Node, err error) error {
Warnf("error for %s: %+v\n", dir, err)
Warnf("ignoring error for %s: %s\n", dir, err)
totalErrors++
return nil
}
@ -134,5 +136,9 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error {
Verbosef("restoring %s to %s\n", res.Snapshot(), opts.Target)
return res.RestoreTo(opts.Target)
err = res.RestoreTo(opts.Target)
if totalErrors > 0 {
Printf("There were %d errors\n", totalErrors)
}
return err
}

View File

@ -158,35 +158,37 @@ func (node *Node) CreateAt(path string, repo Repository, idx *HardlinkIndex) err
}
func (node Node) restoreMetadata(path string) error {
var err error
var firsterr error
err = lchown(path, int(node.UID), int(node.GID))
if err != nil {
return errors.Wrap(err, "Lchown")
if err := lchown(path, int(node.UID), int(node.GID)); err != nil {
firsterr = errors.Wrap(err, "Lchown")
}
if node.Type != "symlink" {
err = fs.Chmod(path, node.Mode)
if err != nil {
return errors.Wrap(err, "Chmod")
if err := fs.Chmod(path, node.Mode); err != nil {
if firsterr != nil {
firsterr = errors.Wrap(err, "Chmod")
}
}
}
if node.Type != "dir" {
err = node.RestoreTimestamps(path)
if err != nil {
if err := node.RestoreTimestamps(path); err != nil {
debug.Log("error restoring timestamps for dir %v: %v", path, err)
return err
if firsterr != nil {
firsterr = err
}
}
}
err = node.restoreExtendedAttributes(path)
if err != nil {
if err := node.restoreExtendedAttributes(path); err != nil {
debug.Log("error restoring extended attributes for %v: %v", path, err)
return err
if firsterr != nil {
firsterr = err
}
}
return nil
return firsterr
}
func (node Node) restoreExtendedAttributes(path string) error {