package main import ( "flag" "log" "os" ) var ( appFlag = flag.String("app", "", "run specific app") cfgFile = flag.String("config", "config.json", "config file") schedFlag = flag.String("schedule", "", "specific schedule") slowFlag = flag.Bool("slow", false, "slow process") testFlag = flag.Bool("test", false, "test run") debugFlag = flag.Bool("debug", false, "debug") cfg Config ) func main() { flag.Parse() err := cfg.Load() if err != nil { log.Printf("Cannot load config (%s)", err) os.Exit(1) } err = RunBackup(*appFlag) if err != nil { log.Printf("Cannot run schedule (%s)", err) os.Exit(1) } } //RunBackup run all backup targets where schedule is registered 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 nil }