Merge branch 'restore-pattern', closes #69

This commit is contained in:
Alexander Neumann
2015-01-02 23:04:29 +01:00
2 changed files with 46 additions and 22 deletions
+15 -2
View File
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"path/filepath"
"github.com/restic/restic"
"github.com/restic/restic/backend"
@@ -21,11 +22,11 @@ func init() {
}
func (cmd CmdRestore) Usage() string {
return "snapshot-ID TARGETDIR"
return "snapshot-ID TARGETDIR [PATTERN]"
}
func (cmd CmdRestore) Execute(args []string) error {
if len(args) != 2 {
if len(args) < 2 || len(args) > 3 {
return fmt.Errorf("wrong number of arguments, Usage: %s", cmd.Usage())
}
@@ -64,6 +65,18 @@ func (cmd CmdRestore) Execute(args []string) error {
return err
}
// TODO: a filter against the full path sucks as filepath.Match doesn't match
// directory separators on '*'. still, it's better than nothing.
if len(args) > 2 {
res.Filter = func(item string, dstpath string, node *restic.Node) bool {
matched, err := filepath.Match(item, args[2])
if err != nil {
panic(err)
}
return matched
}
}
fmt.Printf("restoring %s to %s\n", res.Snapshot(), target)
err = res.RestoreTo(target)