mirror of
https://github.com/kopia/kopia.git
synced 2026-03-12 11:16:25 -04:00
* logging: cleaned up stderr logging - do not show module - do not show timestamps by default (enable with --console-timestamps) * logging: replaced most printStderr() with log.Info * cli: additional logging cleanup
44 lines
1.4 KiB
Go
44 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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()
|
|
blobGarbageCollectMinAge = blobGarbageCollectCommand.Flag("min-age", "Garbage-collect blobs with minimum age").Default("24h").Duration()
|
|
blobGarbageCollectPrefix = blobGarbageCollectCommand.Flag("prefix", "Only GC blobs with given prefix").String()
|
|
)
|
|
|
|
func runBlobGarbageCollectCommand(ctx context.Context, rep *repo.DirectRepository) error {
|
|
advancedCommand(ctx)
|
|
|
|
opts := maintenance.DeleteUnreferencedBlobsOptions{
|
|
DryRun: *blobGarbageCollectCommandDelete != "yes",
|
|
MinAge: *blobGarbageCollectMinAge,
|
|
Parallel: *blobGarbageCollectParallel,
|
|
Prefix: blob.ID(*blobGarbageCollectPrefix),
|
|
}
|
|
|
|
n, err := maintenance.DeleteUnreferencedBlobs(ctx, rep, opts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if opts.DryRun && n > 0 {
|
|
log(ctx).Infof("Pass --delete=yes to delete.")
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
func init() {
|
|
blobGarbageCollectCommand.Action(directRepositoryAction(runBlobGarbageCollectCommand))
|
|
}
|