From 22f23ef31b71e4c8afd0362c94116e810c643844 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Thu, 1 Jan 2015 16:29:41 +0100 Subject: [PATCH] Support for pattern in restore command This just matches the passed pattern against the full source path with filepath.Match which, in contrast go filepath.Glob, doesn't match the directory separator with '*' and is not terribly useful that way. Someone should replace that by a more sophisticated matcher. --- cmd/restic/cmd_restore.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_restore.go b/cmd/restic/cmd_restore.go index b165f2805..693455648 100644 --- a/cmd/restic/cmd_restore.go +++ b/cmd/restic/cmd_restore.go @@ -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)