Skip to content

Commit b4ffda5

Browse files
authored
Remove WAL-E and make WAL-G the default backup tool (#1143)
1 parent c944b47 commit b4ffda5

File tree

15 files changed

+269
-557
lines changed

15 files changed

+269
-557
lines changed

ENVIRONMENT.rst

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ Environment Configuration Settings
1111
- **ETCD_KEY**: Etcd client certificate key. Can be empty if the key is part of certificate.
1212
- **PGHOME**: filesystem path where to put PostgreSQL home directory (/home/postgres by default)
1313
- **APIPORT**: TCP port to Patroni API connections (8008 by default)
14-
- **BACKUP_SCHEDULE**: cron schedule for doing backups via WAL-E (if WAL-E is enabled, '00 01 * * *' by default)
14+
- **BACKUP_SCHEDULE**: cron schedule for doing backups via WAL-G ('00 01 * * *' by default)
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-
- **WALE_TMPDIR**: directory to store WAL-E 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,22 +47,22 @@ 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-
- **WALE_BACKUP_THRESHOLD_MEGABYTES**: maximum size of the WAL segments accumulated after the base backup to consider WAL-E restore instead of pg_basebackup.
51-
- **WALE_BACKUP_THRESHOLD_PERCENTAGE**: maximum ratio (in percents) of the accumulated WAL files to the base backup to consider WAL-E restore instead of pg_basebackup.
52-
- **WALE_ENV_DIR**: directory where to store WAL-E 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.
54-
- **WAL_S3_BUCKET**: (optional) name of the S3 bucket used for WAL-E base backups.
54+
- **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-
- **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-
- **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.
61-
- **WAL_GS_BUCKET**: ditto for the Google Cloud Storage (WAL-E supports both S3 and GCS).
62-
- **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.
63-
- **GOOGLE_APPLICATION_CREDENTIALS**: credentials for WAL-E when running in Google Cloud.
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.
61+
- **WAL_GS_BUCKET**: ditto for the Google Cloud Storage (WAL-G supports both S3 and GCS).
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.
63+
- **GOOGLE_APPLICATION_CREDENTIALS**: credentials for WAL-G when running in Google Cloud.
6464
- **WAL_SWIFT_BUCKET**: ditto for the OpenStack Object Storage (Swift)
65-
- **SWIFT_AUTHURL**: see wal-e documentation https://github.com/wal-e/wal-e#swift
65+
- **SWIFT_AUTHURL**: see wal-g documentation https://wal-g.readthedocs.io/STORAGES/#swift
6666
- **SWIFT_TENANT**:
6767
- **SWIFT_TENANT_ID**:
6868
- **SWIFT_USER**:
@@ -79,7 +79,7 @@ Environment Configuration Settings
7979
- **SWIFT_PROJECT_ID**:
8080
- **SWIFT_PROJECT_DOMAIN_NAME**:
8181
- **SWIFT_PROJECT_DOMAIN_ID**:
82-
- **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.
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,18 +109,17 @@ 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-
- **WALE_DISABLE_S3_SSE**, **WALG_DISABLE_S3_SSE**: by default wal-e/wal-g are 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
116116
-----
117117

118-
`wal-g` is used by default for Azure and SSH backups and restore.
119-
In case of S3, `wal-e` is used for backups and `wal-g` for restore.
120-
121-
- **USE_WALG_BACKUP**: (optional) Enforce using `wal-g` instead of `wal-e` for backups (Boolean)
122-
- **USE_WALG_RESTORE**: (optional) Enforce using `wal-g` instead of `wal-e` for restores (Boolean)
123-
118+
wal-g is used everywhere in Spilo to perform backups and restore from them. **Support for wal-e has been removed**.
119+
Backward compatibility is ensured for environment variables containing **WALE**, the env-dir layout, and bootstrap method names.
120+
This allows existing configurations and clusters to continue working without requiring immediate changes.
121+
Regardless of which variable is set, all backups and restores will be performed using wal-g.
122+
However, if both **WALE** and **WALG** variables are present, the latter will take precedence.
124123
- **WALG_DELTA_MAX_STEPS**, **WALG_DELTA_ORIGIN**, **WALG_DOWNLOAD_CONCURRENCY**, **WALG_UPLOAD_CONCURRENCY**, **WALG_UPLOAD_DISK_CONCURRENCY**, **WALG_DISK_RATE_LIMIT**, **WALG_NETWORK_RATE_LIMIT**, **WALG_COMPRESSION_METHOD**, **WALG_BACKUP_COMPRESSION_METHOD**, **WALG_BACKUP_FROM_REPLICA**, **WALG_SENTINEL_USER_DATA**, **WALG_PREVENT_WAL_OVERWRITE**: (optional) configuration options for wal-g.
125124
- **WALG_S3_CA_CERT_FILE**: (optional) TLS CA certificate for wal-g (see [wal-g configuration](https://github.com/wal-g/wal-g#configuration))
126125
- **WALG_SSH_PREFIX**: (optional) the ssh prefix to store WAL backups at in the format ssh://host.example.com/path/to/backups/ See `Wal-g <https://github.com/wal-g/wal-g#configuration>`__ documentation for details.

postgres-appliance/Dockerfile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ RUN bash base.sh
6868
# Install wal-g
6969
COPY --from=dependencies-builder /builddeps/wal-g /usr/local/bin/
7070

71-
COPY build_scripts/patroni_wale.sh build_scripts/compress_build.sh /builddeps/
71+
COPY build_scripts/patroni.sh build_scripts/compress_build.sh /builddeps/
7272

73-
# Install patroni and wal-e
73+
# Install patroni
7474
ENV PATRONIVERSION=4.0.6
75-
ENV WALE_VERSION=1.1.1
7675

7776
WORKDIR /
7877

79-
RUN bash /builddeps/patroni_wale.sh
78+
RUN bash /builddeps/patroni.sh
8079

8180
RUN if [ "$COMPRESS" = "true" ]; then bash /builddeps/compress_build.sh; fi
8281

@@ -101,7 +100,7 @@ ENV LC_ALL=en_US.utf-8 \
101100
RW_DIR=/run \
102101
DEMO=$DEMO
103102

104-
ENV WALE_ENV_DIR=$RW_DIR/etc/wal-e.d/env \
103+
ENV WALG_ENV_DIR=$RW_DIR/etc/wal-e.d/env \
105104
LOG_ENV_DIR=$RW_DIR/etc/log.d/env \
106105
PGROOT=$PGHOME/pgdata/pgroot
107106

postgres-appliance/bootstrap/clone_with_wale.py renamed to postgres-appliance/bootstrap/clone_with_walg.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def read_configuration():
2525
parser.add_argument('--recovery-target-time',
2626
help='the timestamp up to which recovery will proceed (including time zone)',
2727
dest='recovery_target_time_string')
28-
parser.add_argument('--dry-run', action='store_true', help='find a matching backup and build the wal-e '
28+
parser.add_argument('--dry-run', action='store_true', help='find a matching backup and build the wal-g.'
2929
'command to fetch that backup without running it')
3030
args = parser.parse_args()
3131

@@ -40,8 +40,8 @@ def read_configuration():
4040
return options(args.scope, args.datadir, recovery_target_time, args.dry_run)
4141

4242

43-
def build_wale_command(command, datadir=None, backup=None):
44-
cmd = ['wal-g' if os.getenv('USE_WALG_RESTORE') == 'true' else 'wal-e'] + [command]
43+
def build_walg_command(command, datadir=None, backup=None):
44+
cmd = ['wal-g', command]
4545
if command == 'backup-fetch':
4646
if datadir is None or backup is None:
4747
raise Exception("backup-fetch requires datadir and backup arguments")
@@ -79,7 +79,7 @@ def choose_backup(backup_list, recovery_target_time):
7979

8080

8181
def list_backups(env):
82-
backup_list_cmd = build_wale_command('backup-list')
82+
backup_list_cmd = build_walg_command('backup-list')
8383
output = subprocess.check_output(backup_list_cmd, env=env)
8484
reader = csv.DictReader(fix_output(output), dialect='excel-tab')
8585
return list(reader)
@@ -89,7 +89,7 @@ def get_clone_envdir():
8989
from spilo_commons import get_patroni_config
9090

9191
config = get_patroni_config()
92-
restore_command = shlex.split(config['bootstrap']['clone_with_wale']['recovery_conf']['restore_command'])
92+
restore_command = shlex.split(config['bootstrap']['clone_with_walg']['recovery_conf']['restore_command'])
9393
if len(restore_command) > 4 and restore_command[0] == 'envdir':
9494
return restore_command[1]
9595
raise Exception('Failed to find clone envdir')
@@ -117,10 +117,9 @@ def get_possible_versions():
117117
return [ver for _, ver in sorted(versions.items(), reverse=True)]
118118

119119

120-
def get_wale_environments(env):
121-
use_walg = env.get('USE_WALG_RESTORE') == 'true'
122-
prefix = 'WALG_' if use_walg else 'WALE_'
123-
# len('WALE__PREFIX') = 12
120+
def get_walg_environments(env):
121+
prefix = 'WALG_'
122+
# len('WALG_PREFIX') = 12
124123
names = [name for name in env.keys() if name.endswith('_PREFIX') and name.startswith(prefix) and len(name) > 12]
125124
if len(names) != 1:
126125
raise Exception('Found find {0} {1}*_PREFIX environment variables, expected 1'
@@ -141,7 +140,7 @@ def get_wale_environments(env):
141140

142141
def find_backup(recovery_target_time, env):
143142
old_value = None
144-
for name, value in get_wale_environments(env):
143+
for name, value in get_walg_environments(env):
145144
logger.info('Trying %s for clone', value)
146145
if not old_value:
147146
old_value = env[name]
@@ -164,12 +163,12 @@ def run_clone_from_s3(options):
164163

165164
backup_name, update_envdir = find_backup(options.recovery_target_time, env)
166165

167-
backup_fetch_cmd = build_wale_command('backup-fetch', options.datadir, backup_name)
166+
backup_fetch_cmd = build_walg_command('backup-fetch', options.datadir, backup_name)
168167
logger.info("cloning cluster %s using %s", options.name, ' '.join(backup_fetch_cmd))
169168
if not options.dry_run:
170169
ret = subprocess.call(backup_fetch_cmd, env=env)
171170
if ret != 0:
172-
raise Exception("wal-e backup-fetch exited with exit code {0}".format(ret))
171+
raise Exception("wal-g backup-fetch exited with exit code {0}".format(ret))
173172

174173
if update_envdir: # We need to update file in the clone envdir or restore_command will fail!
175174
envdir = get_clone_envdir()

postgres-appliance/build_scripts/patroni_wale.sh renamed to postgres-appliance/build_scripts/patroni.sh

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

3-
## -------------------------
4-
## Install patroni and wal-e
5-
## -------------------------
3+
## ----------------
4+
## Install patroni
5+
## ----------------
66

77
export DEBIAN_FRONTEND=noninteractive
88

@@ -26,25 +26,17 @@ if [ "$DEMO" != "true" ]; then
2626
python3-etcd \
2727
python3-consul \
2828
python3-kazoo \
29-
python3-boto \
3029
python3-boto3 \
3130
python3-botocore \
3231
python3-cachetools \
33-
python3-cffi \
34-
python3-gevent \
3532
python3-pyasn1-modules \
3633
python3-rsa \
37-
python3-s3transfer \
38-
python3-swiftclient
34+
python3-s3transfer
3935

4036
find /usr/share/python-babel-localedata/locale-data -type f ! -name 'en_US*.dat' -delete
4137

42-
pip3 install filechunkio protobuf \
43-
'git+https://github.com/zalando-pg/wal-e.git@ipv6-imds#egg=wal-e[aws,google,swift]' \
38+
pip3 install protobuf \
4439
'git+https://github.com/zalando/pg_view.git@master#egg=pg-view'
45-
46-
# https://github.com/wal-e/wal-e/issues/318
47-
sed -i 's/^\( for i in range(0,\) num_retries):.*/\1 100):/g' /usr/lib/python3/dist-packages/boto/utils.py
4840
else
4941
EXTRAS=""
5042
fi

postgres-appliance/build_scripts/prepare.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ rm -fr /etc/cron.??*
1919
truncate --size 0 /etc/crontab
2020

2121
if [ "$DEMO" != "true" ]; then
22-
# Required for wal-e
23-
apt-get install -y pv lzop
2422
# install etcdctl
2523
ETCDVERSION=3.3.27
2624
curl -L https://github.com/coreos/etcd/releases/download/v${ETCDVERSION}/etcd-v${ETCDVERSION}-linux-"$(dpkg --print-architecture)".tar.gz \

postgres-appliance/launch.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ 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
57-
CMD="/scripts/patroni_wait.sh -t 3600 -- envdir $WALE_ENV_DIR /scripts/postgres_backup.sh $PGDATA"
58+
CMD="/scripts/patroni_wait.sh -t 3600 -- envdir $WALG_ENV_DIR /scripts/postgres_backup.sh $PGDATA"
5859
if [ "$(id -u)" = "0" ]; then
5960
su postgres -c "PATH=$PATH $CMD" &
6061
else

postgres-appliance/major_upgrade/inplace_upgrade.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
RSYNC_PORT = 5432
2222

2323

24-
def patch_wale_prefix(value, new_version):
24+
def patch_walg_prefix(value, new_version):
2525
from spilo_commons import is_valid_pg_version
2626

2727
if '/spilo/' in value and '/wal/' in value: # path crafted in the configure_spilo.py?
@@ -51,20 +51,20 @@ def update_configs(new_version):
5151

5252
write_patroni_config(config, True)
5353

54-
# update wal-e/wal-g envdir files
54+
# update wal-g envdir files
5555
restore_command = shlex.split(config['postgresql'].get('recovery_conf', {}).get('restore_command', ''))
5656
if len(restore_command) > 6 and restore_command[0] == 'envdir':
5757
envdir = restore_command[1]
5858

5959
try:
6060
for name in os.listdir(envdir):
61-
# len('WALE__PREFIX') = 12
62-
if len(name) > 12 and name.endswith('_PREFIX') and name[:5] in ('WALE_', 'WALG_'):
61+
# len('WALG__PREFIX') = 12
62+
if len(name) > 12 and name.endswith('_PREFIX') and name.startswith('WALG_'):
6363
name = os.path.join(envdir, name)
6464
try:
6565
with open(name) as f:
6666
value = f.read().strip()
67-
new_value = patch_wale_prefix(value, new_version)
67+
new_value = patch_walg_prefix(value, new_version)
6868
if new_value != value:
6969
write_file(new_value, name, True)
7070
except Exception as e:

0 commit comments

Comments
 (0)