mirror of
https://github.com/kopia/kopia.git
synced 2026-03-12 11:16:25 -04:00
* linter: upgraded to 1.33, disabled some linters * lint: fixed 'errorlint' errors This ensures that all error comparisons use errors.Is() or errors.As(). We will be wrapping more errors going forward so it's important that error checks are not strict everywhere. Verified that there are no exceptions for errorlint linter which guarantees that. * lint: fixed or suppressed wrapcheck errors * lint: nolintlint and misc cleanups Co-authored-by: Julio López <julio+gh@kasten.io>
46 lines
1.5 KiB
Go
46 lines
1.5 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()
|
|
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 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(directRepositoryAction(runBlobGarbageCollectCommand))
|
|
}
|