Files
kopia/cli/command_index_optimize.go
Jarek Kowalski 6cb9b8fa4f repo: refactored public API (#318)
* This is 99% mechanical:

Extracted repo.Repository interface that only exposes high-level object and manifest management methods, but not blob nor content management.

Renamed old *repo.Repository to *repo.DirectRepository

Reviewed codebase to only depend on repo.Repository as much as possible, but added way for low-level CLI commands to use DirectRepository.

* PR fixes
2020-03-26 08:04:01 -07:00

28 lines
1010 B
Go

package cli
import (
"context"
"github.com/kopia/kopia/repo"
"github.com/kopia/kopia/repo/content"
)
var (
optimizeCommand = indexCommands.Command("optimize", "Optimize indexes blobs.")
optimizeMaxSmallBlobs = optimizeCommand.Flag("max-small-blobs", "Maximum number of small index blobs that can be left after compaction.").Default("1").Int()
optimizeSkipDeletedOlderThan = optimizeCommand.Flag("skip-deleted-older-than", "Skip deleted blobs above given age").Duration()
optimizeAllIndexes = optimizeCommand.Flag("all", "Optimize all indexes, even those above maximum size.").Bool()
)
func runOptimizeCommand(ctx context.Context, rep *repo.DirectRepository) error {
return rep.Content.CompactIndexes(ctx, content.CompactOptions{
MaxSmallBlobs: *optimizeMaxSmallBlobs,
AllIndexes: *optimizeAllIndexes,
SkipDeletedOlderThan: *optimizeSkipDeletedOlderThan,
})
}
func init() {
optimizeCommand.Action(directRepositoryAction(runOptimizeCommand))
}