mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 16:23:04 -05:00
* 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
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/repo/blob"
|
|
"github.com/kopia/kopia/repo/maintenance"
|
|
)
|
|
|
|
var (
|
|
blobGarbageCollectCommand = blobCommands.Command("gc", "Garbage-collect unused blobs")
|
|
blobGarbageCollectCommandDelete = blobGarbageCollectCommand.Flag("delete", "Whether to delete unused blobs").String()
|
|
blobGarbageCollectParallel = blobGarbageCollectCommand.Flag("parallel", "Number of parallel blob scans").Default("16").Int()
|
|
blobGarbageCollectPrefix = blobGarbageCollectCommand.Flag("prefix", "Only GC blobs with given prefix").String()
|
|
blobGarbageCollectSafety = safetyFlag(blobGarbageCollectCommand)
|
|
)
|
|
|
|
func runBlobGarbageCollectCommand(ctx context.Context, rep repo.DirectRepositoryWriter) error {
|
|
advancedCommand(ctx)
|
|
|
|
opts := maintenance.DeleteUnreferencedBlobsOptions{
|
|
DryRun: *blobGarbageCollectCommandDelete != "yes",
|
|
Parallel: *blobGarbageCollectParallel,
|
|
Prefix: blob.ID(*blobGarbageCollectPrefix),
|
|
}
|
|
|
|
n, err := maintenance.DeleteUnreferencedBlobs(ctx, rep, opts, *blobGarbageCollectSafety)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error deleting unreferenced blobs")
|
|
}
|
|
|
|
if opts.DryRun && n > 0 {
|
|
log(ctx).Infof("Pass --delete=yes to delete.")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
blobGarbageCollectCommand.Action(directRepositoryWriteAction(runBlobGarbageCollectCommand))
|
|
}
|