Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
dd22437
PMM-14576 Initial improvements.
JiriCtvrtka Jun 11, 2026
40aa594
Merge branch 'v3' into PMM-14576-backup-improvements
JiriCtvrtka Jun 11, 2026
dafecb6
Merge branch 'v3' into PMM-14576-backup-improvements
JiriCtvrtka Jun 12, 2026
33e1022
PMM-14576 Increase coverage.
JiriCtvrtka Jun 12, 2026
0350984
PMM-14576 Lint, changes.
JiriCtvrtka Jun 12, 2026
00e8f6b
Merge branch 'v3' into PMM-14576-backup-improvements
JiriCtvrtka Jun 12, 2026
7c3495c
Merge branch 'v3' into PMM-14576-backup-improvements
JiriCtvrtka Jun 15, 2026
dbc7393
PMM-14576 Improvements.
JiriCtvrtka Jun 15, 2026
c279451
PMM-14576 Refactor.
JiriCtvrtka Jun 15, 2026
e44ead2
PMM-14576 Refactor.
JiriCtvrtka Jun 15, 2026
80d4fcb
PMM-14576 Refactor.
JiriCtvrtka Jun 16, 2026
9011f9d
PMM-14576 Format.
JiriCtvrtka Jun 16, 2026
ef0ca4d
PMM-14576 Running backup not consume retries.
JiriCtvrtka Jun 16, 2026
c3050f4
PMM-14576 Lint.
JiriCtvrtka Jun 16, 2026
7e130f5
Merge branch 'v3' into PMM-14576-backup-improvements
JiriCtvrtka Jun 17, 2026
973c321
Merge branch 'main' into PMM-14576-backup-improvements
JiriCtvrtka Jun 22, 2026
c36457c
PMM-14576 Max's suggestion.
JiriCtvrtka Jun 22, 2026
416cca1
PMM-14576 Fix after conflicts.
JiriCtvrtka Jun 22, 2026
8aace63
PMM-14576 Lint.
JiriCtvrtka Jun 22, 2026
dccff14
PMM-14576 Another refactor.
JiriCtvrtka Jun 22, 2026
162541a
Merge branch 'main' into PMM-14576-backup-improvements
JiriCtvrtka Jun 23, 2026
728c61a
PMM-14576 Improvements.
JiriCtvrtka Jun 23, 2026
491925b
PMM-14576 Lint.
JiriCtvrtka Jun 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 27 additions & 24 deletions agent/runner/jobs/mongodb_restore_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/percona/pmm/agent/utils/poll"
agentv1 "github.com/percona/pmm/api/agent/v1"
)

Expand Down Expand Up @@ -211,36 +212,38 @@ func (j *MongoDBRestoreJob) startRestore(ctx context.Context, backupName string)
j.l.Infof("starting backup restore for: %s.", backupName)

var restoreOutput pbmRestore
var err error
startTime := time.Now()

ticker := time.NewTicker(statusCheckInterval)
defer ticker.Stop()
retryCount := 500
started := false

for {
select {
case <-ticker.C:
err := poll.UntilContextTimeout(ctx, statusCheckInterval, func(ctx context.Context) (bool, error) {
// Preserve previous behavior: first restore command runs after the first tick.
if !started {
started = true
return false, nil
}

if j.pitrTimestamp.Unix() == 0 {
err = execPBMCommand(ctx, j.dbURL, &restoreOutput, "restore", backupName)
} else {
err = execPBMCommand(ctx, j.dbURL, &restoreOutput, "restore", "--time="+j.pitrTimestamp.Format("2006-01-02T15:04:05"))
}
var cmdErr error
if j.pitrTimestamp.Unix() == 0 {
cmdErr = execPBMCommand(ctx, j.dbURL, &restoreOutput, "restore", backupName)
} else {
cmdErr = execPBMCommand(ctx, j.dbURL, &restoreOutput, "restore", "--time="+j.pitrTimestamp.Format("2006-01-02T15:04:05"))
}

if err != nil {
if strings.HasSuffix(err.Error(), "another operation in progress") && retryCount > 0 {
retryCount--
continue
}
return nil, fmt.Errorf("pbm restore error: %w", err)
if cmdErr != nil {
if strings.HasSuffix(cmdErr.Error(), "another operation in progress") && retryCount > 0 {
retryCount--
return false, nil
}

restoreOutput.StartedAt = startTime
return &restoreOutput, nil

case <-ctx.Done():
return nil, ctx.Err()
return false, fmt.Errorf("pbm restore error: %w", cmdErr)
}

restoreOutput.StartedAt = startTime
return true, nil
})
if err != nil {
return nil, err
}

return &restoreOutput, nil
}
Loading
Loading