Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/backup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
11 changes: 11 additions & 0 deletions cmd/backup/run_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ package main
import (
"errors"
"fmt"
"math/rand"
"runtime/debug"
"time"

"github.com/offen/docker-volume-backup/internal/errwrap"
)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ The values for each key currently match its default.

# ---

# Optional startup delay ("jitter") applied before each backup run.
# The jitter introduces a random delay between 0 and the given duration,
#
# Set to "0s" or omit the variable to disable jitter completely.
# Default = "0s". In case you need to adjust this value, supply a duration
# value as per https://pkg.go.dev/time#ParseDuration to `BACKUP_JITTER`.
#
# BACKUP_JITTER="0s"

# ---

# The compression algorithm used in conjunction with tar.
# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
# Default is "gz". Note that the selection affects the file extension.
Expand Down