Files
kopia/cli/command_blob_gc.go
Julio Lopez c7ea2c6e09 refactor(general): consistent use "pack" where possible (#4952)
In kopia, "blob" is a generic term to refer to either
an object in an object storage provider, or a file
in a file system storage provider. There are various
types of blobs in a kopia repository.

In kopia, the term "pack" is used to refer to specific types
of blobs, namely 'p' & 'q' pack blobs, that store
"content" data, as opposed to say, "index" blobs.

This change attempts to use the term "pack" consistently
in the functions and types used for pack deletion.

Note that the corresponding task names, shown below, remain
unchanged since these names are used in the persistent
maintenance run metadata, and that is used to make decisions
about the safety of the execution of those tasks.

```
	TaskDeleteOrphanedBlobsQuick     = "quick-delete-blobs"
	TaskDeleteOrphanedBlobsFull      = "full-delete-blobs"
```
2025-11-05 22:03:21 -08:00

53 lines
1.3 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"
)
type commandBlobGC struct {
delete string
parallel int
prefix string
safety maintenance.SafetyParameters
svc appServices
}
func (c *commandBlobGC) setup(svc appServices, parent commandParent) {
cmd := parent.Command("gc", "Garbage-collect unused blobs").Hidden()
cmd.Flag("delete", "Whether to delete unused blobs").StringVar(&c.delete)
cmd.Flag("parallel", "Number of parallel blob scans").Default("16").IntVar(&c.parallel)
cmd.Flag("prefix", "Only GC blobs with given prefix").StringVar(&c.prefix)
safetyFlagVar(cmd, &c.safety)
cmd.Action(svc.directRepositoryWriteAction(c.run))
c.svc = svc
}
func (c *commandBlobGC) run(ctx context.Context, rep repo.DirectRepositoryWriter) error {
c.svc.dangerousCommand()
opts := maintenance.DeleteUnreferencedPacksOptions{
DryRun: c.delete != "yes",
Parallel: c.parallel,
Prefix: blob.ID(c.prefix),
}
stats, err := maintenance.DeleteUnreferencedPacks(ctx, rep, opts, c.safety)
if err != nil {
return errors.Wrap(err, "error deleting unreferenced blobs")
}
if opts.DryRun && stats.UnreferencedPackCount > 0 {
log(ctx).Info("Pass --delete=yes to delete.")
}
return nil
}