You've already forked docker-volume-backup
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:
@@ -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"`
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user