update email and stop on error
This commit is contained in:
parent
f36e7da824
commit
a7ee0bfeb7
33
backup.go
33
backup.go
@ -9,15 +9,16 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
appFlag = flag.String("app", "", "run specific app")
|
||||
cfgFile = flag.String("config", "config.json", "config file")
|
||||
schedFlag = flag.String("schedule", "", "specific schedule")
|
||||
slowFlag = flag.Bool("slow", false, "slow process")
|
||||
testFlag = flag.Bool("test", false, "test run")
|
||||
debugFlag = flag.Bool("debug", false, "debug")
|
||||
testMailFlag = flag.Bool("test-mail", false, "test email setup")
|
||||
cfg Config
|
||||
email *Email
|
||||
appFlag = flag.String("app", "", "run specific app")
|
||||
cfgFile = flag.String("config", "config.json", "config file")
|
||||
schedFlag = flag.String("schedule", "", "specific schedule")
|
||||
slowFlag = flag.Bool("slow", false, "slow process")
|
||||
testFlag = flag.Bool("test", false, "test run")
|
||||
debugFlag = flag.Bool("debug", false, "debug")
|
||||
testMailFlag = flag.Bool("test-mail", false, "test email setup")
|
||||
stopOnErrorFlag = flag.Bool("stop-on-error", false, "stop processing on error")
|
||||
cfg Config
|
||||
email *Email
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -40,20 +41,24 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
err = RunBackup(*appFlag)
|
||||
err = RunBackup(*appFlag, *stopOnErrorFlag)
|
||||
if err != nil {
|
||||
log.Printf("Cannot run schedule (%s)", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if len(email.items) > 0 {
|
||||
SendMail(cfg.Email.SmtpHost, cfg.Email.FromEmail, "Autobackup report", fmt.Sprintf("%v", email.items), cfg.Email.ToEmail)
|
||||
body := " - " + email.items[0]
|
||||
for _, v := range email.items[1:] {
|
||||
body = body + "\r\n" + " - " + v
|
||||
}
|
||||
SendMail(cfg.Email.SmtpHost, cfg.Email.FromEmail, "Autobackup report", body, cfg.Email.ToEmail)
|
||||
log.Printf("Sending summary email\r\n%v", email.items)
|
||||
}
|
||||
}
|
||||
|
||||
//RunBackup run all backup targets where schedule is registered
|
||||
func RunBackup(app string) error {
|
||||
func RunBackup(app string, stopOnError bool) error {
|
||||
if app == "" {
|
||||
if *debugFlag {
|
||||
log.Printf("RunBackup() : Start")
|
||||
@ -64,7 +69,9 @@ func RunBackup(app string) error {
|
||||
if *debugFlag {
|
||||
log.Printf("RunBackup() : Error running %s", a.Name)
|
||||
}
|
||||
return err
|
||||
if stopOnError {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
3
email.go
3
email.go
@ -60,7 +60,8 @@ func SendMail(addr, from, subject, body string, to []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
msg := "To: " + strings.Join(to, ",") + "\r\n" +
|
||||
msg := "Date:" + time.Now().Format("Mon, 02 Jan 2006 15:04:05 -0700") + "\r\n" +
|
||||
"To: " + strings.Join(to, ",") + "\r\n" +
|
||||
"From: " + from + "\r\n" +
|
||||
"Subject: " + subject + "\r\n" +
|
||||
"Content-Type: text/html; charset=\"UTF-8\"\r\n" +
|
||||
|
@ -1,6 +1,6 @@
|
||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||
package main
|
||||
var githash = "8a6fced"
|
||||
var buildstamp = "2022-09-07_14:20:27"
|
||||
var commits = "51"
|
||||
var version = "8a6fced-b51 - 2022-09-07_14:20:27"
|
||||
var githash = "f36e7da"
|
||||
var buildstamp = "2022-10-08_02:49:05"
|
||||
var commits = "52"
|
||||
var version = "f36e7da-b52 - 2022-10-08_02:49:05"
|
||||
|
Loading…
Reference in New Issue
Block a user