From c2c5c9a3fbb398f4200c8b442f92026789b18fb5 Mon Sep 17 00:00:00 2001 From: Senyo Simpson Date: Mon, 17 Nov 2025 16:25:42 +0200 Subject: [PATCH 1/3] neutralise archive command --- internal/pgbackrest/postgres.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/pgbackrest/postgres.go b/internal/pgbackrest/postgres.go index a8bce592fa..855e745022 100644 --- a/internal/pgbackrest/postgres.go +++ b/internal/pgbackrest/postgres.go @@ -39,7 +39,8 @@ func PostgreSQL( outParameters.Mandatory.Add("archive_mode", "on") if backupsEnabled { - outParameters.Mandatory.Add("archive_command", archive) + // outParameters.Mandatory.Add("archive_command", archive) + outParameters.Mandatory.Add("archive_command", `true`) } else { // If backups are disabled, keep archive_mode on (to avoid a Postgres restart) // and throw away WAL. From 2618c81896b631a366226cbe958acc8fa12a9161 Mon Sep 17 00:00:00 2001 From: Senyo Simpson Date: Mon, 17 Nov 2025 17:11:43 +0200 Subject: [PATCH 2/3] akshually, don't add the regex part --- internal/pgbackrest/postgres.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/pgbackrest/postgres.go b/internal/pgbackrest/postgres.go index 855e745022..8db988e7f6 100644 --- a/internal/pgbackrest/postgres.go +++ b/internal/pgbackrest/postgres.go @@ -29,18 +29,17 @@ func PostgreSQL( // - https://pgbackrest.org/command.html#command-archive-push // - https://www.postgresql.org/docs/current/runtime-config-wal.html - fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"` - extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + `` - validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"` + // fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"` + // extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + `` + // validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"` archive := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-push "%p"` - archive += ` && timestamp=$(pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);` - archive += ` if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi` + // archive += ` && timestamp=$(pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);` + // archive += ` if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi` outParameters.Mandatory.Add("archive_mode", "on") if backupsEnabled { - // outParameters.Mandatory.Add("archive_command", archive) - outParameters.Mandatory.Add("archive_command", `true`) + outParameters.Mandatory.Add("archive_command", archive) } else { // If backups are disabled, keep archive_mode on (to avoid a Postgres restart) // and throw away WAL. From 5cd59edcea692de4cab50e6cbea0d26a08a28905 Mon Sep 17 00:00:00 2001 From: Senyo Simpson Date: Mon, 17 Nov 2025 20:09:07 +0200 Subject: [PATCH 3/3] make it error if there are failures, especially in the regex --- internal/pgbackrest/postgres.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/pgbackrest/postgres.go b/internal/pgbackrest/postgres.go index 8db988e7f6..462713b186 100644 --- a/internal/pgbackrest/postgres.go +++ b/internal/pgbackrest/postgres.go @@ -29,12 +29,14 @@ func PostgreSQL( // - https://pgbackrest.org/command.html#command-archive-push // - https://www.postgresql.org/docs/current/runtime-config-wal.html - // fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"` - // extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + `` - // validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"` - archive := `pgbackrest --stanza=` + DefaultStanzaName + ` archive-push "%p"` - // archive += ` && timestamp=$(pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);` - // archive += ` if [ ! -z ${timestamp} ]; then echo ${timestamp} > /pgdata/latest_commit_timestamp.txt; fi` + fixTimezone := `sed -E "s/([0-9]{4}-[0-9]{2}-[0-9]{2}) ([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}) (UTC|[\\+\\-][0-9]{2})/\1T\2\3/" | sed "s/UTC/Z/"` + extractCommitTime := `grep -oP "COMMIT \K[^;]+" | ` + fixTimezone + `` + validateCommitTime := `grep -E "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{6}(Z|[\+\-][0-9]{2})$"` + + archive := `set -e; set -o pipefail; pgbackrest --stanza=` + DefaultStanzaName + ` archive-push "%p"` + archive += ` && timestamp=$(set -o pipefail; pg_waldump "%p" | ` + extractCommitTime + ` | tail -n 1 | ` + validateCommitTime + `);` + archive += ` if [ -z "${timestamp}" ]; then echo "ERROR: Failed to extract valid commit timestamp" >&2; exit 1; fi;` + archive += ` echo "${timestamp}" > /pgdata/latest_commit_timestamp.txt` outParameters.Mandatory.Add("archive_mode", "on")