Skip to content

Commit f2dd591

Browse files
committed
Look in more directories for restore binaries
This makes restores compatible with images from other distros. Issue: PGO-864
1 parent 1f74cae commit f2dd591

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ func (r *Reconciler) reconcileRestoreJob(ctx context.Context,
12681268

12691269
// NOTE (andrewlecuyer): Forcing users to put each argument separately might prevent the need
12701270
// to do any escaping or use eval.
1271-
cmd := pgbackrest.RestoreCommand(pgdata, params, strings.Join(opts, " "))
1271+
cmd := pgbackrest.RestoreCommand(cluster.Spec.PostgresVersion, pgdata, params, strings.Join(opts, " "))
12721272

12731273
// create the volume resources required for the postgres data directory
12741274
dataVolumeMount := postgres.DataVolumeMount()

internal/pgbackrest/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
212212
// - Renames the data directory as needed to bootstrap the cluster using the restored database.
213213
// This ensures compatibility with the "existing" bootstrap method that is included in the
214214
// Patroni config when bootstrapping a cluster using an existing data directory.
215-
func RestoreCommand(pgdata string, params *postgres.ParameterSet, args ...string) []string {
215+
func RestoreCommand(postgresVersion int32, pgdata string, params *postgres.ParameterSet, args ...string) []string {
216216
ps := params.DeepCopy()
217217
ps.Add("data_directory", pgdata)
218218

@@ -266,6 +266,7 @@ func RestoreCommand(pgdata string, params *postgres.ParameterSet, args ...string
266266

267267
script := strings.Join([]string{
268268
`declare -r PGDATA="$1" opts="$2"; export PGDATA PGHOST`,
269+
postgres.ShellPath(postgresVersion),
269270

270271
// Remove any "postmaster.pid" file leftover from a prior failure.
271272
`rm -f "${PGDATA}/postmaster.pid"`,

internal/pgbackrest/config_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,14 @@ func TestReloadCommandPrettyYAML(t *testing.T) {
790790
func TestRestoreCommand(t *testing.T) {
791791
shellcheck := require.ShellCheck(t)
792792

793-
command := RestoreCommand("/pgdata/pg13", postgres.NewParameterSet(), "--repo=1")
793+
command := RestoreCommand(19, "/pgdata/pg13", postgres.NewParameterSet(), "--repo=1")
794794

795795
assert.DeepEqual(t, command[:3], []string{"bash", "-ceu", "--"})
796796
assert.Assert(t, len(command) > 3)
797797

798+
assert.Assert(t, cmp.Contains(command[3], "/usr/pgsql-19/bin"),
799+
"expected path to PostgreSQL binaries")
800+
798801
dir := t.TempDir()
799802
file := filepath.Join(dir, "script.bash")
800803
assert.NilError(t, os.WriteFile(file, []byte(command[3]), 0o600))
@@ -807,7 +810,7 @@ func TestRestoreCommand(t *testing.T) {
807810
func TestRestoreCommandPrettyYAML(t *testing.T) {
808811
assert.Assert(t,
809812
cmp.MarshalContains(
810-
RestoreCommand("/dir", postgres.NewParameterSet(), "--options"),
813+
RestoreCommand(9, "/dir", postgres.NewParameterSet(), "--options"),
811814
"\n- |",
812815
),
813816
"expected literal block scalar")
@@ -819,7 +822,7 @@ func TestRestoreCommandTDE(t *testing.T) {
819822

820823
assert.Assert(t,
821824
cmp.MarshalContains(
822-
RestoreCommand("/dir", params, "--options"),
825+
RestoreCommand(20, "/dir", params, "--options"),
823826
"encryption_key_command = 'whatever'",
824827
),
825828
"expected encryption_key_command setting")

0 commit comments

Comments
 (0)