2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-14 14:52:22 +00:00

s3 migrate layout: Retry on errors

This commit is contained in:
Alexander Neumann 2017-07-02 11:14:44 +02:00
parent 993e370f92
commit 453c9c9199

View File

@ -2,6 +2,8 @@ package migrations
import (
"context"
"fmt"
"os"
"path"
"restic"
"restic/backend"
@ -34,13 +36,35 @@ func (m *S3Layout) Check(ctx context.Context, repo restic.Repository) (bool, err
return true, nil
}
func retry(max int, fail func(err error), f func() error) error {
var err error
for i := 0; i < max; i++ {
err = f()
if err == nil {
return err
}
if fail != nil {
fail(err)
}
}
return err
}
// maxErrors for retrying renames on s3.
const maxErrors = 20
func (m *S3Layout) moveFiles(ctx context.Context, be *s3.Backend, l backend.Layout, t restic.FileType) error {
printErr := func(err error) {
fmt.Fprintf(os.Stderr, "renaming file returned error: %v\n", err)
}
for name := range be.List(ctx, t) {
h := restic.Handle{Type: t, Name: name}
debug.Log("move %v", h)
if err := be.Rename(h, l); err != nil {
return err
}
retry(maxErrors, printErr, func() error {
return be.Rename(h, l)
})
}
return nil