Files
kopia/cli/command_content_rewrite.go
Jarek Kowalski d07eb9f300 cli: added --safety=full|none flag to maintenance commands (#912)
* cli: added --safety=full|none flag to maintenance commands

This allows selection between safe, high-latency maintenance parameters
which allow concurrent access (`full`) or low-latency which may be
unsafe in certain situations when concurrent Kopia processes are
running.

This is a breaking change for advanced CLI commands, where it removes
timing parameters and replaces them with single `--safety` option.

* 'blob gc'
* 'content rewrite'
* 'snapshot gc'

* pr renames

* maintenance: fixed computation of safe time for --safety=none

* maintenance: improved logging for blob gc

* maintenance: do not rewrite truly short, densely packed packs

* mechanical: pass eventual consistency settle time via CompactOptions

* maintenance: add option to disable eventual consistency time buffers with --safety=none

* maintenance: trigger flush at the end of snapshot gc

* maintenance: reload indexes after compaction that drops deleted entries, this allows single-pass maintenance with --safety=none to delete all unused blobs

* testing: allow debugging of integration tests inside VSCode

* testing: added end-to-end maintenance test that verifies that full maintenance with --safety=none removes all data
2021-04-02 21:56:01 -07:00

51 lines
2.0 KiB
Go

package cli
import (
"context"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/blob"
"github.com/kopia/kopia/repo/content"
"github.com/kopia/kopia/repo/maintenance"
)
var (
contentRewriteCommand = contentCommands.Command("rewrite", "Rewrite content using most recent format")
contentRewriteIDs = contentRewriteCommand.Arg("contentID", "Identifiers of contents to rewrite").Strings()
contentRewriteParallelism = contentRewriteCommand.Flag("parallelism", "Number of parallel workers").Default("16").Int()
contentRewriteShortPacks = contentRewriteCommand.Flag("short", "Rewrite contents from short packs").Bool()
contentRewriteFormatVersion = contentRewriteCommand.Flag("format-version", "Rewrite contents using the provided format version").Default("-1").Int()
contentRewritePackPrefix = contentRewriteCommand.Flag("pack-prefix", "Only rewrite contents from pack blobs with a given prefix").String()
contentRewriteDryRun = contentRewriteCommand.Flag("dry-run", "Do not actually rewrite, only print what would happen").Short('n').Bool()
contentRewriteSafety = safetyFlag(contentRewriteCommand)
)
func runContentRewriteCommand(ctx context.Context, rep repo.DirectRepositoryWriter) error {
advancedCommand(ctx)
return maintenance.RewriteContents(ctx, rep, &maintenance.RewriteContentsOptions{
ContentIDRange: contentIDRange(),
ContentIDs: toContentIDs(*contentRewriteIDs),
FormatVersion: *contentRewriteFormatVersion,
PackPrefix: blob.ID(*contentRewritePackPrefix),
Parallel: *contentRewriteParallelism,
ShortPacks: *contentRewriteShortPacks,
DryRun: *contentRewriteDryRun,
}, *contentRewriteSafety)
}
func toContentIDs(s []string) []content.ID {
var result []content.ID
for _, cid := range s {
result = append(result, content.ID(cid))
}
return result
}
func init() {
contentRewriteCommand.Action(directRepositoryWriteAction(runContentRewriteCommand))
setupContentIDRangeFlags(contentRewriteCommand)
}