You've already forked docker-volume-backup
mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-11-23 21:44:40 +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:
@@ -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