Skip to content

Commit

Permalink
fix: restic should initialize repo on backup operation
Browse files Browse the repository at this point in the history
  • Loading branch information
garethgeorge committed Dec 20, 2023
1 parent fc9c06d commit e57abbd
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions internal/orchestrator/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
type RepoOrchestrator struct {
mu sync.Mutex

l *zap.Logger
repoConfig *v1.Repo
repo *restic.Repo
l *zap.Logger
repoConfig *v1.Repo
repo *restic.Repo
initialized bool
}

// newRepoOrchestrator accepts a config and a repo that is configured with the properties of that config object.
Expand Down Expand Up @@ -53,16 +54,23 @@ func (r *RepoOrchestrator) SnapshotsForPlan(ctx context.Context, plan *v1.Plan)
func (r *RepoOrchestrator) Backup(ctx context.Context, plan *v1.Plan, progressCallback func(event *restic.BackupProgressEntry)) (*restic.BackupProgressEntry, error) {
zap.L().Debug("repo orchestrator starting backup", zap.String("repo", r.repoConfig.Id))

r.mu.Lock()
defer r.mu.Unlock()
if !r.initialized {

if err := r.repo.Init(ctx); err != nil {
return nil, fmt.Errorf("failed to initialize repo: %w", err)
}
r.initialized = true
}

snapshots, err := r.SnapshotsForPlan(ctx, plan)
if err != nil {
return nil, fmt.Errorf("failed to get snapshots for plan: %w", err)
}

r.l.Debug("got snapshots for plan", zap.String("repo", r.repoConfig.Id), zap.Int("count", len(snapshots)), zap.String("plan", plan.Id), zap.String("tag", tagForPlan(plan)))

r.mu.Lock()
defer r.mu.Unlock()

startTime := time.Now()

var opts []restic.BackupOption
Expand Down

0 comments on commit e57abbd

Please sign in to comment.