mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 19:08:55 +00:00
migrate: Allow migrations to request a check run
This is currently only used by upgrade_repo_v2.
This commit is contained in:
parent
59eb132dcd
commit
c1bbbcd0dc
@ -84,6 +84,20 @@ func applyMigrations(opts MigrateOptions, gopts GlobalOptions, repo restic.Repos
|
||||
Warnf("check for migration %v failed, continuing anyway\n", m.Name())
|
||||
}
|
||||
|
||||
repoCheckOpts := m.RepoCheckOptions()
|
||||
if repoCheckOpts != nil {
|
||||
Printf("checking repository integrity...\n")
|
||||
|
||||
checkOptions := CheckOptions{}
|
||||
checkGopts := gopts
|
||||
// the repository is already locked
|
||||
checkGopts.NoLock = true
|
||||
err = runCheck(checkOptions, checkGopts, []string{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
Printf("applying migration %v...\n", m.Name())
|
||||
if err = m.Apply(ctx, repo); err != nil {
|
||||
Warnf("migration %v failed: %v\n", m.Name(), err)
|
||||
|
@ -6,11 +6,16 @@ import (
|
||||
"github.com/restic/restic/internal/restic"
|
||||
)
|
||||
|
||||
type RepositoryCheckOptions struct {
|
||||
}
|
||||
|
||||
// Migration implements a data migration.
|
||||
type Migration interface {
|
||||
// Check returns true if the migration can be applied to a repo.
|
||||
Check(context.Context, restic.Repository) (bool, error)
|
||||
|
||||
RepoCheckOptions() *RepositoryCheckOptions
|
||||
|
||||
// Apply runs the migration.
|
||||
Apply(context.Context, restic.Repository) error
|
||||
|
||||
|
@ -37,6 +37,10 @@ func (m *S3Layout) Check(ctx context.Context, repo restic.Repository) (bool, err
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (m *S3Layout) RepoCheckOptions() *RepositoryCheckOptions {
|
||||
return nil
|
||||
}
|
||||
|
||||
func retry(max int, fail func(err error), f func() error) error {
|
||||
var err error
|
||||
for i := 0; i < max; i++ {
|
||||
|
@ -50,6 +50,9 @@ func (*UpgradeRepoV2) Check(ctx context.Context, repo restic.Repository) (bool,
|
||||
return isV1, nil
|
||||
}
|
||||
|
||||
func (*UpgradeRepoV2) RepoCheckOptions() *RepositoryCheckOptions {
|
||||
return &RepositoryCheckOptions{}
|
||||
}
|
||||
func (*UpgradeRepoV2) upgrade(ctx context.Context, repo restic.Repository) error {
|
||||
h := restic.Handle{Type: restic.ConfigFile}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user