From 500f4f9997f74ae15e99e073bb1baceb7fda1a94 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 4 Aug 2014 22:55:54 +0200 Subject: [PATCH] Add command 'snapshots' --- cmd/khepri/cmd_snapshots.go | 41 +++++++++++++++++++++++++++++++++++++ cmd/khepri/main.go | 1 + 2 files changed, 42 insertions(+) create mode 100644 cmd/khepri/cmd_snapshots.go diff --git a/cmd/khepri/cmd_snapshots.go b/cmd/khepri/cmd_snapshots.go new file mode 100644 index 000000000..cf9523e6b --- /dev/null +++ b/cmd/khepri/cmd_snapshots.go @@ -0,0 +1,41 @@ +package main + +import ( + "errors" + "fmt" + "log" + + "github.com/fd0/khepri" +) + +const TimeFormat = "02.01.2006 15:04:05 -0700" + +func commandSnapshots(repo *khepri.Repository, args []string) error { + if len(args) != 0 { + return errors.New("usage: snapshots") + } + + snapshot_ids, err := repo.List(khepri.TYPE_REF) + if err != nil { + log.Fatalf("error loading list of snapshot ids: %v", err) + } + + fmt.Printf("found snapshots:\n") + for _, id := range snapshot_ids { + snapshot, err := khepri.LoadSnapshot(repo, id) + + if err != nil { + log.Printf("error loading snapshot %s: %v", id, err) + continue + } + + fmt.Printf("%s %s@%s %s %s\n", + snapshot.Time.Format(TimeFormat), + snapshot.Username, + snapshot.Hostname, + snapshot.Dir, + id) + } + + return nil +} diff --git a/cmd/khepri/main.go b/cmd/khepri/main.go index bffcc2f8b..7aeac74f4 100644 --- a/cmd/khepri/main.go +++ b/cmd/khepri/main.go @@ -31,6 +31,7 @@ func init() { commands["backup"] = commandBackup commands["restore"] = commandRestore commands["list"] = commandList + commands["snapshots"] = commandSnapshots } func main() {