Skip to content

Commit 83878fe

Browse files
authored
make bucket prefix for logical backup configurable (#2609)
* make bucket prefix for logical backup configurable * include container comparison in logical backup diff * add unit test and update description for compareContainers * don't rely on users putting / in the config - reflect other comments from review
1 parent 6ddafad commit 83878fe

File tree

20 files changed

+165
-65
lines changed

20 files changed

+165
-65
lines changed

.github/workflows/publish_ghcr_image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181
- name: Build and push multiarch logical-backup image to ghcr
8282
uses: docker/build-push-action@v3
8383
with:
84-
context: docker/logical-backup
84+
context: logical-backup
8585
push: true
8686
build-args: BASE_IMAGE=ubuntu:22.04
8787
tags: "${{ steps.image_lb.outputs.BACKUP_IMAGE }}"

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ spec:
528528
type: string
529529
logical_backup_s3_bucket:
530530
type: string
531+
logical_backup_s3_bucket_prefix:
532+
type: string
531533
logical_backup_s3_endpoint:
532534
type: string
533535
logical_backup_s3_region:

charts/postgres-operator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ configLogicalBackup:
372372
logical_backup_s3_access_key_id: ""
373373
# S3 bucket to store backup results
374374
logical_backup_s3_bucket: "my-bucket-url"
375+
# S3 bucket prefix to use
376+
logical_backup_s3_bucket_prefix: "spilo"
375377
# S3 region of bucket
376378
logical_backup_s3_region: ""
377379
# S3 endpoint url when not using AWS

delivery.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pipeline:
9090
commands:
9191
- desc: Build image
9292
cmd: |
93-
cd docker/logical-backup
93+
cd logical-backup
9494
export TAG=$(git describe --tags --always --dirty)
9595
IMAGE="registry-write.opensource.zalan.do/acid/logical-backup"
9696
docker build --rm -t "$IMAGE:$TAG$CDP_TAG" .

docs/administrator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ but only snapshots of your data. In its current state, see logical backups as a
12831283
way to quickly create SQL dumps that you can easily restore in an empty test
12841284
cluster.
12851285

1286-
2. The [example image](https://github.com/zalando/postgres-operator/blob/master/docker/logical-backup/Dockerfile) implements the backup
1286+
2. The [example image](https://github.com/zalando/postgres-operator/blob/master/logical-backup/Dockerfile) implements the backup
12871287
via `pg_dumpall` and upload of compressed and encrypted results to an S3 bucket.
12881288
`pg_dumpall` requires a `superuser` access to a DB and runs on the replica when
12891289
possible.

docs/reference/operator_parameters.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,9 @@ grouped under the `logical_backup` key.
813813
default values from `postgres_pod_resources` will be used.
814814

815815
* **logical_backup_docker_image**
816-
An image for pods of the logical backup job. The [example image](https://github.com/zalando/postgres-operator/blob/master/docker/logical-backup/Dockerfile)
816+
An image for pods of the logical backup job. The [example image](https://github.com/zalando/postgres-operator/blob/master/logical-backup/Dockerfile)
817817
runs `pg_dumpall` on a replica if possible and uploads compressed results to
818-
an S3 bucket under the key `/spilo/pg_cluster_name/cluster_k8s_uuid/logical_backups`.
818+
an S3 bucket under the key `/<configured-s3-bucket-prefix>/<pg_cluster_name>/<cluster_k8s_uuid>/logical_backups`.
819819
The default image is the same image built with the Zalando-internal CI
820820
pipeline. Default: "registry.opensource.zalan.do/acid/logical-backup:v1.11.0"
821821

@@ -845,6 +845,9 @@ grouped under the `logical_backup` key.
845845
S3 bucket to store backup results. The bucket has to be present and
846846
accessible by Postgres pods. Default: empty.
847847

848+
* **logical_backup_s3_bucket_prefix**
849+
S3 bucket prefix to use in configured bucket. Default: "spilo"
850+
848851
* **logical_backup_s3_endpoint**
849852
When using non-AWS S3 storage, endpoint can be set as a ENV variable. The default is empty.
850853

File renamed without changes.

docker/logical-backup/dump.sh renamed to logical-backup/dump.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function compress {
4545
}
4646

4747
function az_upload {
48-
PATH_TO_BACKUP=$LOGICAL_BACKUP_S3_BUCKET"/spilo/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
48+
PATH_TO_BACKUP=$LOGICAL_BACKUP_S3_BUCKET"/"$LOGICAL_BACKUP_S3_BUCKET_PREFIX"/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
4949

5050
az storage blob upload --file "$1" --account-name "$LOGICAL_BACKUP_AZURE_STORAGE_ACCOUNT_NAME" --account-key "$LOGICAL_BACKUP_AZURE_STORAGE_ACCOUNT_KEY" -c "$LOGICAL_BACKUP_AZURE_STORAGE_CONTAINER" -n "$PATH_TO_BACKUP"
5151
}
@@ -72,7 +72,7 @@ function aws_delete_outdated {
7272
cutoff_date=$(date -d "$LOGICAL_BACKUP_S3_RETENTION_TIME ago" +%F)
7373

7474
# mimic bucket setup from Spilo
75-
prefix="spilo/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"
75+
prefix=$LOGICAL_BACKUP_S3_BUCKET_PREFIX"/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"
7676

7777
args=(
7878
"--no-paginate"
@@ -107,7 +107,7 @@ function aws_upload {
107107
# mimic bucket setup from Spilo
108108
# to keep logical backups at the same path as WAL
109109
# NB: $LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX already contains the leading "/" when set by the Postgres Operator
110-
PATH_TO_BACKUP=s3://$LOGICAL_BACKUP_S3_BUCKET"/spilo/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
110+
PATH_TO_BACKUP=s3://$LOGICAL_BACKUP_S3_BUCKET"/"$LOGICAL_BACKUP_S3_BUCKET_PREFIX"/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
111111

112112
args=()
113113

@@ -120,7 +120,7 @@ function aws_upload {
120120
}
121121

122122
function gcs_upload {
123-
PATH_TO_BACKUP=gs://$LOGICAL_BACKUP_S3_BUCKET"/spilo/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
123+
PATH_TO_BACKUP=gs://$LOGICAL_BACKUP_S3_BUCKET"/"$LOGICAL_BACKUP_S3_BUCKET_PREFIX"/"$SCOPE$LOGICAL_BACKUP_S3_BUCKET_SCOPE_SUFFIX"/logical_backups/"$(date +%s).sql.gz
124124

125125
gsutil -o Credentials:gs_service_key_file=$LOGICAL_BACKUP_GOOGLE_APPLICATION_CREDENTIALS cp - "$PATH_TO_BACKUP"
126126
}

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ data:
9090
logical_backup_provider: "s3"
9191
# logical_backup_s3_access_key_id: ""
9292
logical_backup_s3_bucket: "my-bucket-url"
93+
# logical_backup_s3_bucket_prefix: "spilo"
9394
# logical_backup_s3_region: ""
9495
# logical_backup_s3_endpoint: ""
9596
# logical_backup_s3_secret_access_key: ""

manifests/operatorconfiguration.crd.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ spec:
526526
type: string
527527
logical_backup_s3_bucket:
528528
type: string
529+
logical_backup_s3_bucket_prefix:
530+
type: string
529531
logical_backup_s3_endpoint:
530532
type: string
531533
logical_backup_s3_region:

0 commit comments

Comments
 (0)