forked from TrueCloudLab/restic
Add mostly ready repacker
This commit is contained in:
parent
51aff3ca57
commit
266bc05edc
2 changed files with 30 additions and 3 deletions
|
@ -38,6 +38,33 @@ func (r *Repacker) Repack() error {
|
||||||
|
|
||||||
debug.Log("Repacker.Repack", "found packs: %v", packs)
|
debug.Log("Repacker.Repack", "found packs: %v", packs)
|
||||||
|
|
||||||
|
blobs, err := FindBlobsForPacks(r.src, packs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.Log("Repacker.Repack", "found blobs: %v", blobs)
|
||||||
|
|
||||||
|
for id := range r.unusedBlobs {
|
||||||
|
debug.Log("Repacker.Repack", "remove unused blob %v", id.Str())
|
||||||
|
blobs.Delete(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.Log("Repacker.Repack", "need to repack blobs: %v", blobs)
|
||||||
|
|
||||||
|
err = RepackBlobs(r.src, r.dst, blobs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
debug.Log("Repacker.Repack", "remove unneeded packs: %v", packs)
|
||||||
|
for packID := range packs {
|
||||||
|
err = r.src.Backend().Remove(backend.Data, packID.String())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +127,8 @@ func repackBlob(src, dst *repository.Repository, id backend.ID) error {
|
||||||
|
|
||||||
// RepackBlobs reads all blobs in blobIDs from src and saves them into new pack
|
// RepackBlobs reads all blobs in blobIDs from src and saves them into new pack
|
||||||
// files in dst. Source and destination repo may be the same.
|
// files in dst. Source and destination repo may be the same.
|
||||||
func RepackBlobs(src, dst *repository.Repository, blobIDs backend.IDs) (err error) {
|
func RepackBlobs(src, dst *repository.Repository, blobIDs backend.IDSet) (err error) {
|
||||||
for _, id := range blobIDs {
|
for id := range blobIDs {
|
||||||
err = repackBlob(src, dst, id)
|
err = repackBlob(src, dst, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -85,7 +85,7 @@ func TestRepackerFindPacks(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRepackBlobs(t *testing.T) {
|
func TestRepacker(t *testing.T) {
|
||||||
WithTestEnvironment(t, checkerTestData, func(repodir string) {
|
WithTestEnvironment(t, checkerTestData, func(repodir string) {
|
||||||
repo := OpenLocalRepo(t, repodir)
|
repo := OpenLocalRepo(t, repodir)
|
||||||
OK(t, repo.LoadIndex())
|
OK(t, repo.LoadIndex())
|
||||||
|
|
Loading…
Add table
Reference in a new issue