mirror of
https://github.com/kopia/kopia.git
synced 2026-01-29 08:43:09 -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.3 KiB
Go
34 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/kopia/kopia/internal/units"
|
|
"github.com/kopia/kopia/repo"
|
|
"github.com/kopia/kopia/repo/maintenance"
|
|
"github.com/kopia/kopia/snapshot/snapshotgc"
|
|
)
|
|
|
|
var (
|
|
snapshotGCCommand = snapshotCommands.Command("gc", "Remove contents not used by any snapshot")
|
|
snapshotGCMinContentAge = snapshotGCCommand.Flag("min-age", "Minimum content age to allow deletion").Default("24h").Duration()
|
|
snapshotGCDelete = snapshotGCCommand.Flag("delete", "Delete unreferenced contents").Bool()
|
|
)
|
|
|
|
func runSnapshotGCCommand(ctx context.Context, rep *repo.DirectRepository) error {
|
|
st, err := snapshotgc.Run(ctx, rep, maintenance.SnapshotGCParams{
|
|
MinContentAge: *snapshotGCMinContentAge,
|
|
}, *snapshotGCDelete)
|
|
|
|
log(ctx).Infof("GC found %v unused contents (%v bytes)", st.UnusedCount, units.BytesStringBase2(st.UnusedBytes))
|
|
log(ctx).Infof("GC found %v unused contents that are too recent to delete (%v bytes)", st.TooRecentCount, units.BytesStringBase2(st.TooRecentBytes))
|
|
log(ctx).Infof("GC found %v in-use contents (%v bytes)", st.InUseCount, units.BytesStringBase2(st.InUseBytes))
|
|
log(ctx).Infof("GC found %v in-use system-contents (%v bytes)", st.SystemCount, units.BytesStringBase2(st.SystemBytes))
|
|
|
|
return err
|
|
}
|
|
|
|
func init() {
|
|
snapshotGCCommand.Action(directRepositoryAction(runSnapshotGCCommand))
|
|
}
|