backup/backup.go

64 lines
1.1 KiB
Go
Raw Normal View History

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"
2022-06-17 14:54:14 +02:00
"time"
2023-06-29 22:58:24 +02:00
log "github.com/sirupsen/logrus"
2021-10-11 03:43:05 +02:00
)
var (
2023-06-29 22:58:24 +02:00
cfgFile = flag.String("config", "config.json", "config file")
isDaemon = flag.Bool("daemon", false, "run as daemon")
debug = flag.Bool("debug", false, "log debug messages")
logFile = flag.String("logfile", "", "log file")
cfg Config
email *Email
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)
}
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)
2022-06-17 14:54:14 +02:00
email = new(Email)
email.startTime = time.Now()
2022-06-19 05:59:17 +02:00
email.items = make([]string, 0)
2022-06-17 14:54:14 +02:00
2023-06-29 22:58:24 +02:00
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 {
cfg.Start(nil)
server := NewServer(cfg.Admin.Addr, cfg.Admin.Username, cfg.Admin.Password)
server.Run()
} else {
e := NewEmail(time.Now())
cfg.Start(e)
defer cfg.Stop(e)
2022-06-17 14:54:14 +02:00
2023-06-29 22:58:24 +02:00
cfg.Run(e)
2021-10-11 03:43:05 +02:00
2023-06-29 22:58:24 +02:00
os.Exit(0)
2021-10-11 03:43:05 +02:00
}
}