2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-15 17:47:21 +00:00
restic/cmd/khepri/cmd_backup.go
Alexander Neumann 2428843faa Refactor
2014-08-11 22:47:24 +02:00

40 lines
589 B
Go

package main
import (
"errors"
"fmt"
"log"
"github.com/fd0/khepri"
)
func commandBackup(repo *khepri.Repository, args []string) error {
if len(args) != 1 {
return errors.New("usage: backup dir")
}
target := args[0]
tree, err := khepri.NewTreeFromPath(repo, target)
if err != nil {
return err
}
id, err := tree.Save(repo)
if err != nil {
return err
}
sn := khepri.NewSnapshot(target)
sn.Content = id
snid, err := sn.Save(repo)
if err != nil {
log.Printf("error saving snapshopt: %v", err)
}
fmt.Printf("%q archived as %v\n", target, snid)
return nil
}