2014-04-27 22:00:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
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 commandBackup(repo *khepri.Repository, args []string) error {
|
2014-04-27 22:00:15 +00:00
|
|
|
if len(args) != 1 {
|
|
|
|
return errors.New("usage: backup dir")
|
|
|
|
}
|
|
|
|
|
|
|
|
target := args[0]
|
|
|
|
|
2014-08-11 20:47:24 +00:00
|
|
|
tree, err := khepri.NewTreeFromPath(repo, target)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := tree.Save(repo)
|
2014-04-27 22:00:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-08-04 20:46:14 +00:00
|
|
|
sn := khepri.NewSnapshot(target)
|
2014-08-11 20:47:24 +00:00
|
|
|
sn.Content = id
|
2014-08-04 20:46:14 +00:00
|
|
|
snid, err := sn.Save(repo)
|
2014-08-04 18:47:04 +00:00
|
|
|
|
2014-08-04 20:46:14 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("error saving snapshopt: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("%q archived as %v\n", target, snid)
|
2014-04-27 22:00:15 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|