mirror of
https://github.com/octoleo/restic.git
synced 2024-11-24 21:57:41 +00:00
Add command 'snapshots'
This commit is contained in:
parent
e8b83e460f
commit
500f4f9997
41
cmd/khepri/cmd_snapshots.go
Normal file
41
cmd/khepri/cmd_snapshots.go
Normal file
@ -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
|
||||
}
|
@ -31,6 +31,7 @@ func init() {
|
||||
commands["backup"] = commandBackup
|
||||
commands["restore"] = commandRestore
|
||||
commands["list"] = commandList
|
||||
commands["snapshots"] = commandSnapshots
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user