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 (
|
var (
|
||||||
appFlag = flag.String("app", "", "run specific app")
|
appFlag = flag.String("app", "", "run specific app")
|
||||||
cfgFile = flag.String("config", "config.json", "config file")
|
cfgFile = flag.String("config", "config.json", "config file")
|
||||||
schedFlag = flag.String("schedule", "", "specific schedule")
|
schedFlag = flag.String("schedule", "", "specific schedule")
|
||||||
slowFlag = flag.Bool("slow", false, "slow process")
|
slowFlag = flag.Bool("slow", false, "slow process")
|
||||||
testFlag = flag.Bool("test", false, "test run")
|
testFlag = flag.Bool("test", false, "test run")
|
||||||
debugFlag = flag.Bool("debug", false, "debug")
|
debugFlag = flag.Bool("debug", false, "debug")
|
||||||
testMailFlag = flag.Bool("test-mail", false, "test email setup")
|
testMailFlag = flag.Bool("test-mail", false, "test email setup")
|
||||||
cfg Config
|
stopOnErrorFlag = flag.Bool("stop-on-error", false, "stop processing on error")
|
||||||
email *Email
|
cfg Config
|
||||||
|
email *Email
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -40,20 +41,24 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = RunBackup(*appFlag)
|
err = RunBackup(*appFlag, *stopOnErrorFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Cannot run schedule (%s)", err)
|
log.Printf("Cannot run schedule (%s)", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(email.items) > 0 {
|
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)
|
log.Printf("Sending summary email\r\n%v", email.items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//RunBackup run all backup targets where schedule is registered
|
//RunBackup run all backup targets where schedule is registered
|
||||||
func RunBackup(app string) error {
|
func RunBackup(app string, stopOnError bool) error {
|
||||||
if app == "" {
|
if app == "" {
|
||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("RunBackup() : Start")
|
log.Printf("RunBackup() : Start")
|
||||||
@ -64,7 +69,9 @@ func RunBackup(app string) error {
|
|||||||
if *debugFlag {
|
if *debugFlag {
|
||||||
log.Printf("RunBackup() : Error running %s", a.Name)
|
log.Printf("RunBackup() : Error running %s", a.Name)
|
||||||
}
|
}
|
||||||
return err
|
if stopOnError {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
3
email.go
3
email.go
@ -60,7 +60,8 @@ func SendMail(addr, from, subject, body string, to []string) error {
|
|||||||
return err
|
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" +
|
"From: " + from + "\r\n" +
|
||||||
"Subject: " + subject + "\r\n" +
|
"Subject: " + subject + "\r\n" +
|
||||||
"Content-Type: text/html; charset=\"UTF-8\"\r\n" +
|
"Content-Type: text/html; charset=\"UTF-8\"\r\n" +
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||||
package main
|
package main
|
||||||
var githash = "8a6fced"
|
var githash = "f36e7da"
|
||||||
var buildstamp = "2022-09-07_14:20:27"
|
var buildstamp = "2022-10-08_02:49:05"
|
||||||
var commits = "51"
|
var commits = "52"
|
||||||
var version = "8a6fced-b51 - 2022-09-07_14:20:27"
|
var version = "f36e7da-b52 - 2022-10-08_02:49:05"
|
||||||
|
Loading…
Reference in New Issue
Block a user