9
9
"context"
10
10
"fmt"
11
11
"io"
12
- "strings"
13
12
14
13
"github.com/pkg/errors"
15
14
@@ -24,10 +23,6 @@ const (
24
23
// errMsgStaleReposWithVolumesConfig is the error message displayed when a volume-backed repo has been
25
24
// configured, but the configuration has not yet propagated into the container.
26
25
errMsgStaleReposWithVolumesConfig = "postgres operator error: pgBackRest stale volume-backed repo configuration"
27
-
28
- // errMsgBackupDbMismatch is the error message returned from pgBackRest when PG versions
29
- // or PG system identifiers do not match between the PG instance and the existing stanza
30
- errMsgBackupDbMismatch = "backup and archive info files exist but do not match the database"
31
26
)
32
27
33
28
// Executor calls "pgbackrest" commands
@@ -46,15 +41,10 @@ type Executor func(
46
41
// from running (with a config mismatch indicating that the pgBackRest configuration as stored in
47
42
// the cluster's pgBackRest ConfigMap has not yet propagated to the Pod).
48
43
func (exec Executor ) StanzaCreateOrUpgrade (ctx context.Context , configHash string ,
49
- upgrade bool , postgresCluster * v1beta1.PostgresCluster ) (bool , error ) {
44
+ postgresCluster * v1beta1.PostgresCluster ) (bool , error ) {
50
45
51
46
var stdout , stderr bytes.Buffer
52
47
53
- stanzaCmd := "create"
54
- if upgrade {
55
- stanzaCmd = "upgrade"
56
- }
57
-
58
48
var reposWithVolumes []v1beta1.PGBackRestRepo
59
49
for _ , repo := range postgresCluster .Spec .Backups .PGBackRest .Repos {
60
50
if repo .Volume != nil {
@@ -83,18 +73,18 @@ func (exec Executor) StanzaCreateOrUpgrade(ctx context.Context, configHash strin
83
73
// Otherwise, it runs the pgbackrest command, which will either be "stanza-create" or
84
74
// "stanza-upgrade", depending on the value of the boolean "upgrade" parameter.
85
75
const script = `
86
- declare -r hash="$1" stanza="$2" hash_msg="$3" vol_msg="$4" cmd="$5" check_repo_cmd="$6 "
76
+ declare -r hash="$1" stanza="$2" hash_msg="$3" vol_msg="$4" check_repo_cmd="$5 "
87
77
if [[ "$(< /etc/pgbackrest/conf.d/config-hash)" != "${hash}" ]]; then
88
78
printf >&2 "%s" "${hash_msg}"; exit 1;
89
79
elif ! bash -c "${check_repo_cmd}"; then
90
80
printf >&2 "%s" "${vol_msg}"; exit 1;
91
81
else
92
- pgbackrest "${cmd}" --stanza="${stanza}"
82
+ pgbackrest stanza-create --stanza= "${stanza}" || pgbackrest stanza-upgrade --stanza="${stanza}"
93
83
fi
94
84
`
95
85
if err := exec (ctx , nil , & stdout , & stderr , "bash" , "-ceu" , "--" ,
96
86
script , "-" , configHash , DefaultStanzaName , errMsgConfigHashMismatch , errMsgStaleReposWithVolumesConfig ,
97
- fmt . Sprintf ( "stanza-%s" , stanzaCmd ), checkRepoCmd ); err != nil {
87
+ checkRepoCmd ); err != nil {
98
88
99
89
errReturn := stderr .String ()
100
90
111
101
return true , nil
112
102
}
113
103
114
- // if the err returned from pgbackrest command is about a version mismatch
115
- // then we should run upgrade rather than create
116
- if strings .Contains (errReturn , errMsgBackupDbMismatch ) {
117
- return exec .StanzaCreateOrUpgrade (ctx , configHash , true , postgresCluster )
118
- }
119
-
120
104
// if none of the above errors, return the err
121
105
return false , errors .WithStack (fmt .Errorf ("%w: %v" , err , errReturn ))
122
106
}
0 commit comments