From da60175fcc920531209b9ce227793fb1a698d948 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Sat, 14 Oct 2023 15:24:49 +0200 Subject: [PATCH] cron --- Readme.md | 9 +++++++++ main.go | 27 +++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index 424caed..c2fe657 100644 --- a/Readme.md +++ b/Readme.md @@ -144,6 +144,15 @@ The job argument is optional and can be used to show just the plan of on job bas ### Cron run +Execute the deletion, **without** ask before deleting the files + +``` +idun execute -job abc2 -cron +``` + +The job argument is optional and can be used to show just the plan of on job based on the "name" in the config. + + ## FAQ ### Why minimum Hour/Day/Month If you configure to keep one backup per hour for 12 hours Idun will make sure there will be hourly backups for at least 12 hours. But based on the rules of the next Buckets, which is per Day from 00:00:00 UTC to 23:59:59 UTC there may be a gap between the end hour of the "Hourly Bucket" and the beginn of the "Daily Bucket", in this case Iduna will not delete the Backup files. So ther will be up to 35 Hours Hourly Backups. diff --git a/main.go b/main.go index 1cd0148..0cb26ab 100644 --- a/main.go +++ b/main.go @@ -172,6 +172,11 @@ func main() { Value: "config.yml", Usage: "path to config", }, + &cli.BoolFlag{ + Name: "cron", + Value: false, + Usage: "Run as cron, dont ask for yes", + }, }, Action: func(cCtx *cli.Context) error { configPath := cCtx.String("path") @@ -238,13 +243,23 @@ func main() { } } - fmt.Println("Write \"yes\" to execute") - reader := bufio.NewReader(os.Stdin) - text, _ := reader.ReadString('\n') - // convert CRLF to LF - text = strings.Replace(text, "\n", "", -1) + cron := cCtx.Bool("cron") - if text == "yes" { + if !cron { + fmt.Println("Write \"yes\" to execute") + reader := bufio.NewReader(os.Stdin) + text, _ := reader.ReadString('\n') + // convert CRLF to LF + text = strings.Replace(text, "\n", "", -1) + + if text == "yes" { + err = jobStorage.Delete(allFilesToDeleted) + if err != nil { + log.Fatal().Err(err).Msg("cant delete files from storage") + return err + } + } + } else { err = jobStorage.Delete(allFilesToDeleted) if err != nil { log.Fatal().Err(err).Msg("cant delete files from storage")