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