File tree Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Expand file tree Collapse file tree 3 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ type Config struct {
3737 BackupLatestSymlink string `split_words:"true"`
3838 BackupArchive string `split_words:"true" default:"/archive"`
3939 BackupCronExpression string `split_words:"true" default:"@daily"`
40+ BackupJitter time.Duration `split_words:"true" default:"0s"`
4041 BackupRetentionDays int32 `split_words:"true" default:"-1"`
4142 BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
4243 BackupPruningPrefix string `split_words:"true"`
Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ package main
66import (
77 "errors"
88 "fmt"
9+ "math/rand"
910 "runtime/debug"
11+ "time"
1012
1113 "github.com/offen/docker-volume-backup/internal/errwrap"
1214)
@@ -51,6 +53,15 @@ func runScript(c *Config) (err error) {
5153 }
5254 }()
5355
56+ if s .c != nil && s .c .BackupJitter > 0 {
57+ max := s .c .BackupJitter
58+ delay := time .Duration (rand .Int63n (int64 (max ) + 1 ))
59+ if delay > 0 {
60+ s .logger .Info (fmt .Sprintf ("Applying startup jitter of %v" , delay ))
61+ time .Sleep (delay )
62+ }
63+ }
64+
5465 if initErr := s .init (); initErr != nil {
5566 err = errwrap .Wrap (initErr , "error instantiating script" )
5667 return
Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ The values for each key currently match its default.
4747
4848# ---
4949
50+ # Optional startup delay ("jitter") applied before each backup run.
51+ # The jitter introduces a random delay between 0 and the given duration,
52+ #
53+ # Set to "0s" or omit the variable to disable jitter completely.
54+ # Default = "0s". In case you need to adjust this value, supply a duration
55+ # value as per https://pkg.go.dev/time#ParseDuration to `BACKUP_JITTER`.
56+ #
57+ # BACKUP_JITTER="0s"
58+
59+ # ---
60+
5061# The compression algorithm used in conjunction with tar.
5162# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
5263# Default is "gz". Note that the selection affects the file extension.
You can’t perform that action at this time.
0 commit comments