From d02a19c9957951cfe88bc91480a352f13db91871 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 12:57:14 +0300 Subject: [PATCH 01/21] Testing GCS --- Dockerfile | 2 +- backup.sh | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ad33265..3ec87ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.15 RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl aws-cli + && apk --no-cache add dumb-init postgresql-client curl google-cloud-sdk RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron diff --git a/backup.sh b/backup.sh index 5f2ab59..5ee0e48 100644 --- a/backup.sh +++ b/backup.sh @@ -48,6 +48,10 @@ case "${PG_BACKUP_ACTION:-dump}" in AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" fi + echo "Configuring ACCESS KEYS" + sed -i "s|replace_gs_access_key_id|$S3_ACCESS_KEY_ID|g" /root/.boto + sed -i "s|replace_gs_secret_access_key|$S3_SECRET_ACCESS_KEY|g" /root/.boto + # env vars needed for aws tools export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY @@ -56,20 +60,19 @@ case "${PG_BACKUP_ACTION:-dump}" in # TODO: check if database is fresh echo "Snapshotting $POSTGRES_DB database" pg_dump -Fc $POSTGRES_HOST_OPTS $POSTGRES_DB > dump.backup - aws configure set default.s3.multipart_chunksize 16MB if [ "${PRIVATE_BACKUP}" == "true" ] || [ "${PRIVATE_BACKUP}" == "1" ]; then echo "Rotating old snapshot" - aws $AWS_ARGS s3 cp s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup --acl private || true + gsutil cp gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup || true echo "Uploading fresh private snapshot to $S3_BUCKET/$S3_PATH/$S3_FILENAME" - cat dump.backup | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup --acl private || exit 2 + cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 else echo "Rotating old snapshot" - aws $AWS_ARGS s3 cp s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup --acl public-read || true + gsutil cp gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup || true echo "Uploading fresh public snapshot to $S3_BUCKET/$S3_PATH/$S3_FILENAME" - cat dump.backup | aws $AWS_ARGS s3 cp - s3://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup --acl public-read || exit 2 + cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 fi echo "Snapshot uploaded successfully, removing local file" From bd4d3bf3526bba154fa6c789f9ff4199a158d600 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 13:20:39 +0300 Subject: [PATCH 02/21] Use gcs image --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3ec87ef..bfcf464 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM alpine:3.15 +FROM google/cloud-sdk:a448.0.0-alpine RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl google-cloud-sdk + && apk --no-cache add dumb-init postgresql-client curl RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron From 1e74251d8bc092c1fe040e6c250964546b0f15ae Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 13:28:34 +0300 Subject: [PATCH 03/21] Fix --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index bfcf464..6773ccb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM google/cloud-sdk:a448.0.0-alpine +FROM google/cloud-sdk:448.0.0-alpine RUN apk update \ && apk --no-cache add dumb-init postgresql-client curl From 421dde5ee329fa603630e5201df0642a6da44c3e Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 15:11:43 +0300 Subject: [PATCH 04/21] Back to apline --- Dockerfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6773ccb..3577ff0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,14 @@ -FROM google/cloud-sdk:448.0.0-alpine +FROM alpine:3.15 RUN apk update \ && apk --no-cache add dumb-init postgresql-client curl +RUN curl -sSL https://sdk.cloud.google.com | bash + +ENV PATH $PATH:/root/google-cloud-sdk/bin + +ADD boto.config /root/.boto + RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron COPY entrypoint.sh . From dc65ee4718bb5fd43cc5d8e406cac8a0cc1d87e8 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 15:13:27 +0300 Subject: [PATCH 05/21] Add boto --- boto.config | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 boto.config diff --git a/boto.config b/boto.config new file mode 100644 index 0000000..c68baf8 --- /dev/null +++ b/boto.config @@ -0,0 +1,13 @@ +[Credentials] +gs_access_key_id=replace_gs_access_key_id +gs_secret_access_key=replace_gs_secret_access_key + +[Boto] + +[GoogleCompute] + +[GSUtil] +content_language = en +default_api_version = 2 + +[OAuth2] \ No newline at end of file From 0414fd353c50d8071988fdf8491c0e7489e66fc8 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 15:16:55 +0300 Subject: [PATCH 06/21] Fix --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3577ff0..549303e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.15 RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl + && apk --no-cache add dumb-init postgresql-client curl python which bash RUN curl -sSL https://sdk.cloud.google.com | bash From d099fd08c7f740c148f613d739eab79151571864 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 15:22:43 +0300 Subject: [PATCH 07/21] Another test --- Dockerfile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 549303e..368055f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,20 @@ FROM alpine:3.15 RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl python which bash + && apk --no-cache add dumb-init postgresql-client curl python3 -RUN curl -sSL https://sdk.cloud.google.com | bash +RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-396.0.0-linux-x86_64.tar.gz -ENV PATH $PATH:/root/google-cloud-sdk/bin +# ARM +# RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-396.0.0-linux-arm.tar.gz + +RUN tar -xf google-cloud-cli-396.0.0-linux-x86_64.tar.gz + +RUN ./google-cloud-sdk/install.sh --usage-reporting false -q + +RUN rm google-cloud-cli-396.0.0-linux-x86_64.tar.gz + +ENV PATH $PATH:/google-cloud-sdk/bin/ ADD boto.config /root/.boto From 4b865c963d036c66fa6983bff5ccbdfba6eb3f11 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 16:06:36 +0300 Subject: [PATCH 08/21] Another one --- Dockerfile | 19 ++----------------- backup.sh | 7 ++++--- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 368055f..7520fe9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,7 @@ -FROM alpine:3.15 +FROM google/cloud-sdk:alpine RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl python3 - -RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-396.0.0-linux-x86_64.tar.gz - -# ARM -# RUN curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-396.0.0-linux-arm.tar.gz - -RUN tar -xf google-cloud-cli-396.0.0-linux-x86_64.tar.gz - -RUN ./google-cloud-sdk/install.sh --usage-reporting false -q - -RUN rm google-cloud-cli-396.0.0-linux-x86_64.tar.gz - -ENV PATH $PATH:/google-cloud-sdk/bin/ - -ADD boto.config /root/.boto + && apk --no-cache add dumb-init postgresql-client curl RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron diff --git a/backup.sh b/backup.sh index 5ee0e48..a6a5ce4 100644 --- a/backup.sh +++ b/backup.sh @@ -48,9 +48,10 @@ case "${PG_BACKUP_ACTION:-dump}" in AWS_ARGS="--endpoint-url ${S3_ENDPOINT}" fi - echo "Configuring ACCESS KEYS" - sed -i "s|replace_gs_access_key_id|$S3_ACCESS_KEY_ID|g" /root/.boto - sed -i "s|replace_gs_secret_access_key|$S3_SECRET_ACCESS_KEY|g" /root/.boto + # Google Cloud Auth + echo "Authenticating to Google Cloud..." + echo $S3_SECRET_ACCESS_KEY | base64 -d > /key.json + gcloud auth activate-service-account --key-file /key.json --project "$S3_ACCESS_KEY_ID" -q # env vars needed for aws tools export AWS_ACCESS_KEY_ID=$S3_ACCESS_KEY_ID From ac6c6ec7bc4b895fada49e58999f3392c00674c0 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 16:33:56 +0300 Subject: [PATCH 09/21] Make public --- backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup.sh b/backup.sh index a6a5ce4..b003e33 100644 --- a/backup.sh +++ b/backup.sh @@ -70,10 +70,10 @@ case "${PG_BACKUP_ACTION:-dump}" in cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 else echo "Rotating old snapshot" - gsutil cp gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup || true + gsutil cp gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup -a public-read || true echo "Uploading fresh public snapshot to $S3_BUCKET/$S3_PATH/$S3_FILENAME" - cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 + cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup -a public-read || exit 2 fi echo "Snapshot uploaded successfully, removing local file" From 5caae23ac76f7122042c35ab0f945f4b158371b8 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 16:54:23 +0300 Subject: [PATCH 10/21] Fix --- backup.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backup.sh b/backup.sh index b003e33..9ac59cf 100644 --- a/backup.sh +++ b/backup.sh @@ -70,10 +70,10 @@ case "${PG_BACKUP_ACTION:-dump}" in cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 else echo "Rotating old snapshot" - gsutil cp gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup -a public-read || true + gsutil cp -a public-read gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.old.backup || true echo "Uploading fresh public snapshot to $S3_BUCKET/$S3_PATH/$S3_FILENAME" - cat dump.backup | gsutil cp - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup -a public-read || exit 2 + cat dump.backup | gsutil cp -a public-read - gs://$S3_BUCKET/$S3_PATH/$S3_FILENAME.backup || exit 2 fi echo "Snapshot uploaded successfully, removing local file" From 4d1b80bb48aae94b44ec420bb2916dd8148f7fbe Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 17:14:54 +0300 Subject: [PATCH 11/21] Setting up trap to make sure the dump file is deleted --- backup.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backup.sh b/backup.sh index 9ac59cf..2a8a175 100644 --- a/backup.sh +++ b/backup.sh @@ -58,6 +58,15 @@ case "${PG_BACKUP_ACTION:-dump}" in export AWS_SECRET_ACCESS_KEY=$S3_SECRET_ACCESS_KEY export AWS_DEFAULT_REGION=$S3_REGION + # Define a cleanup function + cleanup() { + echo "Cleaning up..." + rm -f dump.backup + } + + # Set a trap to call the cleanup function when the script exits + trap cleanup EXIT + # TODO: check if database is fresh echo "Snapshotting $POSTGRES_DB database" pg_dump -Fc $POSTGRES_HOST_OPTS $POSTGRES_DB > dump.backup @@ -77,7 +86,6 @@ case "${PG_BACKUP_ACTION:-dump}" in fi echo "Snapshot uploaded successfully, removing local file" - rm dump.backup if [ ! -z "$HEARTBEAT_URI" ]; then echo "Sending heartbeat signal" From f9b3b5fb4b580cee36249639a6a50c4cb1c849b0 Mon Sep 17 00:00:00 2001 From: dmir Date: Tue, 3 Oct 2023 17:15:45 +0300 Subject: [PATCH 12/21] Fix --- backup.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/backup.sh b/backup.sh index 2a8a175..0edb5c1 100644 --- a/backup.sh +++ b/backup.sh @@ -86,6 +86,7 @@ case "${PG_BACKUP_ACTION:-dump}" in fi echo "Snapshot uploaded successfully, removing local file" + rm dump.backup if [ ! -z "$HEARTBEAT_URI" ]; then echo "Sending heartbeat signal" From 61162590aad51955aaeb3be4e0a360cc419a35eb Mon Sep 17 00:00:00 2001 From: dmir Date: Wed, 4 Oct 2023 18:45:07 +0300 Subject: [PATCH 13/21] Trying to fix --- Dockerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7520fe9..efea059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,14 @@ -FROM google/cloud-sdk:alpine +FROM alpine:3.15 + + RUN apk add --update \ + python \ + curl \ + which \ + bash + + RUN curl -sSL https://sdk.cloud.google.com | bash + + ENV PATH $PATH:/root/google-cloud-sdk/bin RUN apk update \ && apk --no-cache add dumb-init postgresql-client curl From b511da2933ea33a1afc0c303ac36a24b5cc4c2a0 Mon Sep 17 00:00:00 2001 From: dmir Date: Wed, 4 Oct 2023 18:47:20 +0300 Subject: [PATCH 14/21] Again --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index efea059..3a0d760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.15 RUN apk add --update \ - python \ + python3 \ curl \ which \ bash From e219f8d0bf75a54cf8194d3283c52084aa4fba01 Mon Sep 17 00:00:00 2001 From: dmir Date: Wed, 27 Dec 2023 20:48:57 +0300 Subject: [PATCH 15/21] pg-15-gcs --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3a0d760..06a59cd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.15 +FROM alpine:3.18 RUN apk add --update \ python3 \ @@ -11,7 +11,7 @@ FROM alpine:3.15 ENV PATH $PATH:/root/google-cloud-sdk/bin RUN apk update \ - && apk --no-cache add dumb-init postgresql-client curl + && apk --no-cache add dumb-init postgresql15-client curl RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron From 779191779df4a11eb2a5efc09b0af3921f878f28 Mon Sep 17 00:00:00 2001 From: dmir Date: Sun, 4 Feb 2024 20:29:19 +0300 Subject: [PATCH 16/21] pg16 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 06a59cd..689627a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ FROM alpine:3.18 ENV PATH $PATH:/root/google-cloud-sdk/bin RUN apk update \ - && apk --no-cache add dumb-init postgresql15-client curl + && apk --no-cache add dumb-init postgresql16-client curl RUN curl -L https://github.com/odise/go-cron/releases/download/v0.0.7/go-cron-linux.gz | zcat > /usr/local/bin/go-cron && chmod +x /usr/local/bin/go-cron From 11ca32cec523d02f400b91b4f7cf6755241835aa Mon Sep 17 00:00:00 2001 From: dmir Date: Sun, 4 Feb 2024 20:40:09 +0300 Subject: [PATCH 17/21] bump alpine --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 689627a..6b91216 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.18 +FROM alpine:3.19 RUN apk add --update \ python3 \ From a7a14a162806ecfe0f85f1a9f2449d10894bc6b1 Mon Sep 17 00:00:00 2001 From: dmir Date: Thu, 8 Feb 2024 17:20:24 +0300 Subject: [PATCH 18/21] Try autovacuum --- backup.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backup.sh b/backup.sh index 0edb5c1..5dae686 100644 --- a/backup.sh +++ b/backup.sh @@ -99,10 +99,18 @@ case "${PG_BACKUP_ACTION:-dump}" in exit 1 fi + echo "Turning off autovacuum" + psql $POSTGRES_HOST_OPTS -c "ALTER SYSTEM SET autovacuum = off;" + psql $POSTGRES_HOST_OPTS -c "SELECT pg_reload_conf;" + echo "Downloading latest snapshot from $PG_BACKUP_FILE" curl -o dump.backup $PG_BACKUP_FILE echo "Restoring $POSTGRES_DB database" pg_restore -v -d $POSTGRES_DB $POSTGRES_HOST_OPTS dump.backup + + echo "Re-enable autovacuum" + psql $POSTGRES_HOST_OPTS -c "ALTER SYSTEM RESET autovacuum;" + psql $POSTGRES_HOST_OPTS -c "SELECT pg_reload_conf;" ;; esac From 088496557be63dcde74e0dd0c83fb96c8039ff41 Mon Sep 17 00:00:00 2001 From: dmir Date: Thu, 8 Feb 2024 17:28:47 +0300 Subject: [PATCH 19/21] backup fix --- backup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backup.sh b/backup.sh index 5dae686..16fa9e1 100644 --- a/backup.sh +++ b/backup.sh @@ -100,8 +100,8 @@ case "${PG_BACKUP_ACTION:-dump}" in fi echo "Turning off autovacuum" - psql $POSTGRES_HOST_OPTS -c "ALTER SYSTEM SET autovacuum = off;" - psql $POSTGRES_HOST_OPTS -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "ALTER SYSTEM SET autovacuum = off;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "SELECT pg_reload_conf;" echo "Downloading latest snapshot from $PG_BACKUP_FILE" curl -o dump.backup $PG_BACKUP_FILE @@ -110,7 +110,7 @@ case "${PG_BACKUP_ACTION:-dump}" in pg_restore -v -d $POSTGRES_DB $POSTGRES_HOST_OPTS dump.backup echo "Re-enable autovacuum" - psql $POSTGRES_HOST_OPTS -c "ALTER SYSTEM RESET autovacuum;" - psql $POSTGRES_HOST_OPTS -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "ALTER SYSTEM RESET autovacuum;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "SELECT pg_reload_conf;" ;; esac From 8a46c93e70a933972ebea425c35d8a9f989e24bf Mon Sep 17 00:00:00 2001 From: dmir Date: Thu, 8 Feb 2024 17:32:35 +0300 Subject: [PATCH 20/21] Fix --- backup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backup.sh b/backup.sh index 16fa9e1..3e3f7dd 100644 --- a/backup.sh +++ b/backup.sh @@ -100,8 +100,8 @@ case "${PG_BACKUP_ACTION:-dump}" in fi echo "Turning off autovacuum" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "ALTER SYSTEM SET autovacuum = off;" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "ALTER SYSTEM SET autovacuum = off;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "SELECT pg_reload_conf;" echo "Downloading latest snapshot from $PG_BACKUP_FILE" curl -o dump.backup $PG_BACKUP_FILE @@ -110,7 +110,7 @@ case "${PG_BACKUP_ACTION:-dump}" in pg_restore -v -d $POSTGRES_DB $POSTGRES_HOST_OPTS dump.backup echo "Re-enable autovacuum" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "ALTER SYSTEM RESET autovacuum;" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "ALTER SYSTEM RESET autovacuum;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "SELECT pg_reload_conf;" ;; esac From 86d1a9b827f3c8b27e31ea114448bcf246e17ee8 Mon Sep 17 00:00:00 2001 From: dmir Date: Thu, 8 Feb 2024 17:39:43 +0300 Subject: [PATCH 21/21] Another fix --- backup.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backup.sh b/backup.sh index 3e3f7dd..5199b64 100644 --- a/backup.sh +++ b/backup.sh @@ -100,8 +100,8 @@ case "${PG_BACKUP_ACTION:-dump}" in fi echo "Turning off autovacuum" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "ALTER SYSTEM SET autovacuum = off;" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d postgres -U $POSTGRES_USER -c "ALTER SYSTEM SET autovacuum = off;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d postgres -U $POSTGRES_USER -c "SELECT pg_reload_conf();" echo "Downloading latest snapshot from $PG_BACKUP_FILE" curl -o dump.backup $PG_BACKUP_FILE @@ -110,7 +110,7 @@ case "${PG_BACKUP_ACTION:-dump}" in pg_restore -v -d $POSTGRES_DB $POSTGRES_HOST_OPTS dump.backup echo "Re-enable autovacuum" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "ALTER SYSTEM RESET autovacuum;" - psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d $POSTGRES_DB -U $POSTGRES_USER -c "SELECT pg_reload_conf;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d postgres -U $POSTGRES_USER -c "ALTER SYSTEM RESET autovacuum;" + psql -h $POSTGRES_HOST -p $POSTGRES_PORT -d postgres -U $POSTGRES_USER -c "SELECT pg_reload_conf();" ;; esac