diff --git a/app/main.go b/app/main.go index 7a4857cc..be5ef7f5 100644 --- a/app/main.go +++ b/app/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "time" "github.com/gorilla/sessions" "github.com/hashicorp/logutils" @@ -120,6 +121,7 @@ func main() { BackupLocation: opts.BackupLocation, SiteID: siteID, KeepMax: opts.MaxBackupFiles, + Duration: 24 * time.Hour, }.Do() } diff --git a/app/migrator/backup.go b/app/migrator/backup.go index cd14b784..59d2226f 100644 --- a/app/migrator/backup.go +++ b/app/migrator/backup.go @@ -13,17 +13,26 @@ import ( "github.com/pkg/errors" ) +// AutoBackup struct handles daily backups params for siteID +type AutoBackup struct { + Exporter Exporter + BackupLocation string + SiteID string + KeepMax int + Duration time.Duration +} + // Do runs daily export to local files, keeps up to keepMax backups for given siteID func (ab AutoBackup) Do() { - log.Print("[INFO] activate auto-backup") - tick := time.NewTicker(24 * time.Hour) + log.Printf("[INFO] activate auto-backup for %s", ab.BackupLocation) + tick := time.NewTicker(24 * ab.Duration) for range tick.C { - _, err := ab.makeBackup() - if err != nil { + if _, err := ab.makeBackup(); err != nil { log.Printf("[WARN] auto-backup for %s failed, %s", ab.SiteID, err) continue } ab.removeOldBackupFiles() + log.Printf("[DEBUG] next backup at %s", time.Now().Add(ab.Duration)) } } diff --git a/app/migrator/migrator.go b/app/migrator/migrator.go index 605611f6..4745fbf2 100644 --- a/app/migrator/migrator.go +++ b/app/migrator/migrator.go @@ -54,11 +54,3 @@ func ImportComments(p ImportParams) error { return importer.Import(fh, p.SiteID) } - -// AutoBackup struct handles daily backups params for siteID -type AutoBackup struct { - Exporter Exporter - BackupLocation string - SiteID string - KeepMax int -}