Skip to content

Commit 6d746c9

Browse files
committed
Fix --target Option Detection for Restores
A regex is now used to determine whether or not a "--target" flag already exists in the options provided for a pgBackRest restore. This avoids conflicts with other options containing the string "target" (e.g. "--target-action"), therefore ensuring the PITR target is properly injected into the pgBackRest options as needed. Issue: [ch9162]
1 parent ba2b53e commit 6d746c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/operator/backrest/restore.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package backrest
1818
import (
1919
"errors"
2020
"fmt"
21+
"regexp"
2122
"strconv"
2223
"strings"
2324
"time"
@@ -35,6 +36,10 @@ import (
3536
"k8s.io/apimachinery/pkg/util/wait"
3637
)
3738

39+
// restoreTargetRegex defines a regex to detect if a restore target has been specified
40+
// for pgBackRest using the '--target' option
41+
var restoreTargetRegex = regexp.MustCompile("--target(=| +)")
42+
3843
type BackrestRestoreJobTemplateFields struct {
3944
JobName string
4045
ClusterName string
@@ -67,7 +72,7 @@ func UpdatePGClusterSpecForRestore(clientset kubeapi.Interface, cluster *crv1.Pg
6772

6873
// set the proper target for the restore job
6974
pitrTarget := task.Spec.Parameters[config.LABEL_BACKREST_PITR_TARGET]
70-
if pitrTarget != "" && !strings.Contains(restoreOpts, "--target") {
75+
if pitrTarget != "" && !restoreTargetRegex.MatchString(restoreOpts) {
7176
restoreOpts = fmt.Sprintf("%s --target=%s", restoreOpts, strconv.Quote(pitrTarget))
7277
}
7378

0 commit comments

Comments
 (0)