From 29d37e0dc14d3fe694a2f2dc0d9ad9c29752ac81 Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 18 Oct 2021 22:20:44 +0800 Subject: [PATCH] specific app --- app.go | 2 +- backup.go | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/app.go b/app.go index ff96e51..e9ae3ab 100644 --- a/app.go +++ b/app.go @@ -586,7 +586,7 @@ func (a AppConfig) SendSnapshots() error { func (a AppConfig) CleanupSnapshot() error { if *debugFlag { - log.Printf("AppConfig.CleanupSnapshot : %s : Start]", a.Name) + log.Printf("AppConfig.CleanupSnapshot : %s : Start", a.Name) } cleanupSnapshot := make(map[string]string) diff --git a/backup.go b/backup.go index 7ae903a..bfbc785 100644 --- a/backup.go +++ b/backup.go @@ -28,6 +28,7 @@ type BoxConfig struct { } var ( + appFlag = flag.String("app", "", "run specific app") cfgFile = flag.String("config", "config.json", "config file") schedFlag = flag.String("schedule", "", "specific schedule") testFlag = flag.Bool("test", false, "test run") @@ -203,7 +204,7 @@ func main() { os.Exit(1) } - err = RunBackup() + err = RunBackup(*appFlag) if err != nil { log.Printf("Cannot run schedule (%s)", err) os.Exit(1) @@ -211,18 +212,34 @@ func main() { } //RunBackup run all backup targets where schedule is registered -func RunBackup() error { - if *debugFlag { - log.Printf("RunBackup() : Start") - } - - for _, app := range cfg.Apps { - err := app.RunAppBackup() - if err != nil { - if *debugFlag { - log.Printf("RunBackup() : Error running %s", app.Name) +func RunBackup(app string) error { + if app == "" { + if *debugFlag { + log.Printf("RunBackup() : Start") + } + for _, a := range cfg.Apps { + err := a.RunAppBackup() + if err != nil { + if *debugFlag { + log.Printf("RunBackup() : Error running %s", a.Name) + } + return err + } + } + } else { + if *debugFlag { + log.Printf("RunBackup() : Start %s", app) + } + for _, a := range cfg.Apps { + if a.Name == app { + err := a.RunAppBackup() + if err != nil { + if *debugFlag { + log.Printf("RunBackup() : Error running %s", a.Name) + } + return err + } } - return err } }