pass backup duration

This commit is contained in:
Umputun
2018-01-01 02:15:59 -06:00
parent ce1a897555
commit 44c84626e6
3 changed files with 15 additions and 12 deletions
+2
View File
@@ -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()
}
+13 -4
View File
@@ -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))
}
}
-8
View File
@@ -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
}