1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 16:26:11 +00:00
restic/cmd/khepri/cmd_backup.go

37 lines
667 B
Go
Raw Normal View History

2014-04-27 22:00:15 +00:00
package main
import (
"errors"
"fmt"
2014-09-23 20:39:12 +00:00
"os"
2014-04-27 22:00:15 +00:00
2014-07-28 18:20:32 +00:00
"github.com/fd0/khepri"
2014-09-23 20:39:12 +00:00
"github.com/fd0/khepri/backend"
2014-04-27 22:00:15 +00:00
)
2014-09-23 20:39:12 +00:00
func commandBackup(be backend.Server, key *khepri.Key, args []string) error {
2014-04-27 22:00:15 +00:00
if len(args) != 1 {
2014-09-23 20:39:12 +00:00
return errors.New("usage: backup [dir|file]")
2014-04-27 22:00:15 +00:00
}
target := args[0]
2014-09-23 20:39:12 +00:00
arch, err := khepri.NewArchiver(be, key)
2014-08-11 20:47:24 +00:00
if err != nil {
2014-09-23 20:39:12 +00:00
fmt.Fprintf(os.Stderr, "err: %v\n", err)
2014-08-11 20:47:24 +00:00
}
2014-09-23 20:39:12 +00:00
arch.Error = func(dir string, fi os.FileInfo, err error) error {
2014-10-04 17:20:15 +00:00
fmt.Fprintf(os.Stderr, "error for %s: %v\n%v\n", dir, err, fi)
2014-04-27 22:00:15 +00:00
return err
}
2014-09-23 20:39:12 +00:00
_, blob, err := arch.Import(target)
2014-08-04 20:46:14 +00:00
if err != nil {
2014-09-23 20:39:12 +00:00
return err
2014-08-04 20:46:14 +00:00
}
2014-09-23 20:39:12 +00:00
fmt.Printf("snapshot %s saved\n", blob.Storage)
2014-04-27 22:00:15 +00:00
return nil
}