forked from monobilisim/pgsql-backup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (52 loc) · 1.32 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"fmt"
"monodb-backup/backup"
"monodb-backup/clog"
"monodb-backup/config"
"monodb-backup/notify"
"runtime"
"github.com/robfig/cron"
)
var Version = "dev"
func main() {
var configPath string
if runtime.GOOS == "windows" {
configPath = "C:\\ProgramData\\monodb-backup\\monodb-backup.yml"
} else {
configPath = "/etc/monodb-backup.yml"
}
printVersion := flag.Bool("version", false, "Prints version")
filePath := flag.String("config", configPath, "Path of the configuration file in YAML format")
flag.Parse()
if *printVersion {
fmt.Println("monodb-backup " + Version)
return
}
config.ParseParams(filePath)
clog.InitializeLogger()
var logger *clog.CustomLogger = &clog.Logger
if config.Parameters.Database == "mssql" {
backup.InitializeMSSQL()
}
logger.Info("monodb-backup started.")
if config.Parameters.RunEveryCron != "" {
c := cron.New()
c.AddFunc(config.Parameters.RunEveryCron, initBackup)
c.Start()
select {}
} else {
// backwards compatibility
initBackup()
}
logger.Info("monodb-backup job finished.")
// notify.SendAlarm("monodb-backup job finished.", false)
}
func initBackup() {
if config.Parameters.BackupType.Type == "minio" || config.Parameters.BackupType.Type == "s3" {
backup.InitializeS3Session()
}
backup.Backup()
notify.SendSingleEntityAlarm()
}