From 54348264fbbe94fac3b31974ff32931c4a37430c Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 11:07:10 +0100 Subject: [PATCH 01/13] added flag for restic snapshots --- cmd/mongodump.go | 2 +- cmd/mysqldump.go | 2 +- cmd/pgdump.go | 2 +- cmd/redisdump.go | 2 +- cmd/root.go | 11 +++++++---- cmd/tar.go | 2 +- pkg/restic/client.go | 19 +++++++++++++++++++ pkg/restic/commands.go | 7 +++++-- pkg/restic/config.go | 7 ++++--- pkg/source/backup.go | 13 ++++++++++--- 10 files changed, 50 insertions(+), 17 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index fe1e858..dcf05f6 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index 41f6126..c5ba71c 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -18,7 +18,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index 15f8256..b6ccea3 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index e400f40..668ec8a 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index 7a2bd82..e06b733 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,10 +15,11 @@ import ( var ( // Used for flags. - cfgFiles []string - useRestic bool - useResticForget bool - cleanup bool + cfgFiles []string + useRestic bool + useResticForget bool + cleanup bool + listResticSnapshots bool rootCmd = &cobra.Command{ Use: "brudi", @@ -37,6 +38,8 @@ func init() { rootCmd.PersistentFlags().BoolVar(&cleanup, "cleanup", false, "cleanup backup files afterwards") + rootCmd.PersistentFlags().BoolVar(&listResticSnapshots, "restic-snapshots", false, "List snapshots in restic repository afterwards") + rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index ff4f5a4..71fbf8b 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index a6b0b02..afd447d 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -26,6 +26,10 @@ func NewResticClient(logger *log.Entry, hostname string, backupPaths ...string) Flags: &ForgetFlags{}, IDs: []string{}, }, + Snapshots: &SnapshotOptions{ + Flags: &SnapshotFlags{}, + IDs: []string{}, + }, } err := conf.InitFromViper() @@ -83,3 +87,18 @@ func (c *Client) DoResticForget(ctx context.Context) error { return nil } + +func (c *Client) ListSnapshots(ctx context.Context) error { + c.Logger.Info("running 'restic snapshots'") + + output, err := ListSnapshots(ctx, c.Config.Global, c.Config.Snapshots) + if err != nil { + return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + } + fmt.Println("output of `restic snapshots`:") + for index := range output { + fmt.Println(fmt.Sprintf("ID: %s; Time: %s; Host: %s; Tags: %s; Paths: %s", + output[index].ID, output[index].Time, output[index].Hostname, output[index].Tags, output[index].Paths)) + } + return nil +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 51873ab..93c2b0b 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -229,14 +229,17 @@ func GetSnapshotSizeByPath(ctx context.Context, snapshotID, path string) (size u } // ListSnapshots executes "restic snapshots" -func ListSnapshots(ctx context.Context, opts *SnapshotOptions) ([]Snapshot, error) { +func ListSnapshots(ctx context.Context, glob *GlobalOptions, opts *SnapshotOptions) ([]Snapshot, error) { + args := append([]string{"--json"}, cli.StructToCLI(opts)...) + args = append(args, cli.StructToCLI(glob)...) cmd := cli.CommandType{ Binary: binary, Command: "snapshots", - Args: append([]string{"--json"}, cli.StructToCLI(opts)...), + Args: args, } out, err := cli.Run(ctx, cmd) if err != nil { + fmt.Println(string(out)) return nil, err } diff --git a/pkg/restic/config.go b/pkg/restic/config.go index f373fe8..78ceff2 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -9,9 +9,10 @@ const ( ) type Config struct { - Global *GlobalOptions - Backup *BackupOptions - Forget *ForgetOptions + Global *GlobalOptions + Backup *BackupOptions + Forget *ForgetOptions + Snapshots *SnapshotOptions } func (c *Config) InitFromViper() error { diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 320920e..38ccc30 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -34,7 +34,7 @@ func getGenericBackendForKind(kind string) (Generic, error) { } } -func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget bool) error { +func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -84,9 +84,16 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe return err } - if !useResticForget { + if useResticForget { + err = resticClient.DoResticForget(ctx) + if err != nil { + return err + } + } + if !listResticSnapshots { return nil } - return resticClient.DoResticForget(ctx) + return resticClient.ListSnapshots(ctx) + } From 83864b5c0ac3fd154411d809f834ac5f3f20c566 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 11:25:01 +0100 Subject: [PATCH 02/13] added flag for restic check --- cmd/mongodump.go | 2 +- cmd/mysqldump.go | 2 +- cmd/pgdump.go | 2 +- cmd/redisdump.go | 2 +- cmd/root.go | 5 ++++- cmd/tar.go | 2 +- pkg/restic/client.go | 13 ++++++++++++- pkg/restic/commands.go | 4 ++-- pkg/restic/config.go | 1 + pkg/source/backup.go | 13 ++++++++++--- 10 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index dcf05f6..7e86d3a 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) + err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index c5ba71c..0433bfc 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -18,7 +18,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) + err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index b6ccea3..6c25e24 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) + err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index 668ec8a..d91ca2a 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) + err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index e06b733..e407fb2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,6 +20,7 @@ var ( useResticForget bool cleanup bool listResticSnapshots bool + doResticCheck bool rootCmd = &cobra.Command{ Use: "brudi", @@ -38,7 +39,9 @@ func init() { rootCmd.PersistentFlags().BoolVar(&cleanup, "cleanup", false, "cleanup backup files afterwards") - rootCmd.PersistentFlags().BoolVar(&listResticSnapshots, "restic-snapshots", false, "List snapshots in restic repository afterwards") + rootCmd.PersistentFlags().BoolVar(&listResticSnapshots, "restic-snapshots", false, "list snapshots in restic repository afterwards") + + rootCmd.PersistentFlags().BoolVar(&doResticCheck, "restic-check", false, "perform 'restic check' on the repository") rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index 71fbf8b..30af0c5 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -19,7 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots) + err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index afd447d..3685103 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -3,7 +3,6 @@ package restic import ( "context" "fmt" - "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -30,6 +29,7 @@ func NewResticClient(logger *log.Entry, hostname string, backupPaths ...string) Flags: &SnapshotFlags{}, IDs: []string{}, }, + Check: &CheckFlags{}, } err := conf.InitFromViper() @@ -102,3 +102,14 @@ func (c *Client) ListSnapshots(ctx context.Context) error { } return nil } + +func (c *Client) DoResticCheck(ctx context.Context) error { + c.Logger.Info("running 'restic check'") + + output, err := Check(ctx, c.Config.Global, c.Config.Check) + if err != nil { + return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + } + fmt.Println(string(output)) + return nil +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 93c2b0b..86c9f81 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -270,11 +270,11 @@ func Find(ctx context.Context, opts *FindOptions) ([]FindResult, error) { } // Check executes "restic check" -func Check(ctx context.Context, flags *CheckFlags) ([]byte, error) { +func Check(ctx context.Context, glob *GlobalOptions, flags *CheckFlags) ([]byte, error) { cmd := cli.CommandType{ Binary: binary, Command: "check", - Args: cli.StructToCLI(flags), + Args: append(cli.StructToCLI(glob), cli.StructToCLI(flags)...), } return cli.Run(ctx, cmd) } diff --git a/pkg/restic/config.go b/pkg/restic/config.go index 78ceff2..3a13bce 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -13,6 +13,7 @@ type Config struct { Backup *BackupOptions Forget *ForgetOptions Snapshots *SnapshotOptions + Check *CheckFlags } func (c *Config) InitFromViper() error { diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 38ccc30..8dd63af 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -34,7 +34,7 @@ func getGenericBackendForKind(kind string) (Generic, error) { } } -func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots bool) error { +func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, resticCheck bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -90,10 +90,17 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe return err } } - if !listResticSnapshots { + if listResticSnapshots { + err = resticClient.ListSnapshots(ctx) + if err != nil { + return err + } + } + + if !resticCheck { return nil } - return resticClient.ListSnapshots(ctx) + return resticClient.DoResticCheck(ctx) } From d37a92fea3e4fc5359b004a6720c556b41a16a67 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 11:33:02 +0100 Subject: [PATCH 03/13] added flag for restic prune --- cmd/mongodump.go | 3 ++- cmd/mysqldump.go | 3 ++- cmd/pgdump.go | 3 ++- cmd/redisdump.go | 3 ++- cmd/root.go | 3 +++ cmd/tar.go | 3 ++- pkg/restic/client.go | 13 ++++++++++++- pkg/restic/commands.go | 4 ++-- pkg/source/backup.go | 10 +++++++++- 9 files changed, 36 insertions(+), 9 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index 7e86d3a..21c99e8 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -19,7 +19,8 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) + err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, + doResticCheck, doResticPrune) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index 0433bfc..acb2781 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -18,7 +18,8 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) + err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, + doResticCheck, doResticPrune) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index 6c25e24..f797e4f 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -19,7 +19,8 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) + err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, + doResticCheck, doResticPrune) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index d91ca2a..7f87b14 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -19,7 +19,8 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) + err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, + doResticCheck, doResticPrune) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index e407fb2..af717f9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,6 +21,7 @@ var ( cleanup bool listResticSnapshots bool doResticCheck bool + doResticPrune bool rootCmd = &cobra.Command{ Use: "brudi", @@ -43,6 +44,8 @@ func init() { rootCmd.PersistentFlags().BoolVar(&doResticCheck, "restic-check", false, "perform 'restic check' on the repository") + rootCmd.PersistentFlags().BoolVar(&doResticPrune, "restic-prune", false, "perform 'restic prune' on the repository") + rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index 30af0c5..c7559a1 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -19,7 +19,8 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, doResticCheck) + err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, + doResticCheck, doResticPrune) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 3685103..919d929 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -95,7 +95,7 @@ func (c *Client) ListSnapshots(ctx context.Context) error { if err != nil { return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) } - fmt.Println("output of `restic snapshots`:") + fmt.Println("output of 'restic snapshots':") for index := range output { fmt.Println(fmt.Sprintf("ID: %s; Time: %s; Host: %s; Tags: %s; Paths: %s", output[index].ID, output[index].Time, output[index].Hostname, output[index].Tags, output[index].Paths)) @@ -113,3 +113,14 @@ func (c *Client) DoResticCheck(ctx context.Context) error { fmt.Println(string(output)) return nil } + +func (c *Client) PruneRepo(ctx context.Context) error { + c.Logger.Info("running 'restic prune") + + output, err := Prune(ctx, c.Config.Global) + if err != nil { + return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + } + fmt.Println(string(output)) + return nil +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 86c9f81..7b244eb 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -344,11 +344,11 @@ func Forget( } // Prune executes "restic prune" -func Prune(ctx context.Context) ([]byte, error) { +func Prune(ctx context.Context, glob *GlobalOptions) ([]byte, error) { cmd := cli.CommandType{ Binary: binary, Command: "prune", - Args: nil, + Args: cli.StructToCLI(glob), } return cli.Run(ctx, cmd) } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 8dd63af..3abf208 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -34,7 +34,8 @@ func getGenericBackendForKind(kind string) (Generic, error) { } } -func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, resticCheck bool) error { +func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, + resticCheck, resticPrune bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -97,6 +98,13 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe } } + if resticPrune { + err = resticClient.PruneRepo(ctx) + if err != nil { + return err + } + } + if !resticCheck { return nil } From 9c65549c126459a3f9471e263615578d2bec6fc2 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 11:39:58 +0100 Subject: [PATCH 04/13] added flag for restic rebuild-index --- cmd/mongodump.go | 2 +- cmd/mysqldump.go | 2 +- cmd/pgdump.go | 2 +- cmd/redisdump.go | 2 +- cmd/root.go | 3 +++ cmd/tar.go | 2 +- pkg/restic/client.go | 11 +++++++++++ pkg/restic/commands.go | 4 ++-- pkg/source/backup.go | 9 ++++++++- 9 files changed, 29 insertions(+), 8 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index 21c99e8..c50d2c9 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune) + doResticCheck, doResticPrune, rebuildResticIndex) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index acb2781..41ce8b2 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -19,7 +19,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune) + doResticCheck, doResticPrune, rebuildResticIndex) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index f797e4f..aac7f3c 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune) + doResticCheck, doResticPrune, rebuildResticIndex) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index 7f87b14..7708391 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune) + doResticCheck, doResticPrune, rebuildResticIndex) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index af717f9..4dbaec4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,6 +22,7 @@ var ( listResticSnapshots bool doResticCheck bool doResticPrune bool + rebuildResticIndex bool rootCmd = &cobra.Command{ Use: "brudi", @@ -46,6 +47,8 @@ func init() { rootCmd.PersistentFlags().BoolVar(&doResticPrune, "restic-prune", false, "perform 'restic prune' on the repository") + rootCmd.PersistentFlags().BoolVar(&rebuildResticIndex, "restic-rebuild-index", false, "perform 'restic rebuild-index' on the repository") + rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index c7559a1..6c9c49a 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune) + doResticCheck, doResticPrune, rebuildResticIndex) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 919d929..8781415 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -124,3 +124,14 @@ func (c *Client) PruneRepo(ctx context.Context) error { fmt.Println(string(output)) return nil } + +func (c *Client) RebuildIndex(ctx context.Context) error { + c.Logger.Info("running 'restic rebuild-index'") + + output, err := RebuildIndex(ctx, c.Config.Global) + if err != nil { + return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + } + fmt.Println(string(output)) + return nil +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index 7b244eb..c0b1a20 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -354,13 +354,13 @@ func Prune(ctx context.Context, glob *GlobalOptions) ([]byte, error) { } // RebuildIndex executes "restic rebuild-index" -func RebuildIndex(ctx context.Context) ([]byte, error) { +func RebuildIndex(ctx context.Context, glob *GlobalOptions) ([]byte, error) { nice := 19 ionice := 2 cmd := cli.CommandType{ Binary: binary, Command: "rebuild-index", - Args: nil, + Args: cli.StructToCLI(glob), Nice: &nice, IONice: &ionice, } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 3abf208..a9f758e 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -35,7 +35,7 @@ func getGenericBackendForKind(kind string) (Generic, error) { } func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, - resticCheck, resticPrune bool) error { + resticCheck, resticPrune, rebuildIndex bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -105,6 +105,13 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe } } + if rebuildIndex { + err = resticClient.RebuildIndex(ctx) + if err != nil { + return err + } + } + if !resticCheck { return nil } From 85e3d2ca826977aa704fbbf43c173439cca31c60 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 11:52:15 +0100 Subject: [PATCH 05/13] added flag for restic tags --- cmd/mongodump.go | 2 +- cmd/mysqldump.go | 2 +- cmd/pgdump.go | 2 +- cmd/redisdump.go | 2 +- cmd/root.go | 3 +++ cmd/tar.go | 2 +- pkg/restic/client.go | 15 +++++++++++++++ pkg/restic/commands.go | 4 ++-- pkg/restic/config.go | 1 + pkg/source/backup.go | 10 +++++++++- 10 files changed, 35 insertions(+), 8 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index c50d2c9..e1ce214 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex) + doResticCheck, doResticPrune, rebuildResticIndex, resticTags) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index 41ce8b2..4b637a1 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -19,7 +19,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex) + doResticCheck, doResticPrune, rebuildResticIndex, resticTags) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index aac7f3c..207c088 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex) + doResticCheck, doResticPrune, rebuildResticIndex, resticTags) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index 7708391..b75a112 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex) + doResticCheck, doResticPrune, rebuildResticIndex, resticTags) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index 4dbaec4..61e9d3d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,6 +23,7 @@ var ( doResticCheck bool doResticPrune bool rebuildResticIndex bool + resticTags bool rootCmd = &cobra.Command{ Use: "brudi", @@ -49,6 +50,8 @@ func init() { rootCmd.PersistentFlags().BoolVar(&rebuildResticIndex, "restic-rebuild-index", false, "perform 'restic rebuild-index' on the repository") + rootCmd.PersistentFlags().BoolVar(&resticTags, "restic-tags", false, "executes 'restic tags' after backing up things with restic") + rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index 6c9c49a..1edc7b0 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -20,7 +20,7 @@ var ( defer cancel() err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex) + doResticCheck, doResticPrune, rebuildResticIndex, resticTags) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 8781415..5c198d3 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -29,6 +29,10 @@ func NewResticClient(logger *log.Entry, hostname string, backupPaths ...string) Flags: &SnapshotFlags{}, IDs: []string{}, }, + Tags: &TagOptions{ + Flags: &TagFlags{}, + IDs: []string{}, + }, Check: &CheckFlags{}, } @@ -135,3 +139,14 @@ func (c *Client) RebuildIndex(ctx context.Context) error { fmt.Println(string(output)) return nil } + +func (c *Client) ResticTag(ctx context.Context) error { + c.Logger.Info("running 'restic rebuild-index'") + + output, err := Tag(ctx, c.Config.Global, c.Config.Tags) + if err != nil { + return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + } + fmt.Println(string(output)) + return nil +} diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index c0b1a20..b356bb1 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -392,11 +392,11 @@ func Unlock(ctx context.Context, globalOpts *GlobalOptions, unlockOpts *UnlockOp } // Tag executes "restic tag" -func Tag(ctx context.Context, opts *TagOptions) ([]byte, error) { +func Tag(ctx context.Context, glob *GlobalOptions, opts *TagOptions) ([]byte, error) { cmd := cli.CommandType{ Binary: binary, Command: "tag", - Args: cli.StructToCLI(opts), + Args: append(cli.StructToCLI(glob), cli.StructToCLI(opts)...), } return cli.Run(ctx, cmd) } diff --git a/pkg/restic/config.go b/pkg/restic/config.go index 3a13bce..3c35c7d 100644 --- a/pkg/restic/config.go +++ b/pkg/restic/config.go @@ -13,6 +13,7 @@ type Config struct { Backup *BackupOptions Forget *ForgetOptions Snapshots *SnapshotOptions + Tags *TagOptions Check *CheckFlags } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index a9f758e..8151205 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -35,7 +35,7 @@ func getGenericBackendForKind(kind string) (Generic, error) { } func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, - resticCheck, resticPrune, rebuildIndex bool) error { + resticCheck, resticPrune, rebuildIndex, resticTags bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -91,6 +91,7 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe return err } } + if listResticSnapshots { err = resticClient.ListSnapshots(ctx) if err != nil { @@ -105,6 +106,13 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe } } + if resticTags { + err = resticClient.ResticTag(ctx) + if err != nil { + return err + } + } + if rebuildIndex { err = resticClient.RebuildIndex(ctx) if err != nil { From 40883879e5d5d84f789203f53ec83fcbebb0bd44 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Thu, 24 Dec 2020 12:07:31 +0100 Subject: [PATCH 06/13] updated readme --- README.md | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/README.md b/README.md index 555e263..dc9a020 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ Using `brudi` will save you from finding yourself writing bash-scripts to create - [Redis](#redis) - [Restic](#restic) - [Forget](#forget) + - [Snapshots](#snapshots) + - [Check](#check) + - [Prune](#prune) + - [Rebuild-Index](#rebuild-index) + - [Tags](#tags) - [Sensitive data: Environment variables](#sensitive-data--environment-variables) - [Featurestate](#featurestate) - [Source backup methods](#source-backup-methods) @@ -262,6 +267,82 @@ restic: ids: [] ``` +##### Snapshots + +It's possible to run `restic snapshots`-cmd after executing `restic backup` with `brudi` by using `--restic-snapshots`. +The `snapshots`-options are defined in the configuration `.yaml` for brudi. + +```yaml +restic: + global: + flags: + # you can provide the repository also via RESTIC_REPOSITORY + repo: "s3:s3.eu-central-1.amazonaws.com/your.s3.bucket/myResticRepo" + backup: + flags: + # in case there is no hostname given, the hostname from source backup is used + hostname: "MyHost" + # these paths are backuped additionally to your given source backup + paths: [] + snapshots: + flags: + host: "MyHost" +``` + +##### Check + +It's possible to run `restic check`-cmd after executing `restic backup` with `brudi` by using `--restic-check`. +The `check`-options are defined in the configuration `.yaml` for brudi. + +```yaml +restic: + global: + flags: + # you can provide the repository also via RESTIC_REPOSITORY + repo: "s3:s3.eu-central-1.amazonaws.com/your.s3.bucket/myResticRepo" + backup: + flags: + # in case there is no hostname given, the hostname from source backup is used + hostname: "MyHost" + # these paths are backuped additionally to your given source backup + paths: [] + check: + checkUnused: true +``` + +##### Prune + +It's possible to run `restic prune`-cmd after executing `restic backup` with `brudi` by using `--restic-prune`. +The `prune`-cmd has no specific options + +##### Rebuild-Index +It's possible to run `restic rebuild-index`-cmd after executing `restic backup` with `brudi` by using `--restic-rebuild-index`. +he `rebuild-index`-cmd has no specific options + +##### Tags + +It's possible to run `restic tags`-cmd after executing `restic backup` with `brudi` by using `--restic-tags`. +The `tags`-options are defined in the configuration `.yaml` for brudi. + +```yaml +restic: + global: + flags: + # you can provide the repository also via RESTIC_REPOSITORY + repo: "s3:s3.eu-central-1.amazonaws.com/your.s3.bucket/myResticRepo" + backup: + flags: + # in case there is no hostname given, the hostname from source backup is used + hostname: "MyHost" + # these paths are backuped additionally to your given source backup + paths: [] + tags: + flags: + add: ["TestTag"] + host: "MyHost" + ids: [] +``` + #### Sensitive data: Environment variables In case you don't want to provide data directly in the `.yaml`-file, e.g. sensitive data like passwords, you can use environment-variables. @@ -304,5 +385,10 @@ As soon as a variable for a key exists in your environment, the value of this en - [x] `commands` - [x] `restic backup` - [x] `restic forget` + - [x] `restic snapshots` + - [x] `restic prune` + - [x] `restic check` + - [x] `restic rebuild index` + - [x] `restic taga` - [x] `storage` - [x] `s3` From 0fd391040dd683d4ef9d92eb58116d2cd5b635ec Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Wed, 30 Dec 2020 16:14:28 +0100 Subject: [PATCH 07/13] Refactoring and documentation --- pkg/restic/client.go | 16 ++++++++++++---- pkg/restic/commands.go | 2 +- pkg/source/backup.go | 12 ++++++++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 5c198d3..645426a 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -12,6 +12,7 @@ type Client struct { Config *Config } +// NewResticClient creates a new restic client with the given hostname and backup paths func NewResticClient(logger *log.Entry, hostname string, backupPaths ...string) (*Client, error) { conf := &Config{ Global: &GlobalOptions{ @@ -55,6 +56,7 @@ func NewResticClient(logger *log.Entry, hostname string, backupPaths ...string) }, nil } +// DoResticBackup executes initBackup and CreateBackup with the settings from c func (c *Client) DoResticBackup(ctx context.Context) error { c.Logger.Info("running 'restic backup'") @@ -77,6 +79,7 @@ func (c *Client) DoResticBackup(ctx context.Context) error { return nil } +// DoResticForget executes Forget with the settings from c func (c *Client) DoResticForget(ctx context.Context) error { c.Logger.Info("running 'restic forget'") @@ -92,7 +95,8 @@ func (c *Client) DoResticForget(ctx context.Context) error { return nil } -func (c *Client) ListSnapshots(ctx context.Context) error { +// DoResticListSnapshots executes ListSnapshots with the settings from c +func (c *Client) DoResticListSnapshots(ctx context.Context) error { c.Logger.Info("running 'restic snapshots'") output, err := ListSnapshots(ctx, c.Config.Global, c.Config.Snapshots) @@ -107,6 +111,7 @@ func (c *Client) ListSnapshots(ctx context.Context) error { return nil } +// DoResticCheck executes Check with the settings from c func (c *Client) DoResticCheck(ctx context.Context) error { c.Logger.Info("running 'restic check'") @@ -118,7 +123,8 @@ func (c *Client) DoResticCheck(ctx context.Context) error { return nil } -func (c *Client) PruneRepo(ctx context.Context) error { +// DoResticPruneRepo executes Prune with the settings from c +func (c *Client) DoResticPruneRepo(ctx context.Context) error { c.Logger.Info("running 'restic prune") output, err := Prune(ctx, c.Config.Global) @@ -129,7 +135,8 @@ func (c *Client) PruneRepo(ctx context.Context) error { return nil } -func (c *Client) RebuildIndex(ctx context.Context) error { +// DoResticRebuildIndex executes RebuildIndex with the settings from c +func (c *Client) DoResticRebuildIndex(ctx context.Context) error { c.Logger.Info("running 'restic rebuild-index'") output, err := RebuildIndex(ctx, c.Config.Global) @@ -140,7 +147,8 @@ func (c *Client) RebuildIndex(ctx context.Context) error { return nil } -func (c *Client) ResticTag(ctx context.Context) error { +// DoResticTag executes Tag with the settings from c +func (c *Client) DoResticTag(ctx context.Context) error { c.Logger.Info("running 'restic rebuild-index'") output, err := Tag(ctx, c.Config.Global, c.Config.Tags) diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index b356bb1..af60801 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -39,7 +39,7 @@ func init() { forgetConcreteSnapshotPattern = regexp.MustCompile(`^removed snapshot ([0-9a-z].*)$`) } -// InitBackup executes "restic init" +// initBackup executes "restic init" func initBackup(ctx context.Context, globalOpts *GlobalOptions) ([]byte, error) { cmd := cli.CommandType{ Binary: binary, diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 8151205..b002a81 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -34,6 +34,8 @@ func getGenericBackendForKind(kind string) (Generic, error) { } } +// DoBackupForKind performs the appropriate backup action for given arguments. +// It also executes any given restic commands after files have been backed up, func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, resticCheck, resticPrune, rebuildIndex, resticTags bool) error { logKind := log.WithFields( @@ -80,6 +82,8 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe return err } + // execute any applicable restic commands + err = resticClient.DoResticBackup(ctx) if err != nil { return err @@ -93,28 +97,28 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe } if listResticSnapshots { - err = resticClient.ListSnapshots(ctx) + err = resticClient.DoResticListSnapshots(ctx) if err != nil { return err } } if resticPrune { - err = resticClient.PruneRepo(ctx) + err = resticClient.DoResticPruneRepo(ctx) if err != nil { return err } } if resticTags { - err = resticClient.ResticTag(ctx) + err = resticClient.DoResticTag(ctx) if err != nil { return err } } if rebuildIndex { - err = resticClient.RebuildIndex(ctx) + err = resticClient.DoResticRebuildIndex(ctx) if err != nil { return err } From 61ae6e027c765e3466ce2e2659ad247d4a8fd7c7 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Mon, 11 Jan 2021 17:10:59 +0100 Subject: [PATCH 08/13] wrap extra flags in struct --- cmd/mongodump.go | 9 +++++++-- cmd/mysqldump.go | 9 +++++++-- cmd/pgdump.go | 9 +++++++-- cmd/redisdump.go | 9 +++++++-- pkg/source/backup.go | 13 ++++++------- pkg/source/types.go | 8 ++++++++ 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index e1ce214..0d0a9b1 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -19,8 +19,13 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mongodump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex, resticTags) + err := source.DoBackupForKind(ctx, mongodump.Kind, source.ExtraResticFlags{ + ResticCheck: doResticCheck, + ResticList: listResticSnapshots, + ResticRebuild: rebuildResticIndex, + ResticPrune: doResticPrune, + ResticTags: resticTags, + }, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index 4b637a1..0483ffb 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -18,8 +18,13 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mysqldump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex, resticTags) + err := source.DoBackupForKind(ctx, mysqldump.Kind, source.ExtraResticFlags{ + ResticCheck: doResticCheck, + ResticList: listResticSnapshots, + ResticRebuild: rebuildResticIndex, + ResticPrune: doResticPrune, + ResticTags: resticTags, + }, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index 207c088..d6dc41e 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -19,8 +19,13 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, pgdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex, resticTags) + err := source.DoBackupForKind(ctx, pgdump.Kind, source.ExtraResticFlags{ + ResticCheck: doResticCheck, + ResticList: listResticSnapshots, + ResticRebuild: rebuildResticIndex, + ResticPrune: doResticPrune, + ResticTags: resticTags, + }, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index b75a112..dd3582a 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -19,8 +19,13 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, redisdump.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex, resticTags) + err := source.DoBackupForKind(ctx, redisdump.Kind, source.ExtraResticFlags{ + ResticCheck: doResticCheck, + ResticList: listResticSnapshots, + ResticRebuild: rebuildResticIndex, + ResticPrune: doResticPrune, + ResticTags: resticTags, + }, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index b002a81..4fc3cc0 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -36,8 +36,7 @@ func getGenericBackendForKind(kind string) (Generic, error) { // DoBackupForKind performs the appropriate backup action for given arguments. // It also executes any given restic commands after files have been backed up, -func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useResticForget, listResticSnapshots, - resticCheck, resticPrune, rebuildIndex, resticTags bool) error { +func DoBackupForKind(ctx context.Context, kind string, resticFlags ExtraResticFlags, cleanup, useRestic, useResticForget bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -96,35 +95,35 @@ func DoBackupForKind(ctx context.Context, kind string, cleanup, useRestic, useRe } } - if listResticSnapshots { + if resticFlags.ResticList { err = resticClient.DoResticListSnapshots(ctx) if err != nil { return err } } - if resticPrune { + if resticFlags.ResticPrune { err = resticClient.DoResticPruneRepo(ctx) if err != nil { return err } } - if resticTags { + if resticFlags.ResticTags { err = resticClient.DoResticTag(ctx) if err != nil { return err } } - if rebuildIndex { + if resticFlags.ResticRebuild { err = resticClient.DoResticRebuildIndex(ctx) if err != nil { return err } } - if !resticCheck { + if !resticFlags.ResticCheck { return nil } diff --git a/pkg/source/types.go b/pkg/source/types.go index c8d2377..6404db4 100644 --- a/pkg/source/types.go +++ b/pkg/source/types.go @@ -4,6 +4,14 @@ import ( "context" ) +type ExtraResticFlags struct { + ResticList bool + ResticCheck bool + ResticPrune bool + ResticRebuild bool + ResticTags bool +} + type Generic interface { CreateBackup(ctx context.Context) error GetBackupPath() string From 174208afb3a77f4d686406e22b273363c2086256 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Mon, 11 Jan 2021 17:16:20 +0100 Subject: [PATCH 09/13] update tests to new method signature of doBackupForKind --- test/pkg/source/mongodbtest/mongodb_test.go | 2 +- test/pkg/source/mysqltest/mysql_test.go | 2 +- test/pkg/source/postgrestest/postgres_test.go | 2 +- test/pkg/source/redisdump/redisdump_test.go | 2 +- test/pkg/source/tar/tar_test.go | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/pkg/source/mongodbtest/mongodb_test.go b/test/pkg/source/mongodbtest/mongodb_test.go index b3551bb..bc1706e 100644 --- a/test/pkg/source/mongodbtest/mongodb_test.go +++ b/test/pkg/source/mongodbtest/mongodb_test.go @@ -150,7 +150,7 @@ func mongoDoBackup(ctx context.Context, useRestic bool, } // perform backup action on mongodb-container - err = source.DoBackupForKind(ctx, dumpKind, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) if err != nil { return []interface{}{}, err } diff --git a/test/pkg/source/mysqltest/mysql_test.go b/test/pkg/source/mysqltest/mysql_test.go index c6f4886..79d747c 100644 --- a/test/pkg/source/mysqltest/mysql_test.go +++ b/test/pkg/source/mysqltest/mysql_test.go @@ -172,7 +172,7 @@ func mySQLDoBackup(ctx context.Context, useRestic bool, } // use brudi to create dump - err = source.DoBackupForKind(ctx, dumpKind, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) if err != nil { return []TestStruct{}, err } diff --git a/test/pkg/source/postgrestest/postgres_test.go b/test/pkg/source/postgrestest/postgres_test.go index 183468b..b80ebee 100644 --- a/test/pkg/source/postgrestest/postgres_test.go +++ b/test/pkg/source/postgrestest/postgres_test.go @@ -192,7 +192,7 @@ func pgDoBackup(ctx context.Context, useRestic bool, } // perform backup action on database - err = source.DoBackupForKind(ctx, dumpKind, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) if err != nil { return []testStruct{}, err } diff --git a/test/pkg/source/redisdump/redisdump_test.go b/test/pkg/source/redisdump/redisdump_test.go index 83d0b1e..5d1277c 100644 --- a/test/pkg/source/redisdump/redisdump_test.go +++ b/test/pkg/source/redisdump/redisdump_test.go @@ -160,7 +160,7 @@ func redisDoBackup(ctx context.Context, useRestic bool, } // perform backup action on first redis container - err = source.DoBackupForKind(ctx, dumpKind, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) if err != nil { return testStruct{}, errors.WithStack(err) } diff --git a/test/pkg/source/tar/tar_test.go b/test/pkg/source/tar/tar_test.go index 430fb4f..2247c71 100644 --- a/test/pkg/source/tar/tar_test.go +++ b/test/pkg/source/tar/tar_test.go @@ -76,7 +76,7 @@ func TestTarTestSuite(t *testing.T) { // tarDoBackup uses brudi to compress a test file into a tar.gz archive and returns the uncompressed files md5 hash func tarDoBackup(ctx context.Context) (string, error) { hash, err := hashFile(backupPath) - err = source.DoBackupForKind(ctx, "tar", false, false, false) + err = source.DoBackupForKind(ctx, "tar", source.ExtraResticFlags{}, false, false, false) if err != nil { return "", err } From a1d4f5b20ee40ce9450870507e10d01630fd367b Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Mon, 11 Jan 2021 17:28:48 +0100 Subject: [PATCH 10/13] fixed misisng and wrong functions and arguments --- cmd/tar.go | 9 +++++++-- pkg/restic/client.go | 9 +++++++++ test/pkg/source/internal/testcommons.go | 9 +++++++++ test/pkg/source/mongodbtest/mongodb_test.go | 2 +- test/pkg/source/mysqltest/mysql_test.go | 2 +- test/pkg/source/postgrestest/postgres_test.go | 2 +- test/pkg/source/redisdump/redisdump_test.go | 2 +- test/pkg/source/tar/tar_test.go | 2 +- 8 files changed, 30 insertions(+), 7 deletions(-) diff --git a/cmd/tar.go b/cmd/tar.go index 1edc7b0..766ebaf 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -19,8 +19,13 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, tar.Kind, cleanup, useRestic, useResticForget, listResticSnapshots, - doResticCheck, doResticPrune, rebuildResticIndex, resticTags) + err := source.DoBackupForKind(ctx, tar.Kind, source.ExtraResticFlags{ + ResticCheck: doResticCheck, + ResticList: listResticSnapshots, + ResticRebuild: rebuildResticIndex, + ResticPrune: doResticPrune, + ResticTags: resticTags, + }, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/pkg/restic/client.go b/pkg/restic/client.go index af55082..0debbc1 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -83,6 +83,15 @@ func (c *Client) DoResticBackup(ctx context.Context) error { return nil } +func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { + c.Logger.Info("running 'restic restore'") + _, err := RestoreBackup(ctx, c.Config.Global, c.Config.Restore, false) + if err != nil { + return errors.WithStack(fmt.Errorf("error while while running restic restore: %s", err.Error())) + } + return nil +} + func (c *Client) DoResticForget(ctx context.Context) error { c.Logger.Info("running 'restic forget'") diff --git a/test/pkg/source/internal/testcommons.go b/test/pkg/source/internal/testcommons.go index e9ddb32..2f9983e 100644 --- a/test/pkg/source/internal/testcommons.go +++ b/test/pkg/source/internal/testcommons.go @@ -3,6 +3,7 @@ package internal import ( "context" "fmt" + "github.com/mittwald/brudi/pkg/source" "github.com/pkg/errors" "github.com/spf13/viper" "os" @@ -33,6 +34,14 @@ var ResticReq = testcontainers.ContainerRequest{ }, } +var ExtraFlags = source.ExtraResticFlags{ + ResticCheck: false, + ResticRebuild: false, + ResticTags: false, + ResticPrune: false, + ResticList: false, +} + // NewTestContainerSetup creates a TestContainerSetup which acts as a wrapper for the testcontainer specified by request func NewTestContainerSetup(ctx context.Context, request *testcontainers.ContainerRequest, port nat.Port) (TestContainerSetup, error) { result := TestContainerSetup{} diff --git a/test/pkg/source/mongodbtest/mongodb_test.go b/test/pkg/source/mongodbtest/mongodb_test.go index bc1706e..5518c7c 100644 --- a/test/pkg/source/mongodbtest/mongodb_test.go +++ b/test/pkg/source/mongodbtest/mongodb_test.go @@ -150,7 +150,7 @@ func mongoDoBackup(ctx context.Context, useRestic bool, } // perform backup action on mongodb-container - err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, commons.ExtraFlags, false, useRestic, false) if err != nil { return []interface{}{}, err } diff --git a/test/pkg/source/mysqltest/mysql_test.go b/test/pkg/source/mysqltest/mysql_test.go index 79d747c..63e80b5 100644 --- a/test/pkg/source/mysqltest/mysql_test.go +++ b/test/pkg/source/mysqltest/mysql_test.go @@ -172,7 +172,7 @@ func mySQLDoBackup(ctx context.Context, useRestic bool, } // use brudi to create dump - err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, commons.ExtraFlags, false, useRestic, false) if err != nil { return []TestStruct{}, err } diff --git a/test/pkg/source/postgrestest/postgres_test.go b/test/pkg/source/postgrestest/postgres_test.go index b80ebee..99264cc 100644 --- a/test/pkg/source/postgrestest/postgres_test.go +++ b/test/pkg/source/postgrestest/postgres_test.go @@ -192,7 +192,7 @@ func pgDoBackup(ctx context.Context, useRestic bool, } // perform backup action on database - err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, commons.ExtraFlags, false, useRestic, false) if err != nil { return []testStruct{}, err } diff --git a/test/pkg/source/redisdump/redisdump_test.go b/test/pkg/source/redisdump/redisdump_test.go index 5d1277c..f8f1274 100644 --- a/test/pkg/source/redisdump/redisdump_test.go +++ b/test/pkg/source/redisdump/redisdump_test.go @@ -160,7 +160,7 @@ func redisDoBackup(ctx context.Context, useRestic bool, } // perform backup action on first redis container - err = source.DoBackupForKind(ctx, dumpKind, source.ExtraResticFlags{}, false, useRestic, false) + err = source.DoBackupForKind(ctx, dumpKind, commons.ExtraFlags, false, useRestic, false) if err != nil { return testStruct{}, errors.WithStack(err) } diff --git a/test/pkg/source/tar/tar_test.go b/test/pkg/source/tar/tar_test.go index 2247c71..1f2fc82 100644 --- a/test/pkg/source/tar/tar_test.go +++ b/test/pkg/source/tar/tar_test.go @@ -76,7 +76,7 @@ func TestTarTestSuite(t *testing.T) { // tarDoBackup uses brudi to compress a test file into a tar.gz archive and returns the uncompressed files md5 hash func tarDoBackup(ctx context.Context) (string, error) { hash, err := hashFile(backupPath) - err = source.DoBackupForKind(ctx, "tar", source.ExtraResticFlags{}, false, false, false) + err = source.DoBackupForKind(ctx, "tar", commons.ExtraFlags, false, false, false) if err != nil { return "", err } From a53a3e854a874528d46f1674a9ea492521597bc9 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Tue, 12 Jan 2021 14:04:13 +0100 Subject: [PATCH 11/13] linting --- cmd/mongodump.go | 8 +------ cmd/mysqldump.go | 8 +------ cmd/pgdump.go | 8 +------ cmd/redisdump.go | 8 +------ cmd/root.go | 29 +++++++++++++------------ cmd/tar.go | 8 +------ pkg/config/types.go | 8 +++++++ pkg/restic/client.go | 7 +++--- pkg/source/backup.go | 6 +++-- pkg/source/types.go | 8 ------- test/pkg/source/internal/testcommons.go | 9 ++++---- 11 files changed, 41 insertions(+), 66 deletions(-) diff --git a/cmd/mongodump.go b/cmd/mongodump.go index 0d0a9b1..0e98460 100644 --- a/cmd/mongodump.go +++ b/cmd/mongodump.go @@ -19,13 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mongodump.Kind, source.ExtraResticFlags{ - ResticCheck: doResticCheck, - ResticList: listResticSnapshots, - ResticRebuild: rebuildResticIndex, - ResticPrune: doResticPrune, - ResticTags: resticTags, - }, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, mongodump.Kind, extaResticFlags, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/mysqldump.go b/cmd/mysqldump.go index 0483ffb..72f3fc2 100644 --- a/cmd/mysqldump.go +++ b/cmd/mysqldump.go @@ -18,13 +18,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, mysqldump.Kind, source.ExtraResticFlags{ - ResticCheck: doResticCheck, - ResticList: listResticSnapshots, - ResticRebuild: rebuildResticIndex, - ResticPrune: doResticPrune, - ResticTags: resticTags, - }, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, mysqldump.Kind, extaResticFlags, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/pgdump.go b/cmd/pgdump.go index d6dc41e..8482704 100644 --- a/cmd/pgdump.go +++ b/cmd/pgdump.go @@ -19,13 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, pgdump.Kind, source.ExtraResticFlags{ - ResticCheck: doResticCheck, - ResticList: listResticSnapshots, - ResticRebuild: rebuildResticIndex, - ResticPrune: doResticPrune, - ResticTags: resticTags, - }, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, pgdump.Kind, extaResticFlags, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/redisdump.go b/cmd/redisdump.go index dd3582a..aef3a03 100644 --- a/cmd/redisdump.go +++ b/cmd/redisdump.go @@ -19,13 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, redisdump.Kind, source.ExtraResticFlags{ - ResticCheck: doResticCheck, - ResticList: listResticSnapshots, - ResticRebuild: rebuildResticIndex, - ResticPrune: doResticPrune, - ResticTags: resticTags, - }, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, redisdump.Kind, extaResticFlags, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/cmd/root.go b/cmd/root.go index 61e9d3d..2677dbd 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,15 +15,11 @@ import ( var ( // Used for flags. - cfgFiles []string - useRestic bool - useResticForget bool - cleanup bool - listResticSnapshots bool - doResticCheck bool - doResticPrune bool - rebuildResticIndex bool - resticTags bool + cfgFiles []string + useRestic bool + useResticForget bool + cleanup bool + extaResticFlags config.ExtraResticFlags rootCmd = &cobra.Command{ Use: "brudi", @@ -42,15 +38,20 @@ func init() { rootCmd.PersistentFlags().BoolVar(&cleanup, "cleanup", false, "cleanup backup files afterwards") - rootCmd.PersistentFlags().BoolVar(&listResticSnapshots, "restic-snapshots", false, "list snapshots in restic repository afterwards") + rootCmd.PersistentFlags().BoolVar(&extaResticFlags.ResticList, "restic-snapshots", false, + "list snapshots in restic repository afterwards") - rootCmd.PersistentFlags().BoolVar(&doResticCheck, "restic-check", false, "perform 'restic check' on the repository") + rootCmd.PersistentFlags().BoolVar(&extaResticFlags.ResticCheck, "restic-check", false, + "perform 'restic check' on the repository") - rootCmd.PersistentFlags().BoolVar(&doResticPrune, "restic-prune", false, "perform 'restic prune' on the repository") + rootCmd.PersistentFlags().BoolVar(&extaResticFlags.ResticPrune, "restic-prune", false, + "perform 'restic prune' on the repository") - rootCmd.PersistentFlags().BoolVar(&rebuildResticIndex, "restic-rebuild-index", false, "perform 'restic rebuild-index' on the repository") + rootCmd.PersistentFlags().BoolVar(&extaResticFlags.ResticRebuild, "restic-rebuild-index", false, + "perform 'restic rebuild-index' on the repository") - rootCmd.PersistentFlags().BoolVar(&resticTags, "restic-tags", false, "executes 'restic tags' after backing up things with restic") + rootCmd.PersistentFlags().BoolVar(&extaResticFlags.ResticTags, "restic-tags", false, + "executes 'restic tags' after backing up things with restic") rootCmd.PersistentFlags().StringSliceVarP(&cfgFiles, "config", "c", []string{}, "config file (default is ${HOME}/.brudi.yaml)") } diff --git a/cmd/tar.go b/cmd/tar.go index 766ebaf..1f1df9f 100644 --- a/cmd/tar.go +++ b/cmd/tar.go @@ -19,13 +19,7 @@ var ( ctx, cancel := context.WithCancel(context.Background()) defer cancel() - err := source.DoBackupForKind(ctx, tar.Kind, source.ExtraResticFlags{ - ResticCheck: doResticCheck, - ResticList: listResticSnapshots, - ResticRebuild: rebuildResticIndex, - ResticPrune: doResticPrune, - ResticTags: resticTags, - }, cleanup, useRestic, useResticForget) + err := source.DoBackupForKind(ctx, tar.Kind, extaResticFlags, cleanup, useRestic, useResticForget) if err != nil { panic(err) } diff --git a/pkg/config/types.go b/pkg/config/types.go index 7b76045..bfa8aad 100644 --- a/pkg/config/types.go +++ b/pkg/config/types.go @@ -4,3 +4,11 @@ const ( KeyOptionsFlags = "options.flags" KeyOptionsAdditionalArgs = "options.additionalArgs" ) + +type ExtraResticFlags struct { + ResticList bool + ResticCheck bool + ResticPrune bool + ResticRebuild bool + ResticTags bool +} diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 0debbc1..ae03e4c 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -3,6 +3,7 @@ package restic import ( "context" "fmt" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" ) @@ -113,12 +114,12 @@ func (c *Client) DoResticListSnapshots(ctx context.Context) error { output, err := ListSnapshots(ctx, c.Config.Global, c.Config.Snapshots) if err != nil { - return errors.WithStack(fmt.Errorf("%s - %s", err.Error(), output)) + return errors.WithStack(err) } fmt.Println("output of 'restic snapshots':") for index := range output { - fmt.Println(fmt.Sprintf("ID: %s; Time: %s; Host: %s; Tags: %s; Paths: %s", - output[index].ID, output[index].Time, output[index].Hostname, output[index].Tags, output[index].Paths)) + fmt.Printf("ID: %d; Time: %s; Host: %s; Tags: %s; Paths: %s\n", + output[index].ID, output[index].Time, output[index].Hostname, output[index].Tags, output[index].Paths) } return nil } diff --git a/pkg/source/backup.go b/pkg/source/backup.go index 4fc3cc0..4ec529f 100644 --- a/pkg/source/backup.go +++ b/pkg/source/backup.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "github.com/mittwald/brudi/pkg/config" + "github.com/mittwald/brudi/pkg/restic" "github.com/mittwald/brudi/pkg/source/pgdump" @@ -36,7 +38,8 @@ func getGenericBackendForKind(kind string) (Generic, error) { // DoBackupForKind performs the appropriate backup action for given arguments. // It also executes any given restic commands after files have been backed up, -func DoBackupForKind(ctx context.Context, kind string, resticFlags ExtraResticFlags, cleanup, useRestic, useResticForget bool) error { +func DoBackupForKind(ctx context.Context, kind string, resticFlags config.ExtraResticFlags, + cleanup, useRestic, useResticForget bool) error { logKind := log.WithFields( log.Fields{ "kind": kind, @@ -128,5 +131,4 @@ func DoBackupForKind(ctx context.Context, kind string, resticFlags ExtraResticFl } return resticClient.DoResticCheck(ctx) - } diff --git a/pkg/source/types.go b/pkg/source/types.go index 6404db4..c8d2377 100644 --- a/pkg/source/types.go +++ b/pkg/source/types.go @@ -4,14 +4,6 @@ import ( "context" ) -type ExtraResticFlags struct { - ResticList bool - ResticCheck bool - ResticPrune bool - ResticRebuild bool - ResticTags bool -} - type Generic interface { CreateBackup(ctx context.Context) error GetBackupPath() string diff --git a/test/pkg/source/internal/testcommons.go b/test/pkg/source/internal/testcommons.go index 2f9983e..7f222fe 100644 --- a/test/pkg/source/internal/testcommons.go +++ b/test/pkg/source/internal/testcommons.go @@ -3,14 +3,15 @@ package internal import ( "context" "fmt" - "github.com/mittwald/brudi/pkg/source" - "github.com/pkg/errors" - "github.com/spf13/viper" "os" "os/exec" "strings" + "github.com/mittwald/brudi/pkg/config" + "github.com/docker/go-connections/nat" + "github.com/pkg/errors" + "github.com/spf13/viper" "github.com/testcontainers/testcontainers-go" ) @@ -34,7 +35,7 @@ var ResticReq = testcontainers.ContainerRequest{ }, } -var ExtraFlags = source.ExtraResticFlags{ +var ExtraFlags = config.ExtraResticFlags{ ResticCheck: false, ResticRebuild: false, ResticTags: false, From 8c00c6718fab2c412bc14f6e0d969252cea8d306 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Tue, 12 Jan 2021 14:31:46 +0100 Subject: [PATCH 12/13] documentation --- pkg/restic/client.go | 2 ++ pkg/restic/commands.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/restic/client.go b/pkg/restic/client.go index ae03e4c..8a34dde 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -84,6 +84,7 @@ func (c *Client) DoResticBackup(ctx context.Context) error { return nil } +// DoResticRestore exectutes RestoreBackup with the settings from c func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { c.Logger.Info("running 'restic restore'") _, err := RestoreBackup(ctx, c.Config.Global, c.Config.Restore, false) @@ -93,6 +94,7 @@ func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { return nil } +// DoResticForget excecutes Forget with the settings of c func (c *Client) DoResticForget(ctx context.Context) error { c.Logger.Info("running 'restic forget'") diff --git a/pkg/restic/commands.go b/pkg/restic/commands.go index cf50b9b..a592626 100644 --- a/pkg/restic/commands.go +++ b/pkg/restic/commands.go @@ -25,7 +25,7 @@ var ( cmdTimeout = 6 * time.Hour ) -// InitBackup executes "restic init" +// initBackup executes "restic init" func initBackup(ctx context.Context, globalOpts *GlobalOptions) ([]byte, error) { cmd := newCommand("init", cli.StructToCLI(globalOpts)...) From 1bafbb86aba689c69bf144c3f03caf42eef8a325 Mon Sep 17 00:00:00 2001 From: Yannik Bramkamp Date: Wed, 13 Jan 2021 09:26:57 +0100 Subject: [PATCH 13/13] linting --- pkg/restic/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/restic/client.go b/pkg/restic/client.go index 8a34dde..126c84f 100644 --- a/pkg/restic/client.go +++ b/pkg/restic/client.go @@ -84,7 +84,7 @@ func (c *Client) DoResticBackup(ctx context.Context) error { return nil } -// DoResticRestore exectutes RestoreBackup with the settings from c +// DoResticRestore executes RestoreBackup with the settings from c func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { c.Logger.Info("running 'restic restore'") _, err := RestoreBackup(ctx, c.Config.Global, c.Config.Restore, false) @@ -94,7 +94,7 @@ func (c *Client) DoResticRestore(ctx context.Context, backupPath string) error { return nil } -// DoResticForget excecutes Forget with the settings of c +// DoResticForget executes Forget with the settings of c func (c *Client) DoResticForget(ctx context.Context) error { c.Logger.Info("running 'restic forget'")