From 223dc78acbf3a6b11bcdb4686886ee5b36f3e9d2 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 12 Sep 2016 14:26:47 +0200 Subject: [PATCH] Improve statistics for `prune` Sample: counting files in repo building new index for repo [0:00] 100.00% 22 / 22 packs repository contains 22 packs (1377 blobs) with 90.610 MiB bytes processed 1377 blobs: 0 duplicate blobs, 0B duplicate load all snapshots find data that is still in use for 1 snapshots [0:00] 100.00% 1 / 1 snapshots found 409 of 1377 data blobs still in use, removing 968 blobs will delete 10 packs and rewrite 10 packs, this frees 64.232 MiB creating new index [0:00] 100.00% 7 / 7 packs saved new index as df467c6e done Closes #581 --- src/cmds/restic/cmd_prune.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cmds/restic/cmd_prune.go b/src/cmds/restic/cmd_prune.go index 4fa8ba0d3..d59e9ea80 100644 --- a/src/cmds/restic/cmd_prune.go +++ b/src/cmds/restic/cmd_prune.go @@ -161,7 +161,8 @@ func (cmd CmdPrune) Execute(args []string) error { } bar.Done() - cmd.global.Verbosef("found %d of %d data blobs still in use\n", len(usedBlobs), stats.blobs) + cmd.global.Verbosef("found %d of %d data blobs still in use, removing %d blobs\n", + len(usedBlobs), stats.blobs, stats.blobs-len(usedBlobs)) // find packs that need a rewrite rewritePacks := restic.NewIDSet() @@ -176,15 +177,25 @@ func (cmd CmdPrune) Execute(args []string) error { } } + removeBytes := 0 + // find packs that are unneeded removePacks := restic.NewIDSet() -nextPack: for packID, p := range idx.Packs { + + hasActiveBlob := false for _, blob := range p.Entries { h := restic.BlobHandle{ID: blob.ID, Type: blob.Type} if usedBlobs.Has(h) { - continue nextPack + hasActiveBlob = true + continue } + + removeBytes += int(blob.Length) + } + + if hasActiveBlob { + continue } removePacks.Insert(packID) @@ -196,7 +207,8 @@ nextPack: rewritePacks.Delete(packID) } - cmd.global.Verbosef("will delete %d packs and rewrite %d packs\n", len(removePacks), len(rewritePacks)) + cmd.global.Verbosef("will delete %d packs and rewrite %d packs, this frees %s\n", + len(removePacks), len(rewritePacks), formatBytes(uint64(removeBytes))) err = repository.Repack(repo, rewritePacks, usedBlobs) if err != nil {