restic/cmd/khepri/cmd_restore.go

36 lines
615 B
Go
Raw Normal View History

2014-04-28 00:00:15 +02:00
package main
import (
"errors"
2014-08-04 22:46:14 +02:00
"log"
2014-04-28 00:00:15 +02:00
2014-07-28 20:20:32 +02:00
"github.com/fd0/khepri"
2014-04-28 00:00:15 +02:00
)
2014-08-04 20:47:04 +02:00
func commandRestore(repo *khepri.Repository, args []string) error {
2014-04-28 00:00:15 +02:00
if len(args) != 2 {
return errors.New("usage: restore ID dir")
}
2014-07-28 20:20:32 +02:00
id, err := khepri.ParseID(args[0])
2014-04-28 00:00:15 +02:00
if err != nil {
2014-08-03 15:16:56 +02:00
errx(1, "invalid id %q: %v", args[0], err)
2014-04-28 00:00:15 +02:00
}
target := args[1]
2014-08-04 22:46:14 +02:00
sn, err := khepri.LoadSnapshot(repo, id)
if err != nil {
2014-09-21 15:58:52 +02:00
log.Fatalf("error loading snapshot %s: %v", id, err)
2014-08-04 22:46:14 +02:00
}
err = sn.RestoreAt(target)
2014-04-28 00:00:15 +02:00
if err != nil {
2014-09-21 15:58:52 +02:00
log.Fatalf("error restoring snapshot %s: %v", id, err)
2014-04-28 00:00:15 +02:00
}
2014-08-05 23:13:07 +02:00
log.Printf("%q restored to %q\n", id, target)
2014-04-28 00:00:15 +02:00
return nil
}