From daeb4cdf8f0b3a1e80bd3eb3e85d937dec2e341c Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Fri, 29 Jan 2021 22:24:23 +0100 Subject: [PATCH 1/2] prune: Fix statistics for --repack-cacheable-only --- cmd/restic/cmd_prune.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index bf64401b4..a4522003a 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -298,6 +298,14 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB repackPacks := restic.NewIDSet() var repackCandidates []packInfoWithID + repackAllPacksWithDuplicates := true + + keep := func(p packInfo) { + stats.packs.keep++ + if p.duplicateBlobs > 0 { + repackAllPacksWithDuplicates = false + } + } // loop over all packs and decide what to do bar := newProgressMax(!gopts.Quiet, uint64(len(indexPack)), "packs processed") @@ -341,11 +349,11 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB case opts.RepackCachableOnly && p.tpe == restic.DataBlob: // if this is a data pack and --repack-cacheable-only is set => keep pack! - stats.packs.keep++ + keep(p) case p.unusedBlobs == 0 && p.duplicateBlobs == 0 && p.tpe != restic.InvalidBlob: // All blobs in pack are used and not duplicates/mixed => keep pack! - stats.packs.keep++ + keep(p) default: // all other packs are candidates for repacking @@ -385,8 +393,6 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB } } - repackAllPacksWithDuplicates := true - // calculate limit for number of unused bytes in the repo after repacking maxUnusedSizeAfter := opts.maxUnusedBytes(stats.size.used) @@ -429,15 +435,12 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB switch { case !reachedRepackSize && (p.duplicateBlobs > 0 || p.tpe != restic.DataBlob): - // repacking duplicates/mixed is only limited by repackSize + // repacking duplicates/non-data is only limited by repackSize repack(p.ID, p.packInfo) case reachedUnusedSizeAfter, reachedRepackSize: // for all other packs stop repacking if tolerated unused size is reached. - stats.packs.keep++ - if p.duplicateBlobs > 0 { - repackAllPacksWithDuplicates = false - } + keep(p.packInfo) default: repack(p.ID, p.packInfo) From e08e65dc3057ec5108d87ed9d4d1e6359e3fa0a4 Mon Sep 17 00:00:00 2001 From: Alexander Weiss Date: Fri, 29 Jan 2021 22:25:41 +0100 Subject: [PATCH 2/2] prune: Simplify logic selecting packs to repack --- cmd/restic/cmd_prune.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/restic/cmd_prune.go b/cmd/restic/cmd_prune.go index a4522003a..9a415c61d 100644 --- a/cmd/restic/cmd_prune.go +++ b/cmd/restic/cmd_prune.go @@ -434,11 +434,14 @@ func prune(opts PruneOptions, gopts GlobalOptions, repo restic.Repository, usedB } switch { - case !reachedRepackSize && (p.duplicateBlobs > 0 || p.tpe != restic.DataBlob): + case reachedRepackSize: + keep(p.packInfo) + + case p.duplicateBlobs > 0, p.tpe != restic.DataBlob: // repacking duplicates/non-data is only limited by repackSize repack(p.ID, p.packInfo) - case reachedUnusedSizeAfter, reachedRepackSize: + case reachedUnusedSizeAfter: // for all other packs stop repacking if tolerated unused size is reached. keep(p.packInfo)