Skip to content

Commit a9ba9ff

Browse files
committed
support backward compability with old env variables
1 parent 908c6db commit a9ba9ff

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

ENVIRONMENT.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Environment Configuration Settings
1515
- **CLONE_TARGET_TIMELINE**: timeline id of the backup for restore, 'latest' by default.
1616
- **CRONTAB**: anything that you want to run periodically as a cron job (empty by default)
1717
- **PGROOT**: a directory where we put the pgdata (by default /home/postgres/pgroot). One may adjust it to point to the mount point of the persistent volume, such as EBS.
18-
- **WALG_TMPDIR**: directory to store WAL-G temporary files. PGROOT/../tmp by default, make sure it has a few GBs of free space.
18+
- **WALE_TMPDIR** or **WALG_TMPDIR**: directory to store WAL-G temporary files. PGROOT/../tmp by default, make sure it has a few GBs of free space.
1919
- **PGDATA**: location of PostgreSQL data directory, by default PGROOT/pgdata.
2020
- **PGUSER_STANDBY**: username for the replication user, 'standby' by default.
2121
- **PGPASSWORD_STANDBY**: a password for the replication user, 'standby' by default.
@@ -47,19 +47,19 @@ Environment Configuration Settings
4747
- **SSL_RESTAPI_PRIVATE_KEY**: content of the REST Api SSL private key in the SSL_PRIVATE_KEY_FILE file (by default /run/certs/server.key).
4848
- **SSL_TEST_RELOAD**: whenever to test for certificate rotation and reloading (by default True if SSL_PRIVATE_KEY_FILE has been set).
4949
- **RESTAPI_CONNECT_ADDRESS**: when you configure Patroni RESTAPI in SSL mode some safe API (i.e. switchover) perform hostname validation. In this case could be convenient configure ````restapi.connect_address````as a hostname instead of IP. For example, you can configure it as "$(POD_NAME).<service name>".
50-
- **WALG_BACKUP_THRESHOLD_MEGABYTES**: maximum size of the WAL segments accumulated after the base backup to consider WAL-G restore instead of pg_basebackup.
51-
- **WALG_BACKUP_THRESHOLD_PERCENTAGE**: maximum ratio (in percents) of the accumulated WAL files to the base backup to consider WAL-G restore instead of pg_basebackup.
52-
- **WALG_ENV_DIR**: directory where to store WAL-G environment variables
50+
- **WALG_BACKUP_THRESHOLD_MEGABYTES** or **WALE_BACKUP_THRESHOLD_MEGABYTES**: maximum size of the WAL segments accumulated after the base backup to consider WAL-G restore instead of pg_basebackup.
51+
- **WALG_BACKUP_THRESHOLD_PERCENTAGE** or **WALE_BACKUP_THRESHOLD_PERCENTAGE**: maximum ratio (in percents) of the accumulated WAL files to the base backup to consider WAL-G restore instead of pg_basebackup.
52+
- **WALG_ENV_DIR** or **WALE_ENV_DIR**: directory where to store WAL-G environment variables
5353
- **WAL_RESTORE_TIMEOUT**: timeout (in seconds) for restoring a single WAL file (at most 16 MB) from the backup location, 0 by default. A duration of 0 disables the timeout.
5454
- **WAL_S3_BUCKET**: (optional) name of the S3 bucket used for WAL-G base backups.
5555
- **AWS_ACCESS_KEY_ID**: (optional) aws access key
5656
- **AWS_SECRET_ACCESS_KEY**: (optional) aws secret key
5757
- **AWS_REGION**: (optional) region of S3 bucket
5858
- **AWS_ENDPOINT**: (optional) in format 'https://s3.AWS_REGION.amazonaws.com:443', if not specified will be calculated from AWS_REGION
59-
- **WALG_S3_ENDPOINT**: (optional) in format 'https+path://s3.AWS_REGION.amazonaws.com:443', if not specified will be calculated from AWS_ENDPOINT or AWS_REGION
60-
- **WALG_S3_PREFIX**: (optional) the full path to the backup location on S3 in the format s3://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_S3_BUCKET.
59+
- **WALG_S3_ENDPOINT** or **WALE_S3_ENDPOINT**: (optional) in format 'https+path://s3.AWS_REGION.amazonaws.com:443', if not specified will be calculated from AWS_ENDPOINT or AWS_REGION
60+
- **WALG_S3_PREFIX** or **WALE_S3_PREFIX**: (optional) the full path to the backup location on S3 in the format s3://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_S3_BUCKET.
6161
- **WAL_GS_BUCKET**: ditto for the Google Cloud Storage (WAL-G supports both S3 and GCS).
62-
- **WALG_GS_PREFIX**: (optional) the full path to the backup location on the Google Cloud Storage in the format gs://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_GS_BUCKET.
62+
- **WALG_GS_PREFIX** or **WALE_GS_PREFIX**: (optional) the full path to the backup location on the Google Cloud Storage in the format gs://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_GS_BUCKET.
6363
- **GOOGLE_APPLICATION_CREDENTIALS**: credentials for WAL-G when running in Google Cloud.
6464
- **WAL_SWIFT_BUCKET**: ditto for the OpenStack Object Storage (Swift)
6565
- **SWIFT_AUTHURL**: see wal-g documentation https://wal-g.readthedocs.io/STORAGES/#swift
@@ -79,7 +79,7 @@ Environment Configuration Settings
7979
- **SWIFT_PROJECT_ID**:
8080
- **SWIFT_PROJECT_DOMAIN_NAME**:
8181
- **SWIFT_PROJECT_DOMAIN_ID**:
82-
- **WALG_SWIFT_PREFIX**: (optional) the full path to the backup location on the Swift Storage in the format swift://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_SWIFT_BUCKET.
82+
- **WALG_SWIFT_PREFIX** or **WALE_SWIFT_PREFIX**: (optional) the full path to the backup location on the Swift Storage in the format swift://bucket-name/very/long/path. If not specified Spilo will generate it from WAL_SWIFT_BUCKET.
8383
- **SSH_USERNAME**: (optional) the username for WAL backups.
8484
- **SSH_PORT**: (optional) the ssh port for WAL backups.
8585
- **SSH_PRIVATE_KEY_PATH**: (optional) the path to the private key used for WAL backups.
@@ -109,7 +109,7 @@ Environment Configuration Settings
109109
- **KUBERNETES_BOOTSTRAP_LABELS**: a JSON describing names and values of labels used by Patroni as ``kubernetes.bootstrap_labels``. Default is empty.
110110
- **INITDB_LOCALE**: database cluster's default UTF-8 locale (en_US by default)
111111
- **ENABLE_WAL_PATH_COMPAT**: old Spilo images were generating wal path in the backup store using the following template ``/spilo/{WAL_BUCKET_SCOPE_PREFIX}{SCOPE}{WAL_BUCKET_SCOPE_SUFFIX}/wal/``, while new images adding one additional directory (``{PGVERSION}``) to the end. In order to avoid (unlikely) issues with restoring WALs (from S3/GC/and so on) when switching to ``spilo-13`` please set the ``ENABLE_WAL_PATH_COMPAT=true`` when deploying old cluster with ``spilo-13`` for the first time. After that the environment variable could be removed. Change of the WAL path also mean that backups stored in the old location will not be cleaned up automatically.
112-
- **WALG_DISABLE_S3_SSE**: by default wal-g is configured to encrypt files uploaded to S3. In order to disable it you can set this environment variable to ``true``.
112+
- **WALG_DISABLE_S3_SSE** or **WALE_DISABLE_S3_SSE**: by default wal-g is configured to encrypt files uploaded to S3. In order to disable it you can set this environment variable to ``true``.
113113
- **USE_OLD_LOCALES**: whether to use old locales from Ubuntu 18.04 in the Ubuntu 22.04-based image. Default is false.
114114

115115
wal-g

postgres-appliance/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ENV LC_ALL=en_US.utf-8 \
100100
RW_DIR=/run \
101101
DEMO=$DEMO
102102

103-
ENV WALG_ENV_DIR=$RW_DIR/etc/wal-g.d/env \
103+
ENV WALG_ENV_DIR=$RW_DIR/etc/wal-e.d/env \
104104
LOG_ENV_DIR=$RW_DIR/etc/log.d/env \
105105
PGROOT=$PGHOME/pgdata/pgroot
106106

postgres-appliance/launch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ chmod -R go-w "$PGROOT"
5151
chmod 01777 "$RW_DIR/tmp"
5252
chmod 0700 "$PGDATA"
5353

54+
WALG_ENV_DIR="${WALG_ENV_DIR:-$WALE_ENV_DIR}"
5455
if [ "$DEMO" = "true" ]; then
5556
python3 /scripts/configure_spilo.py patroni pgqd certificate pam-oauth2
5657
elif python3 /scripts/configure_spilo.py all; then

postgres-appliance/scripts/configure_spilo.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def set_extended_walg_placeholders(placeholders, prefix):
496496
return False
497497
scope = placeholders.get(prefix + 'SCOPE')
498498
dirname = 'env-' + prefix[:-1].lower() + ('-' + scope if scope else '')
499-
placeholders[prefix + 'WALG_ENV_DIR'] = os.path.join(placeholders['RW_DIR'], 'etc', 'wal-g.d', dirname)
499+
placeholders[prefix + 'WALG_ENV_DIR'] = os.path.join(placeholders['RW_DIR'], 'etc', 'wal-e.d', dirname)
500500
placeholders[prefix + 'WITH_WALG'] = True
501501
return name
502502

@@ -533,7 +533,7 @@ def get_placeholders(provider):
533533
placeholders.setdefault('BACKUP_NUM_TO_RETAIN', '5')
534534
placeholders.setdefault('CRONTAB', '[]')
535535
placeholders.setdefault('PGROOT', os.path.join(placeholders['PGHOME'], 'pgroot'))
536-
placeholders.setdefault('WALG_TMPDIR', os.path.abspath(os.path.join(placeholders['PGROOT'], '../tmp')))
536+
placeholders.setdefault('WALG_TMPDIR', placeholders.get('WALE_TMPDIR', os.path.abspath(os.path.join(placeholders['PGROOT'], '../tmp'))))
537537
placeholders.setdefault('PGDATA', os.path.join(placeholders['PGROOT'], 'pgdata'))
538538
placeholders.setdefault('HUMAN_ROLE', 'zalandos')
539539
placeholders.setdefault('PGUSER_STANDBY', 'standby')
@@ -556,8 +556,8 @@ def get_placeholders(provider):
556556
placeholders.setdefault('SSL_RESTAPI_CA_FILE', '')
557557
placeholders.setdefault('SSL_RESTAPI_CERTIFICATE_FILE', '')
558558
placeholders.setdefault('SSL_RESTAPI_PRIVATE_KEY_FILE', '')
559-
placeholders.setdefault('WALG_BACKUP_THRESHOLD_MEGABYTES', 102400)
560-
placeholders.setdefault('WALG_BACKUP_THRESHOLD_PERCENTAGE', 30)
559+
placeholders.setdefault('WALG_BACKUP_THRESHOLD_MEGABYTES', placeholders.get('WALE_BACKUP_THRESHOLD_MEGABYTES', 102400))
560+
placeholders.setdefault('WALG_BACKUP_THRESHOLD_PERCENTAGE', placeholders.get('WALE_BACKUP_THRESHOLD_PERCENTAGE', 30))
561561
placeholders.setdefault('INITDB_LOCALE', 'en_US')
562562
placeholders.setdefault('CLONE_TARGET_TIMELINE', 'latest')
563563
# if Kubernetes is defined as a DCS, derive the namespace from the POD_NAMESPACE, if not set explicitely.
@@ -570,10 +570,10 @@ def get_placeholders(provider):
570570
if placeholders['NAMESPACE'] not in ('default', '') else '')
571571
placeholders.setdefault('WAL_BUCKET_SCOPE_SUFFIX', '')
572572
placeholders.setdefault('WAL_RESTORE_TIMEOUT', '0')
573-
placeholders.setdefault('WALG_ENV_DIR', os.path.join(placeholders['RW_DIR'], 'etc', 'wal-g.d', 'env'))
573+
placeholders.setdefault('WALG_ENV_DIR', placeholders.get('WALE_ENV_DIR', os.path.join(placeholders['RW_DIR'], 'etc', 'wal-e.d', 'env')))
574574
cpu_count = str(min(psutil.cpu_count(), 10))
575-
placeholders.setdefault('WALG_DOWNLOAD_CONCURRENCY', cpu_count)
576-
placeholders.setdefault('WALG_UPLOAD_CONCURRENCY', cpu_count)
575+
placeholders.setdefault('WALG_DOWNLOAD_CONCURRENCY', placeholders.get('WALE_DOWNLOAD_CONCURRENCY', cpu_count))
576+
placeholders.setdefault('WALG_UPLOAD_CONCURRENCY', placeholders.get('WALE_UPLOAD_CONCURRENCY', cpu_count))
577577
placeholders.setdefault('PAM_OAUTH2', '')
578578
placeholders.setdefault('CALLBACK_SCRIPT', '')
579579
placeholders.setdefault('DCS_ENABLE_KUBERNETES_API', '')
@@ -587,8 +587,11 @@ def get_placeholders(provider):
587587
placeholders.setdefault('KUBERNETES_BYPASS_API_SERVICE', 'true')
588588
placeholders.setdefault('KUBERNETES_BOOTSTRAP_LABELS', '{}')
589589
placeholders.setdefault('USE_PAUSE_AT_RECOVERY_TARGET', False)
590-
placeholders.setdefault('CLONE_METHOD', '')
591-
placeholders.setdefault('CLONE_WITH_WALG', '')
590+
placeholders["CLONE_METHOD"] = (
591+
"CLONE_WITH_WALG" if placeholders.setdefault("CLONE_METHOD", "") == "CLONE_WITH_WALE"
592+
else placeholders["CLONE_METHOD"]
593+
)
594+
placeholders.setdefault('CLONE_WITH_WALG', placeholders.get('CLONE_WITH_WALE', ''))
592595
placeholders.setdefault('CLONE_WITH_BASEBACKUP', '')
593596
placeholders.setdefault('CLONE_TARGET_TIME', '')
594597
placeholders.setdefault('CLONE_TARGET_INCLUSIVE', True)
@@ -631,7 +634,7 @@ def get_placeholders(provider):
631634
else:
632635
set_extended_walg_placeholders(placeholders, 'STANDBY_')
633636

634-
placeholders.setdefault('STANDBY_WITH_WALG', '')
637+
placeholders.setdefault('STANDBY_WITH_WALG', placeholders.get('STANDBY_WITH_WALE', ''))
635638
placeholders.setdefault('STANDBY_HOST', '')
636639
placeholders.setdefault('STANDBY_PORT', '')
637640
placeholders.setdefault('STANDBY_PRIMARY_SLOT_NAME', '')
@@ -645,7 +648,8 @@ def get_placeholders(provider):
645648

646649
# check if we have enough parameters to enable WAL-G
647650
placeholders['USE_WALG'] = any(placeholders.get(n) for n in AUTO_ENABLE_WALG_RESTORE +
648-
('WAL_SWIFT_BUCKET', 'WAL_GCS_BUCKET', 'WAL_GS_BUCKET', 'WALG_GS_PREFIX'))
651+
('WAL_SWIFT_BUCKET', 'WAL_GCS_BUCKET', 'WAL_GS_BUCKET', 'WALG_GS_PREFIX') +
652+
('WALE_GS_PREFIX', 'WALE_S3_PREFIX', 'WALE_AZ_PREFIX', 'WALE_SSH_PREFIX'))
649653

650654
if placeholders.get('WALG_BACKUP_FROM_REPLICA'):
651655
placeholders['WALG_BACKUP_FROM_REPLICA'] = str(placeholders['WALG_BACKUP_FROM_REPLICA']).lower()
@@ -851,7 +855,10 @@ def write_walg_environment(placeholders, prefix, overwrite):
851855
'WAL_S3_BUCKET', 'WAL_GCS_BUCKET', 'WAL_GS_BUCKET', 'WAL_SWIFT_BUCKET', 'BACKUP_NUM_TO_RETAIN',
852856
'ENABLE_WAL_PATH_COMPAT'] + s3_names + swift_names + gs_names + walg_names + azure_names + \
853857
azure_auth_names + ssh_names:
854-
walg[name] = placeholders.get(prefix + name, '')
858+
if "WALG" in name: # check if it is set as WALE_
859+
walg[name] = placeholders.get(prefix + name, placeholders.get(prefix + name.replace("WALG", "WALE"), ''))
860+
else:
861+
walg[name] = placeholders.get(prefix + name, '')
855862

856863
if walg.get('WAL_S3_BUCKET') or walg.get('WALG_S3_PREFIX'):
857864
walg_endpoint = walg.pop('WALG_S3_ENDPOINT', None)

postgres-appliance/scripts/postgres_backup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ else
2323
log "ERROR: Recovery state unknown: $IN_RECOVERY" && exit 1
2424
fi
2525

26-
[[ -z $WALG_BACKUP_COMPRESSION_METHOD ]] || export WALG_COMPRESSION_METHOD=$WALG_BACKUP_COMPRESSION_METHOD
26+
export WALG_COMPRESSION_METHOD="${WALG_BACKUP_COMPRESSION_METHOD:-$WALE_BACKUP_COMPRESSION_METHOD}"
2727
export PGHOST=/var/run/postgresql
2828

2929
# push a new base backup

postgres-appliance/tests/test_spilo.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function wait_backup() {
5454

5555
# speed up backup creation
5656
local backup_starter_pid
57-
backup_starter_pid=$(docker exec "$container" pgrep -f '/bin/bash /scripts/patroni_wait.sh -t 3600 -- envdir /run/etc/wal-g.d/env /scripts/postgres_backup.sh')
57+
backup_starter_pid=$(docker exec "$container" pgrep -f '/bin/bash /scripts/patroni_wait.sh -t 3600 -- envdir /run/etc/wal-e.d/env /scripts/postgres_backup.sh')
5858
if [ -n "$backup_starter_pid" ]; then
5959
docker exec "$container" pkill -P "$backup_starter_pid" -f 'sleep 60'
6060
fi
@@ -66,7 +66,7 @@ function wait_backup() {
6666
docker_exec -i "$1" "psql -U postgres -c CHECKPOINT" > /dev/null 2>&1
6767

6868
while true; do
69-
count=$(docker_exec "$container" "envdir /run/etc/wal-g.d/env wal-g backup-list" | grep -c ^base)
69+
count=$(docker_exec "$container" "envdir /run/etc/wal-e.d/env wal-e backup-list" | grep -c ^base)
7070
if [[ "$count" -gt 0 ]]; then
7171
return
7272
fi
@@ -136,8 +136,8 @@ function test_successful_inplace_upgrade_to_14() {
136136
}
137137

138138
function test_envdir_suffix() {
139-
docker_exec "$1" "cat /run/etc/wal-g.d/env/WALG_S3_PREFIX" | grep -q "$2$" \
140-
&& docker_exec "$1" "cat /run/etc/wal-g.d/env/WALG_S3_PREFIX" | grep -q "$2$"
139+
docker_exec "$1" "cat /run/etc/wal-e.d/env/WALG_S3_PREFIX" | grep -q "$2$" \
140+
&& docker_exec "$1" "cat /run/etc/wal-e.d/env/WALG_S3_PREFIX" | grep -q "$2$"
141141
}
142142

143143
function test_envdir_updated_to_x() {

0 commit comments

Comments
 (0)