-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
43 lines (34 loc) · 946 Bytes
/
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
package main
import (
"time"
log "github.com/sirupsen/logrus"
"github.com/go-co-op/gocron"
"github.com/hibare/GoPG2S3Dump/internal/config"
"github.com/hibare/GoPG2S3Dump/internal/notifiers"
"github.com/hibare/GoPG2S3Dump/internal/pgdump"
)
func main() {
config.LoadConfig()
config.InitConfig()
s := gocron.NewScheduler(time.UTC)
// Schedule backup job
if _, err := s.Cron(config.Current.Backup.Cron).Do(func() {
databases, key, err := pgdump.Dump()
if err != nil {
log.Errorf("Error backingup databases %s", err)
notifiers.NotifyBackupFailure(err)
return
}
notifiers.NotifyBackupSuccess(databases, key)
err = pgdump.PurgeDumps()
if err != nil {
log.Errorf("Error purging dumps %s", err)
notifiers.NotifyBackupDeleteFailure(err)
return
}
}); err != nil {
log.Fatalf("Error cron: %v", err)
}
log.Infof("Scheduled backup job to run every %s", config.Current.Backup.Cron)
s.StartBlocking()
}