mirror of
https://github.com/octoleo/restic.git
synced 2024-11-25 22:27:35 +00:00
Fixing restore with excluded
An exclude filter is basically a 'wildcard but foo', so even if a childMayMatch, other children of a dir may not, therefore childMayMatch does not matter, but we should not go down unless the dir is selected for restore.
This commit is contained in:
parent
4a36993c19
commit
f880ff21aa
@ -113,22 +113,32 @@ func runRestore(opts RestoreOptions, gopts GlobalOptions, args []string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
selectExcludeFilter := func(item string, dstpath string, node *restic.Node) (bool, bool) {
|
selectExcludeFilter := func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
||||||
matched, childMayMatch, err := filter.List(opts.Exclude, item)
|
matched, _, err := filter.List(opts.Exclude, item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Warnf("error for exclude pattern: %v", err)
|
Warnf("error for exclude pattern: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return !matched, childMayMatch
|
// An exclude filter is basically a 'wildcard but foo',
|
||||||
|
// so even if a childMayMatch, other children of a dir may not,
|
||||||
|
// therefore childMayMatch does not matter, but we should not go down
|
||||||
|
// unless the dir is selected for restore
|
||||||
|
selectedForRestore = !matched
|
||||||
|
childMayBeSelected = selectedForRestore && node.Type == "dir"
|
||||||
|
|
||||||
|
return selectedForRestore, childMayBeSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
selectIncludeFilter := func(item string, dstpath string, node *restic.Node) (bool, bool) {
|
selectIncludeFilter := func(item string, dstpath string, node *restic.Node) (selectedForRestore bool, childMayBeSelected bool) {
|
||||||
matched, childMayMatch, err := filter.List(opts.Include, item)
|
matched, childMayMatch, err := filter.List(opts.Include, item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Warnf("error for include pattern: %v", err)
|
Warnf("error for include pattern: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return matched, childMayMatch
|
selectedForRestore = matched
|
||||||
|
childMayBeSelected = childMayMatch && node.Type == "dir"
|
||||||
|
|
||||||
|
return selectedForRestore, childMayBeSelected
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(opts.Exclude) > 0 {
|
if len(opts.Exclude) > 0 {
|
||||||
|
@ -17,7 +17,7 @@ type Restorer struct {
|
|||||||
sn *Snapshot
|
sn *Snapshot
|
||||||
|
|
||||||
Error func(dir string, node *Node, err error) error
|
Error func(dir string, node *Node, err error) error
|
||||||
SelectFilter func(item string, dstpath string, node *Node) (bool, bool)
|
SelectFilter func(item string, dstpath string, node *Node) (selectedForRestore bool, childMayBeSelected bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err }
|
var restorerAbortOnAllErrors = func(str string, node *Node, err error) error { return err }
|
||||||
@ -46,9 +46,9 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, node := range tree.Nodes {
|
for _, node := range tree.Nodes {
|
||||||
selectedForRestore, childMayMatch := res.SelectFilter(filepath.Join(dir, node.Name),
|
selectedForRestore, childMayBeSelected := res.SelectFilter(filepath.Join(dir, node.Name),
|
||||||
filepath.Join(dst, dir, node.Name), node)
|
filepath.Join(dst, dir, node.Name), node)
|
||||||
debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayMatch)
|
debug.Log("SelectFilter returned %v %v", selectedForRestore, childMayBeSelected)
|
||||||
|
|
||||||
if selectedForRestore {
|
if selectedForRestore {
|
||||||
err := res.restoreNodeTo(ctx, node, dir, dst, idx)
|
err := res.restoreNodeTo(ctx, node, dir, dst, idx)
|
||||||
@ -57,7 +57,7 @@ func (res *Restorer) restoreTo(ctx context.Context, dst string, dir string, tree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.Type == "dir" && childMayMatch {
|
if node.Type == "dir" && childMayBeSelected {
|
||||||
if node.Subtree == nil {
|
if node.Subtree == nil {
|
||||||
return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
|
return errors.Errorf("Dir without subtree in tree %v", treeID.Str())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user