2021-10-11 03:43:05 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2021-11-14 05:23:53 +01:00
|
|
|
"fmt"
|
2021-10-11 03:43:05 +02:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2021-10-18 16:20:44 +02:00
|
|
|
appFlag = flag.String("app", "", "run specific app")
|
2021-10-11 03:43:05 +02:00
|
|
|
cfgFile = flag.String("config", "config.json", "config file")
|
|
|
|
schedFlag = flag.String("schedule", "", "specific schedule")
|
2021-11-04 14:33:44 +01:00
|
|
|
slowFlag = flag.Bool("slow", false, "slow process")
|
2021-10-17 16:39:30 +02:00
|
|
|
testFlag = flag.Bool("test", false, "test run")
|
|
|
|
debugFlag = flag.Bool("debug", false, "debug")
|
2021-10-11 03:43:05 +02:00
|
|
|
cfg Config
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2021-11-14 05:23:53 +01:00
|
|
|
fmt.Printf("backup (%s)\n", version)
|
|
|
|
|
2021-10-11 03:43:05 +02:00
|
|
|
err := cfg.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Cannot load config (%s)", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-10-18 16:20:44 +02:00
|
|
|
err = RunBackup(*appFlag)
|
2021-10-11 03:43:05 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Cannot run schedule (%s)", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-16 15:39:54 +02:00
|
|
|
//RunBackup run all backup targets where schedule is registered
|
2021-10-18 16:20:44 +02:00
|
|
|
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
|
|
|
|
}
|
2021-10-11 03:43:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|