3
0
mirror of https://kolaente.dev/konrad/docker-db-backup.git synced 2026-01-10 02:50:08 +01:00

feat: replace interval with a proper cron schedule

This commit is contained in:
kolaente
2021-12-30 12:57:58 +01:00
parent 7b8e1d187c
commit 9cecce4f2d
5 changed files with 20 additions and 19 deletions

View File

@@ -15,7 +15,7 @@ import (
type conf struct {
Folder string // Backup folder _with_ trailing slash
fullCurrentBackupPath string
Interval time.Duration
Schedule string
MaxBackups int
}
@@ -26,14 +26,14 @@ var (
const (
envBackupFolder = `BACKUP_FOLDER`
envInterval = `BACKUP_INTERVAL`
envSchedule = `BACKUP_SCHEDULE`
envMax = `BACKUP_MAX`
)
func init() {
config = &conf{
Folder: "/backups/",
Interval: time.Hour * 6,
Schedule: "* */6 * * * *",
MaxBackups: 12,
}
@@ -46,14 +46,9 @@ func init() {
config.Folder = folder
}
var err error
interval, has := os.LookupEnv(envInterval)
schedule, has := os.LookupEnv(envSchedule)
if has {
config.Interval, err = time.ParseDuration(interval)
if err != nil {
log.Fatalf("Invalid interval: %s\n", err)
}
config.Schedule = schedule
}
max, has := os.LookupEnv(envMax)