59 lines
1.0 KiB
Go
59 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
cfgFile = flag.String("config", "config.json", "config file")
|
|
isDaemon = flag.Bool("daemon", false, "run as daemon")
|
|
debug = flag.Bool("debug", false, "log debug messages")
|
|
quiet = flag.Bool("quiet", false, "remove most log messages")
|
|
logFile = flag.String("logfile", "", "log file")
|
|
cfg Config
|
|
email *Email
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
fmt.Printf("backup (%s)\n", version)
|
|
|
|
if *debug {
|
|
log.SetLevel(log.DebugLevel)
|
|
}
|
|
if *quiet {
|
|
log.SetLevel(log.WarnLevel)
|
|
}
|
|
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 {
|
|
log.Printf("Cannot load config (%s)", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if *isDaemon {
|
|
if cfg.Admin == nil {
|
|
cfg.Admin = NewAdmin()
|
|
}
|
|
cfg.Admin.Run()
|
|
} else {
|
|
cfg.Run()
|
|
os.Exit(0)
|
|
}
|
|
|
|
}
|