mirror of
https://github.com/offen/docker-volume-backup.git
synced 2026-04-23 00:45:36 +02:00
Passing a full duration as retention period is more flexible
This commit is contained in:
@@ -38,6 +38,7 @@ type Config struct {
|
||||
BackupArchive string `split_words:"true" default:"/archive"`
|
||||
BackupCronExpression string `split_words:"true" default:"@daily"`
|
||||
BackupRetentionDays int32 `split_words:"true" default:"-1"`
|
||||
BackupRetentionPeriod time.Duration `split_words:"true"`
|
||||
BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
|
||||
BackupPruningPrefix string `split_words:"true"`
|
||||
BackupStopContainerLabel string `split_words:"true"`
|
||||
|
||||
@@ -17,11 +17,18 @@ import (
|
||||
// the given configuration. In case the given configuration would delete all
|
||||
// backups, it does nothing instead and logs a warning.
|
||||
func (s *script) pruneBackups() error {
|
||||
if s.c.BackupRetentionDays < 0 {
|
||||
if s.c.BackupRetentionDays < 0 && s.c.BackupRetentionPeriod == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
deadline := time.Now().AddDate(0, 0, -int(s.c.BackupRetentionDays)).Add(s.c.BackupPruningLeeway)
|
||||
var deadline time.Time
|
||||
if s.c.BackupRetentionPeriod != 0 {
|
||||
deadline = time.Now().Add(-s.c.BackupRetentionPeriod)
|
||||
} else {
|
||||
s.logger.Warn("Using BACKUP_RETENTION_DAYS has been deprecated and will be removed in the next major version. Please use BACKUP_RETENTION_PERIOD instead.")
|
||||
deadline = time.Now().AddDate(0, 0, -int(s.c.BackupRetentionDays))
|
||||
}
|
||||
deadline = deadline.Add(s.c.BackupPruningLeeway)
|
||||
|
||||
eg := errgroup.Group{}
|
||||
for _, backend := range s.storages {
|
||||
|
||||
@@ -225,6 +225,10 @@ func (s *script) init() error {
|
||||
s.storages = append(s.storages, dropboxBackend)
|
||||
}
|
||||
|
||||
if s.c.BackupRetentionDays > 0 && s.c.BackupRetentionPeriod > 0 {
|
||||
return errwrap.Wrap(nil, "both BACKUP_RETENTION_DAYS and BACKUP_RETENTION_PERIOD were configured, which are mutually exclusive")
|
||||
}
|
||||
|
||||
if s.c.EmailNotificationRecipient != "" {
|
||||
emailURL := fmt.Sprintf(
|
||||
"smtp://%s:%s@%s:%d/?from=%s&to=%s",
|
||||
|
||||
Reference in New Issue
Block a user