diff --git a/backup.go b/backup.go index dd87e83..58b8bd1 100644 --- a/backup.go +++ b/backup.go @@ -9,14 +9,15 @@ 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") - 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") + cfg Config + email *Email ) func main() { @@ -34,6 +35,11 @@ func main() { os.Exit(1) } + if *testMailFlag { + SendMail(cfg.Email.smtpHost, cfg.Email.fromEmail, "test backup email topic", "test backup email body", cfg.Email.toEmail) + os.Exit(0) + } + err = RunBackup(*appFlag) if err != nil { log.Printf("Cannot run schedule (%s)", err) diff --git a/email.go b/email.go index d097bbb..8259953 100644 --- a/email.go +++ b/email.go @@ -2,6 +2,7 @@ package main import ( "encoding/base64" + "log" "net/smtp" "strings" "time" @@ -48,6 +49,10 @@ func SendMail(addr, from, subject, body string, to []string) error { "Content-Transfer-Encoding: base64\r\n" + "\r\n" + base64.StdEncoding.EncodeToString([]byte(body)) + if *debugFlag { + log.Printf("SendMail :\r\n%s", msg) + } + _, err = w.Write([]byte(msg)) if err != nil { return err diff --git a/version.go b/version.go index 3481b5b..3be5cbc 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "7c309b8" -var buildstamp = "2022-06-19_03:58:59" -var commits = "42" -var version = "7c309b8-b42 - 2022-06-19_03:58:59" +var githash = "86ddd52" +var buildstamp = "2022-06-19_04:11:44" +var commits = "43" +var version = "86ddd52-b43 - 2022-06-19_04:11:44"