From 5b3bce7fdc3dc1f4254cefbcdf68f57c38fdd36c Mon Sep 17 00:00:00 2001 From: xeals Date: Fri, 3 Aug 2018 00:14:31 +1000 Subject: [PATCH] Add simple verification command to test if the backup is readable --- cmd/check.go | 43 +++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 2 files changed, 44 insertions(+) create mode 100644 cmd/check.go diff --git a/cmd/check.go b/cmd/check.go new file mode 100644 index 0000000..36ee875 --- /dev/null +++ b/cmd/check.go @@ -0,0 +1,43 @@ +package cmd + +import ( + "io/ioutil" + "log" + "os" + + "github.com/pkg/errors" + "github.com/urfave/cli" +) + +// Check fulfils the `format` subcommand. +var Check = cli.Command{ + Name: "check", + Usage: "Verify that a backup is readable", + UsageText: "Attempts to decrypt the provided backup and do nothing with it except verify that it's readable\n from start to finish. Enables verbose logging by default.", + CustomHelpTemplate: SubcommandHelp, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "password, p", + Usage: "use `PASS` as password for backup file", + }, + cli.StringFlag{ + Name: "pwdfile, P", + Usage: "read password from `FILE`", + }, + }, + Action: func(c *cli.Context) error { + bf, err := setup(c) + if err != nil { + return err + } + + log.SetOutput(os.Stderr) + + if err := Raw(bf, ioutil.Discard); err != nil { + return errors.Wrap(err, "Encountered error while checking") + } + + log.Println("Backup looks okay from here.") + return nil + }, +} diff --git a/main.go b/main.go index b64bd0f..2720b9b 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ func main() { cmd.Format, cmd.Analyse, cmd.Extract, + cmd.Check, } app.Flags = []cli.Flag{ cli.BoolFlag{