forked from TrueCloudLab/restic
Merge pull request #1115 from restic/fix-prune-index
prune: Fix newly created index
This commit is contained in:
commit
c30838878f
2 changed files with 11 additions and 6 deletions
|
@ -235,22 +235,23 @@ func pruneRepository(gopts GlobalOptions, repo restic.Repository) error {
|
||||||
Verbosef("will delete %d packs and rewrite %d packs, this frees %s\n",
|
Verbosef("will delete %d packs and rewrite %d packs, this frees %s\n",
|
||||||
len(removePacks), len(rewritePacks), formatBytes(uint64(removeBytes)))
|
len(removePacks), len(rewritePacks), formatBytes(uint64(removeBytes)))
|
||||||
|
|
||||||
var repackedBlobs restic.IDSet
|
var obsoletePacks restic.IDSet
|
||||||
if len(rewritePacks) != 0 {
|
if len(rewritePacks) != 0 {
|
||||||
bar = newProgressMax(!gopts.Quiet, uint64(len(rewritePacks)), "packs rewritten")
|
bar = newProgressMax(!gopts.Quiet, uint64(len(rewritePacks)), "packs rewritten")
|
||||||
bar.Start()
|
bar.Start()
|
||||||
repackedBlobs, err = repository.Repack(ctx, repo, rewritePacks, usedBlobs, bar)
|
obsoletePacks, err = repository.Repack(ctx, repo, rewritePacks, usedBlobs, bar)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
bar.Done()
|
bar.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removePacks.Merge(obsoletePacks)
|
||||||
|
|
||||||
if err = rebuildIndex(ctx, repo, removePacks); err != nil {
|
if err = rebuildIndex(ctx, repo, removePacks); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
removePacks.Merge(repackedBlobs)
|
|
||||||
if len(removePacks) != 0 {
|
if len(removePacks) != 0 {
|
||||||
bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted")
|
bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted")
|
||||||
bar.Start()
|
bar.Start()
|
||||||
|
|
|
@ -1175,15 +1175,19 @@ func TestPrune(t *testing.T) {
|
||||||
SetupTarTestFixture(t, env.testdata, datafile)
|
SetupTarTestFixture(t, env.testdata, datafile)
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "1")}, opts, gopts)
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0")}, opts, gopts)
|
||||||
|
firstSnapshot := testRunList(t, "snapshots", gopts)
|
||||||
|
Assert(t, len(firstSnapshot) == 1,
|
||||||
|
"expected one snapshot, got %v", firstSnapshot)
|
||||||
|
|
||||||
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, gopts)
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, gopts)
|
||||||
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, gopts)
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, gopts)
|
||||||
|
|
||||||
snapshotIDs := testRunList(t, "snapshots", gopts)
|
snapshotIDs := testRunList(t, "snapshots", gopts)
|
||||||
Assert(t, len(snapshotIDs) == 3,
|
Assert(t, len(snapshotIDs) == 3,
|
||||||
"expected one snapshot, got %v", snapshotIDs)
|
"expected 3 snapshot, got %v", snapshotIDs)
|
||||||
|
|
||||||
testRunForget(t, gopts, snapshotIDs[0].String())
|
testRunForget(t, gopts, firstSnapshot[0].String())
|
||||||
testRunPrune(t, gopts)
|
testRunPrune(t, gopts)
|
||||||
testRunCheck(t, gopts)
|
testRunCheck(t, gopts)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue