From c1795b2acc6995517155f4afe87622fda7aa6aab Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Wed, 28 Apr 2021 10:54:07 +0200 Subject: [PATCH] lean flag --- cmd/cron.go | 2 ++ docs/markdown/cli/cron.md | 4 +++- internal/config.go | 19 ++++++++++++++----- internal/location.go | 4 +++- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/cron.go b/cmd/cron.go index b25bfcf..2f80bf7 100644 --- a/cmd/cron.go +++ b/cmd/cron.go @@ -11,6 +11,7 @@ var cronCmd = &cobra.Command{ Short: "Run cron job for automated backups", Long: `Intended to be mainly triggered by an automated system like systemd or crontab. For each location checks if a cron backup is due and runs it.`, Run: func(cmd *cobra.Command, args []string) { + internal.CRON_LEAN, _ = cmd.Flags().GetBool("lean") err := lock.Lock() CheckErr(err) defer lock.Unlock() @@ -22,4 +23,5 @@ var cronCmd = &cobra.Command{ func init() { rootCmd.AddCommand(cronCmd) + cronCmd.Flags().Bool("lean", false, "only output information about actual backups") } diff --git a/docs/markdown/cli/cron.md b/docs/markdown/cli/cron.md index c14af6e..505b9a8 100644 --- a/docs/markdown/cli/cron.md +++ b/docs/markdown/cli/cron.md @@ -1,11 +1,13 @@ # Cron ```bash -autorestic cron +autorestic cron [--lean] ``` This command is mostly intended to be triggered by an automated system like systemd or crontab. It will run cron jobs as [specified in the cron section](/location/cron) of a specific location. +The `--lean` flag will omit output like _skipping location x: not due yet_. This can be useful if you are dumping the output of the cron job to a log file and don't want to be overwhelmed by the output log. + > :ToCPrevNext diff --git a/internal/config.go b/internal/config.go index c510da0..dbd99e0 100644 --- a/internal/config.go +++ b/internal/config.go @@ -12,10 +12,11 @@ import ( "github.com/spf13/viper" ) -const VERSION = "1.0.7" +const VERSION = "1.0.8" var CI bool = false var VERBOSE bool = false +var CRON_LEAN bool = false type Config struct { Locations map[string]Location `yaml:"locations"` @@ -29,7 +30,9 @@ func GetConfig() *Config { if config == nil { once.Do(func() { if err := viper.ReadInConfig(); err == nil { - colors.Faint.Println("Using config file:", viper.ConfigFileUsed()) + if !CRON_LEAN { + colors.Faint.Println("Using config file:", viper.ConfigFileUsed()) + } } else { return } @@ -190,11 +193,17 @@ func GetAllOrSelected(cmd *cobra.Command, backends bool) ([]string, error) { } func AddFlagsToCommand(cmd *cobra.Command, backend bool) { - cmd.PersistentFlags().BoolP("all", "a", false, "Backup all locations") + var usage string + if backend { + usage = "all backends" + } else { + usage = "all locations" + } + cmd.PersistentFlags().BoolP("all", "a", false, usage) if backend { - cmd.PersistentFlags().StringSliceP("backend", "b", []string{}, "backends") + cmd.PersistentFlags().StringSliceP("backend", "b", []string{}, "select backends") } else { - cmd.PersistentFlags().StringSliceP("location", "l", []string{}, "Locations") + cmd.PersistentFlags().StringSliceP("location", "l", []string{}, "select locations") } } diff --git a/internal/location.go b/internal/location.go index e4a9a60..b587969 100644 --- a/internal/location.go +++ b/internal/location.go @@ -309,7 +309,9 @@ func (l Location) RunCron() error { lock.SetCron(l.name, now.Unix()) l.Backup(true) } else { - colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) + if !CRON_LEAN { + colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) + } } return nil }