mirror of
https://github.com/offen/docker-volume-backup.git
synced 2025-12-06 17:38:01 +01: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"`
|
BackupLatestSymlink string `split_words:"true"`
|
||||||
BackupArchive string `split_words:"true" default:"/archive"`
|
BackupArchive string `split_words:"true" default:"/archive"`
|
||||||
BackupCronExpression string `split_words:"true" default:"@daily"`
|
BackupCronExpression string `split_words:"true" default:"@daily"`
|
||||||
|
BackupJitter time.Duration `split_words:"true" default:"0s"`
|
||||||
BackupRetentionDays int32 `split_words:"true" default:"-1"`
|
BackupRetentionDays int32 `split_words:"true" default:"-1"`
|
||||||
BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
|
BackupPruningLeeway time.Duration `split_words:"true" default:"1m"`
|
||||||
BackupPruningPrefix string `split_words:"true"`
|
BackupPruningPrefix string `split_words:"true"`
|
||||||
|
|||||||
@@ -6,7 +6,9 @@ package main
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/offen/docker-volume-backup/internal/errwrap"
|
"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 {
|
if initErr := s.init(); initErr != nil {
|
||||||
err = errwrap.Wrap(initErr, "error instantiating script")
|
err = errwrap.Wrap(initErr, "error instantiating script")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -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.
|
# The compression algorithm used in conjunction with tar.
|
||||||
# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
|
# Valid options are: "gz" (Gzip), "zst" (Zstd) or "none" (tar only).
|
||||||
# Default is "gz". Note that the selection affects the file extension.
|
# Default is "gz". Note that the selection affects the file extension.
|
||||||
|
|||||||
Reference in New Issue
Block a user