lean flag

This commit is contained in:
cupcakearmy 2021-04-28 10:54:07 +02:00
parent b8d12e518c
commit c1795b2acc
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
4 changed files with 22 additions and 7 deletions

View File

@ -11,6 +11,7 @@ var cronCmd = &cobra.Command{
Short: "Run cron job for automated backups", 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.`, 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) { Run: func(cmd *cobra.Command, args []string) {
internal.CRON_LEAN, _ = cmd.Flags().GetBool("lean")
err := lock.Lock() err := lock.Lock()
CheckErr(err) CheckErr(err)
defer lock.Unlock() defer lock.Unlock()
@ -22,4 +23,5 @@ var cronCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(cronCmd) rootCmd.AddCommand(cronCmd)
cronCmd.Flags().Bool("lean", false, "only output information about actual backups")
} }

View File

@ -1,11 +1,13 @@
# Cron # Cron
```bash ```bash
autorestic cron autorestic cron [--lean]
``` ```
This command is mostly intended to be triggered by an automated system like systemd or crontab. 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. 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 > :ToCPrevNext

View File

@ -12,10 +12,11 @@ import (
"github.com/spf13/viper" "github.com/spf13/viper"
) )
const VERSION = "1.0.7" const VERSION = "1.0.8"
var CI bool = false var CI bool = false
var VERBOSE bool = false var VERBOSE bool = false
var CRON_LEAN bool = false
type Config struct { type Config struct {
Locations map[string]Location `yaml:"locations"` Locations map[string]Location `yaml:"locations"`
@ -29,7 +30,9 @@ func GetConfig() *Config {
if config == nil { if config == nil {
once.Do(func() { once.Do(func() {
if err := viper.ReadInConfig(); err == nil { if err := viper.ReadInConfig(); err == nil {
if !CRON_LEAN {
colors.Faint.Println("Using config file:", viper.ConfigFileUsed()) colors.Faint.Println("Using config file:", viper.ConfigFileUsed())
}
} else { } else {
return return
} }
@ -190,11 +193,17 @@ func GetAllOrSelected(cmd *cobra.Command, backends bool) ([]string, error) {
} }
func AddFlagsToCommand(cmd *cobra.Command, backend bool) { func AddFlagsToCommand(cmd *cobra.Command, backend bool) {
cmd.PersistentFlags().BoolP("all", "a", false, "Backup all locations") var usage string
if backend { if backend {
cmd.PersistentFlags().StringSliceP("backend", "b", []string{}, "backends") usage = "all backends"
} else { } else {
cmd.PersistentFlags().StringSliceP("location", "l", []string{}, "Locations") usage = "all locations"
}
cmd.PersistentFlags().BoolP("all", "a", false, usage)
if backend {
cmd.PersistentFlags().StringSliceP("backend", "b", []string{}, "select backends")
} else {
cmd.PersistentFlags().StringSliceP("location", "l", []string{}, "select locations")
} }
} }

View File

@ -309,7 +309,9 @@ func (l Location) RunCron() error {
lock.SetCron(l.name, now.Unix()) lock.SetCron(l.name, now.Unix())
l.Backup(true) l.Backup(true)
} else { } else {
if !CRON_LEAN {
colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name) colors.Body.Printf("Skipping \"%s\", not due yet.\n", l.name)
} }
}
return nil return nil
} }