Skip to content

Commit

Permalink
Add ability to pass estimation type, when building SnapshotCreate c…
Browse files Browse the repository at this point in the history
…ommand (#3186)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Daniil Fedotov <[email protected]>
  • Loading branch information
3 people authored Oct 23, 2024
1 parent 81a6355 commit 793523b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 30 deletions.
66 changes: 36 additions & 30 deletions pkg/kopia/command/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,39 @@ const (
statsSubCommand = "stats"
verifySubCommand = "verify"

allFlag = "--all"
configFileFlag = "--config-file"
deleteFlag = "--delete"
deltaFlag = "--delta"
directoryIDFlag = "--directory-id"
fileIDFlag = "--file-id"
fileParallelismFlag = "--file-parallelism"
fileQueueLengthFlag = "--file-queue-length"
filterFlag = "--filter"
globalFlag = "--global"
jsonFlag = "--json"
logDirectoryFlag = "--log-dir"
logLevelFlag = "--log-level"
fileLogLevelFlag = "--file-log-level"
LogLevelError = "error"
LogLevelInfo = "info"
maxErrorsFlag = "--max-errors"
parallelFlag = "--parallel"
passwordFlag = "--password"
progressUpdateIntervalFlag = "--progress-update-interval"
rawFlag = "--raw"
showIdenticalFlag = "--show-identical"
sourcesFlag = "--sources"
tagsFlag = "--tags"
unsafeIgnoreSourceFlag = "--unsafe-ignore-source"
ownerFlag = "--owner"
sparseFlag = "--write-sparse-files"
verifyFilesPercentFlag = "--verify-files-percent"
ignorePermissionsError = "--ignore-permission-errors"
noIgnorePermissionsError = "--no-ignore-permission-errors"
allFlag = "--all"
configFileFlag = "--config-file"
deleteFlag = "--delete"
deltaFlag = "--delta"
directoryIDFlag = "--directory-id"
fileIDFlag = "--file-id"
fileParallelismFlag = "--file-parallelism"
fileQueueLengthFlag = "--file-queue-length"
filterFlag = "--filter"
globalFlag = "--global"
jsonFlag = "--json"
logDirectoryFlag = "--log-dir"
logLevelFlag = "--log-level"
fileLogLevelFlag = "--file-log-level"
LogLevelError = "error"
LogLevelInfo = "info"
maxErrorsFlag = "--max-errors"
parallelFlag = "--parallel"
progressEstimationTypeFlag = "--progress-estimation-type"
adaptiveEstimationThresholdFlag = "--adaptive-estimation-threshold"
progressEstimationTypeAdaptive = "adaptive"
passwordFlag = "--password"
progressUpdateIntervalFlag = "--progress-update-interval"
rawFlag = "--raw"
showIdenticalFlag = "--show-identical"
sourcesFlag = "--sources"
tagsFlag = "--tags"
unsafeIgnoreSourceFlag = "--unsafe-ignore-source"
ownerFlag = "--owner"
sparseFlag = "--write-sparse-files"
verifyFilesPercentFlag = "--verify-files-percent"
ignorePermissionsError = "--ignore-permission-errors"
noIgnorePermissionsError = "--no-ignore-permission-errors"

// Server specific
addSubCommand = "add"
Expand Down Expand Up @@ -120,6 +123,9 @@ const (

// Constants for kopia defaults
const (
// defaultAdaptiveEstimationThreshold is a default value of adaptive estimation threshold.
defaultAdaptiveEstimationThreshold = 300000

// DefaultCacheDirectory is the directory where kopia content cache is created
DefaultCacheDirectory = "/tmp/kopia-cache"

Expand Down
14 changes: 14 additions & 0 deletions pkg/kopia/command/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type SnapshotCreateCommandArgs struct {
Tags []string
ProgressUpdateInterval time.Duration
Parallelism int
EstimationType string
EstimationThreshold int
}

// SnapshotCreate returns the kopia command for creation of a snapshot
Expand All @@ -48,6 +50,18 @@ func SnapshotCreate(cmdArgs SnapshotCreateCommandArgs) []string {
args := commonArgs(cmdArgs.CommandArgs)
args = args.AppendLoggable(snapshotSubCommand, createSubCommand, cmdArgs.PathToBackup, jsonFlag)
args = args.AppendLoggableKV(parallelFlag, parallelismStr)

if cmdArgs.EstimationType != "" {
args = args.AppendLoggableKV(progressEstimationTypeFlag, cmdArgs.EstimationType)
if cmdArgs.EstimationType == progressEstimationTypeAdaptive {
threshold := cmdArgs.EstimationThreshold
if threshold == 0 {
threshold = defaultAdaptiveEstimationThreshold
}
thresholdStr := strconv.Itoa(threshold)
args = args.AppendLoggableKV(adaptiveEstimationThresholdFlag, thresholdStr)
}
}
args = addTags(cmdArgs.Tags, args)

// kube.Exec might timeout after 4h if there is no output from the command
Expand Down
37 changes: 37 additions & 0 deletions pkg/kopia/command/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,43 @@ func (kSnapshot *KopiaSnapshotTestSuite) TestSnapshotCommands(c *check.C) {
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot create path/to/backup --json --parallel=8 --progress-update-interval=2m",
},
{
f: func() []string {
args := SnapshotCreateCommandArgs{
CommandArgs: commandArgs,
PathToBackup: "path/to/backup",
Parallelism: 8,
EstimationType: "rough",
}
return SnapshotCreate(args)
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot create path/to/backup --json --parallel=8 --progress-estimation-type=rough --progress-update-interval=1h",
},
{
f: func() []string {
args := SnapshotCreateCommandArgs{
CommandArgs: commandArgs,
PathToBackup: "path/to/backup",
Parallelism: 8,
EstimationType: "adaptive",
}
return SnapshotCreate(args)
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot create path/to/backup --json --parallel=8 --progress-estimation-type=adaptive --adaptive-estimation-threshold=300000 --progress-update-interval=1h",
},
{
f: func() []string {
args := SnapshotCreateCommandArgs{
CommandArgs: commandArgs,
PathToBackup: "path/to/backup",
Parallelism: 8,
EstimationType: "adaptive",
EstimationThreshold: 100,
}
return SnapshotCreate(args)
},
expectedLog: "kopia --log-level=info --config-file=path/kopia.config --log-dir=cache/log --password=encr-key snapshot create path/to/backup --json --parallel=8 --progress-estimation-type=adaptive --adaptive-estimation-threshold=100 --progress-update-interval=1h",
},
{
f: func() []string {
args := SnapshotExpireCommandArgs{
Expand Down

0 comments on commit 793523b

Please sign in to comment.