1
0
mirror of https://github.com/offen/docker-volume-backup.git synced 2025-11-29 05:46:50 +02:00

Add optional jittering before any backup actions (#654)

* NEW: Add optional jittering before backing up

* Removed deprecated rand seeding

* Updated BACKUP_JITTER config option doc

* Moved jittering logic from script init to runScript

* Changed formatting of jittering log message
This commit is contained in:
Esteban Thilliez
2025-10-17 08:37:14 +02:00
committed by GitHub
parent bebe3484c7
commit f76d4fd814
3 changed files with 23 additions and 0 deletions

View File

@@ -37,6 +37,7 @@ type Config struct {
BackupLatestSymlink string `split_words:"true"`
BackupArchive string `split_words:"true" default:"/archive"`
BackupCronExpression string `split_words:"true" default:"@daily"`
BackupJitter time.Duration `split_words:"true" default:"0s"`
BackupRetentionDays int32 `split_words:"true" default:"-1"`
BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
BackupPruningPrefix string `split_words:"true"`

View File

@@ -6,7 +6,9 @@ package main
import (
"errors"
"fmt"
"math/rand"
"runtime/debug"
"time"
"github.com/offen/docker-volume-backup/internal/errwrap"
)
@@ -51,6 +53,15 @@ func runScript(c *Config) (err error) {
}
}()
if s.c != nil && s.c.BackupJitter > 0 {
max := s.c.BackupJitter
delay := time.Duration(rand.Int63n(int64(max) + 1))
if delay > 0 {
s.logger.Info(fmt.Sprintf("Applying startup jitter of %v", delay))
time.Sleep(delay)
}
}
if initErr := s.init(); initErr != nil {
err = errwrap.Wrap(initErr, "error instantiating script")
return