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
|
|
|
"os"
|
2023-06-29 22:58:24 +02:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-10-11 03:43:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-07-31 20:47:24 +02:00
|
|
|
cfgFile = flag.String("config", "backup.json", "config file")
|
2023-06-29 22:58:24 +02:00
|
|
|
isDaemon = flag.Bool("daemon", false, "run as daemon")
|
|
|
|
debug = flag.Bool("debug", false, "log debug messages")
|
2023-06-29 23:46:53 +02:00
|
|
|
quiet = flag.Bool("quiet", false, "remove most log messages")
|
2023-06-29 22:58:24 +02:00
|
|
|
logFile = flag.String("logfile", "", "log file")
|
|
|
|
cfg Config
|
2021-10-11 03:43:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
|
2021-11-14 05:23:53 +01:00
|
|
|
fmt.Printf("backup (%s)\n", version)
|
|
|
|
|
2023-06-29 22:58:24 +02:00
|
|
|
if *debug {
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
2023-06-29 23:46:53 +02:00
|
|
|
if *quiet {
|
|
|
|
log.SetLevel(log.WarnLevel)
|
|
|
|
}
|
2023-06-29 22:58:24 +02:00
|
|
|
if *logFile != "" {
|
|
|
|
if f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644); err != nil {
|
|
|
|
log.Printf("Cannot open logfile (%s)", err)
|
|
|
|
} else {
|
|
|
|
log.SetOutput(f)
|
|
|
|
defer f.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
log.SetReportCaller(true)
|
|
|
|
|
|
|
|
if err := cfg.LoadFile(*cfgFile); err != nil {
|
2021-10-11 03:43:05 +02:00
|
|
|
log.Printf("Cannot load config (%s)", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2023-06-29 22:58:24 +02:00
|
|
|
if *isDaemon {
|
2023-07-31 18:11:29 +02:00
|
|
|
if cfg.Admin == nil {
|
|
|
|
cfg.Admin = NewAdmin()
|
2023-07-31 10:13:36 +02:00
|
|
|
}
|
2023-07-31 18:11:29 +02:00
|
|
|
cfg.Admin.Run()
|
|
|
|
} else {
|
|
|
|
cfg.Run()
|
2023-06-29 22:58:24 +02:00
|
|
|
os.Exit(0)
|
2021-10-11 03:43:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|