mirror of
https://github.com/kopia/kopia.git
synced 2026-01-22 13:27:57 -05:00
* mechanical rename of package snapshot/gc => snapshot/snapshotgc * maintenance: record maintenance run times and statuses Also stopped dropping deleted contents during quick maintenance, since doing this safely requires coordinating with snapshot GC which is part of full maintenance. * cli: 'maintenance info' outputs maintenance run history * maintenance: only drop index entries when it's safe to do so This is based on the timestamp of previous successful GC that's old enough to resolve all race conditions between snapshot creation and GC. * maintenance: added internal flush to RewriteContents() to better measure its time
34 lines
1.0 KiB
Go
34 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"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()
|
|
optimizeDropDeletedOlderThan = optimizeCommand.Flag("drop-deleted-older-than", "Drop deleted contents 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 {
|
|
opt := content.CompactOptions{
|
|
MaxSmallBlobs: *optimizeMaxSmallBlobs,
|
|
AllIndexes: *optimizeAllIndexes,
|
|
}
|
|
|
|
if age := *optimizeDropDeletedOlderThan; age > 0 {
|
|
opt.DropDeletedBefore = time.Now().Add(-age)
|
|
}
|
|
|
|
return rep.Content.CompactIndexes(ctx, opt)
|
|
}
|
|
|
|
func init() {
|
|
optimizeCommand.Action(directRepositoryAction(runOptimizeCommand))
|
|
}
|