mirror of
https://github.com/octoleo/restic.git
synced 2025-01-11 18:18:45 +00:00
Merge pull request #850 from middelink/fix-848
Add progressbar to repack and blob remove phases of prune cmd.
This commit is contained in:
commit
bbcab800c9
@ -217,17 +217,28 @@ 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)))
|
||||||
|
|
||||||
err = repository.Repack(repo, rewritePacks, usedBlobs)
|
if len(rewritePacks) != 0 {
|
||||||
if err != nil {
|
bar = newProgressMax(!gopts.Quiet, uint64(len(rewritePacks)), "packs rewritten")
|
||||||
return err
|
bar.Start()
|
||||||
|
err = repository.Repack(repo, rewritePacks, usedBlobs, bar)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
bar.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
for packID := range removePacks {
|
if len(removePacks) != 0 {
|
||||||
h := restic.Handle{Type: restic.DataFile, Name: packID.String()}
|
bar = newProgressMax(!gopts.Quiet, uint64(len(removePacks)), "packs deleted")
|
||||||
err = repo.Backend().Remove(h)
|
bar.Start()
|
||||||
if err != nil {
|
for packID := range removePacks {
|
||||||
Warnf("unable to remove file %v from the repository\n", packID.Str())
|
h := restic.Handle{Type: restic.DataFile, Name: packID.String()}
|
||||||
|
err = repo.Backend().Remove(h)
|
||||||
|
if err != nil {
|
||||||
|
Warnf("unable to remove file %v from the repository\n", packID.Str())
|
||||||
|
}
|
||||||
|
bar.Report(restic.Stat{Blobs: 1})
|
||||||
}
|
}
|
||||||
|
bar.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
Verbosef("creating new index\n")
|
Verbosef("creating new index\n")
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
// these packs. Each pack is loaded and the blobs listed in keepBlobs is saved
|
// these packs. Each pack is loaded and the blobs listed in keepBlobs is saved
|
||||||
// into a new pack. Afterwards, the packs are removed. This operation requires
|
// into a new pack. Afterwards, the packs are removed. This operation requires
|
||||||
// an exclusive lock on the repo.
|
// an exclusive lock on the repo.
|
||||||
func Repack(repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet) (err error) {
|
func Repack(repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet, p *restic.Progress) (err error) {
|
||||||
debug.Log("repacking %d packs while keeping %d blobs", len(packs), len(keepBlobs))
|
debug.Log("repacking %d packs while keeping %d blobs", len(packs), len(keepBlobs))
|
||||||
|
|
||||||
for packID := range packs {
|
for packID := range packs {
|
||||||
@ -118,6 +118,9 @@ func Repack(repo restic.Repository, packs restic.IDSet, keepBlobs restic.BlobSet
|
|||||||
if err = os.Remove(tempfile.Name()); err != nil {
|
if err = os.Remove(tempfile.Name()); err != nil {
|
||||||
return errors.Wrap(err, "Remove")
|
return errors.Wrap(err, "Remove")
|
||||||
}
|
}
|
||||||
|
if p != nil {
|
||||||
|
p.Report(restic.Stat{Blobs: 1})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := repo.Flush(); err != nil {
|
if err := repo.Flush(); err != nil {
|
||||||
|
@ -132,7 +132,7 @@ func findPacksForBlobs(t *testing.T, repo restic.Repository, blobs restic.BlobSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func repack(t *testing.T, repo restic.Repository, packs restic.IDSet, blobs restic.BlobSet) {
|
func repack(t *testing.T, repo restic.Repository, packs restic.IDSet, blobs restic.BlobSet) {
|
||||||
err := repository.Repack(repo, packs, blobs)
|
err := repository.Repack(repo, packs, blobs, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user