mirror of
https://github.com/octoleo/restic.git
synced 2024-12-25 04:05:58 +00:00
Remove unneeded packs without repacking
This commit is contained in:
parent
de88fb2022
commit
b2a67d458c
@ -169,6 +169,7 @@ func (cmd CmdPrune) Execute(args []string) error {
|
|||||||
for h, blob := range idx.Blobs {
|
for h, blob := range idx.Blobs {
|
||||||
if !usedBlobs.Has(h) {
|
if !usedBlobs.Has(h) {
|
||||||
rewritePacks.Merge(blob.Packs)
|
rewritePacks.Merge(blob.Packs)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if blobCount[h] > 1 {
|
if blobCount[h] > 1 {
|
||||||
@ -176,13 +177,40 @@ func (cmd CmdPrune) Execute(args []string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.global.Verbosef("will rewrite %d packs\n", len(rewritePacks))
|
// find packs that are unneeded
|
||||||
|
removePacks := backend.NewIDSet()
|
||||||
|
nextPack:
|
||||||
|
for packID, p := range idx.Packs {
|
||||||
|
for _, blob := range p.Entries {
|
||||||
|
h := pack.Handle{ID: blob.ID, Type: blob.Type}
|
||||||
|
if usedBlobs.Has(h) {
|
||||||
|
continue nextPack
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removePacks.Insert(packID)
|
||||||
|
|
||||||
|
if !rewritePacks.Has(packID) {
|
||||||
|
return fmt.Errorf("pack %v is unneeded, but not contained in rewritePacks", packID.Str())
|
||||||
|
}
|
||||||
|
|
||||||
|
rewritePacks.Delete(packID)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.global.Verbosef("will delete %d packs and rewrite %d packs\n", len(removePacks), len(rewritePacks))
|
||||||
|
|
||||||
err = repository.Repack(repo, rewritePacks, usedBlobs)
|
err = repository.Repack(repo, rewritePacks, usedBlobs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for packID := range removePacks {
|
||||||
|
err = repo.Backend().Remove(backend.Data, packID.String())
|
||||||
|
if err != nil {
|
||||||
|
cmd.global.Warnf("unable to remove file %v from the repository\n", packID.Str())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmd.global.Verbosef("creating new index\n")
|
cmd.global.Verbosef("creating new index\n")
|
||||||
|
|
||||||
for _ = range repo.List(backend.Data, done) {
|
for _ = range repo.List(backend.Data, done) {
|
||||||
|
Loading…
Reference in New Issue
Block a user