pass backup duration
This commit is contained in:
@@ -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
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user