Compare commits

...
142 Commits
Author SHA1 Message Date
Brad Koehn 653ab7a387 Merge pull request 'Configure Renovate' (#2) from renovate/configure into master
Reviewed-on: https://git.koehn.com/docker/postgres-wal-g/pulls/2
2025-02-26 17:07:45 +00:00
Renovate Bot d6f4953452 Add renovate.json 2025-02-26 17:01:19 +00:00
Brad Koehn 05c907dcee added provenance and SBOM 2024-08-20 09:09:37 -05:00
Brad Koehn a8212acfb5 lint 2024-08-20 09:09:22 -05:00
Brad Koehn 14d15c287e added extra readme 2024-08-06 17:17:04 -05:00
Brad Koehn fb913a8062 added tidy 2024-08-06 17:13:49 -05:00
Brad Koehn 52888bd104 force bookworm 2024-05-22 08:09:48 -05:00
Brad Koehn a437ca53f4 added check for enviornment variables 2024-04-23 12:37:17 -05:00
Brad Koehn 8669c7e663 more docs 2024-04-23 11:49:22 -05:00
Brad Koehn fc63329212 added documentation about testing 2024-04-23 11:26:29 -05:00
Brad Koehn 9ca1e4b2c0 removed specific builder 2024-02-08 11:47:53 -06:00
Brad Koehn e33df13659 added gnutls-bin which makes the mysteriously failing build work. 🤷‍♂️ 2024-02-08 11:47:53 -06:00
Brad Koehn 42be7c5361 Update README.md 2023-11-18 03:53:48 +00:00
Brad Koehn caa0e988b1 fixed build error 2023-11-14 14:10:55 -06:00
Brad Koehn 0283464236 gave up on multi-machine dockerx; fixed docker tag name 2023-11-10 08:11:43 -06:00
Brad Koehn 599b4a7394 setting up key for remote build 2023-11-09 16:51:32 -06:00
Brad Koehn 181d81d8b6 setting up key for remote build 2023-11-09 16:46:20 -06:00
Brad Koehn fe1d076b54 setting up key for remote build 2023-11-09 16:39:19 -06:00
Brad Koehn d644e427bf setting up key for remote build 2023-11-09 16:30:15 -06:00
Brad Koehn 2843231ba3 setting up key for remote build 2023-11-09 16:27:28 -06:00
Brad Koehn d38cf5c191 setting up key for remote build 2023-11-09 16:23:31 -06:00
Brad Koehn aab6a0cbc3 setting up key for remote build 2023-11-09 16:11:44 -06:00
Brad Koehn 3f5f137aac setting up key for remote build 2023-11-09 15:57:01 -06:00
Brad Koehn f1b9fe6c8f setting up key for remote build 2023-11-09 15:53:26 -06:00
Brad Koehn 63777d0241 setting up key for remote build 2023-11-09 15:32:22 -06:00
Brad Koehn ffe01b37ae setting up key for remote build 2023-11-09 15:27:07 -06:00
Brad Koehn 6ccf13f61e setting up key for remote build 2023-11-09 15:17:02 -06:00
Brad Koehn 06627b7c94 setting up key for remote build 2023-11-09 15:10:24 -06:00
Brad Koehn 47a9a80143 setting up key for remote build 2023-11-09 15:08:02 -06:00
Brad Koehn 59d62b6071 use k3s for amd64 builds 2023-11-09 14:58:37 -06:00
Brad Koehn 63e54dbefb removed woodpecker in favor of Gitea Actions 2023-11-04 11:15:50 -05:00
Brad Koehn 353e9afdca removed woodpecker in favor of Gitea Actions 2023-11-04 11:15:16 -05:00
Brad Koehn 25c88d9aee tweaks 2023-11-04 10:43:03 -05:00
Brad Koehn 9210fd7661 tweaks 2023-11-04 10:40:44 -05:00
Brad Koehn 61ff6dd3ea tweaks 2023-11-04 10:38:50 -05:00
Brad Koehn 2509a90e5e multi-arch 2023-11-04 10:33:08 -05:00
Brad Koehn e21c44f8cc fix build-args 2023-11-04 15:30:17 +00:00
Brad Koehn 97d2c06256 trying gitea actions 2023-11-04 10:27:01 -05:00
Brad Koehn 9330274a80 build locally, for amd/64 2023-07-07 11:32:34 -05:00
Brad Koehn 9e3a846dc1 moved cron back to pipeline 2023-02-28 06:44:10 -06:00
Brad Koehn ff60201d72 move cron and run notify in parallel to build 2023-02-28 06:41:45 -06:00
Brad Koehn 17c6ecb0d7 don't report build failure 2023-02-28 06:35:27 -06:00
Brad Koehn f888c65103 enable cron and only send message as needed 2023-02-27 17:04:32 -06:00
Brad Koehn 2dbb67d57d added matrix stuff to test 2023-02-27 17:02:26 -06:00
Brad Koehn 4821a6be85 versioning the builder 2023-02-27 16:35:31 -06:00
Brad Koehn b4004f97e1 buld tweaks and correct failure detection 2023-02-27 16:26:17 -06:00
Brad Koehn d21915e04f test to rebuild automatically 2023-02-27 16:23:42 -06:00
Brad Koehn b1025bf7be added overnight cron job and latest defaults 2023-02-27 09:37:15 -06:00
Brad Koehn f49433d3ee fixed broken link. 2023-02-26 21:00:52 -06:00
Brad Koehn 53618b8e55 added docker tag to match commit tag 2023-02-26 19:19:49 -06:00
Brad Koehn 179daa3d14 tags working 2023-02-26 19:19:49 -06:00
Brad Koehn 7fe34cd27c fixed tag indexes. I hope 2023-02-26 19:19:49 -06:00
Brad Koehn 7b1cc24f2e remove branch specifier 2023-02-26 19:19:49 -06:00
Brad Koehn 66d4b429cf branch name 2023-02-26 19:19:49 -06:00
Brad Koehn 8d201da1a2 using tagged builds 2023-02-26 19:19:49 -06:00
Brad Koehn 226ba8b2d0 Remove GitLab build 2023-02-26 21:05:08 +00:00
Brad Koehn 93013a5b39 removed unneeded job; mtu was the magic 2023-02-26 08:00:58 -06:00
Brad Koehn 20b012a6a0 tell plugin to lower mtu because mtu path discovery broken 2023-02-26 06:52:30 -06:00
Brad Koehn 83fa1e24a6 use image with ifconfig installed 2023-02-26 06:41:22 -06:00
Brad Koehn 36f146a58f getting mtu 2023-02-26 06:33:21 -06:00
Brad Koehn caf5c50aa6 trying the build outside k3s 2023-02-25 14:07:25 -06:00
Brad Koehn c0dabcc230 just run the test 2023-02-25 13:15:57 -06:00
Brad Koehn 192afe1453 added test job 2023-02-25 13:15:01 -06:00
Brad Koehn 69f99303d4 we need some stinking badges 2023-02-25 11:45:40 -06:00
Brad Koehn ef80955920 make apt-get update less quiet 2023-02-25 11:32:19 -06:00
Brad Koehn 2ae1d24f9a forgot that you cannot build for ARM 2023-02-25 11:22:34 -06:00
Brad Koehn 2b8df13fda fixed build_args 2023-02-25 11:19:32 -06:00
Brad Koehn c1346e5f41 adding environment variable as literals 2023-02-25 11:15:37 -06:00
Brad Koehn 2f98080099 using docker-buildx plugin 2023-02-25 11:11:58 -06:00
Brad Koehn acadcd0db6 attempting to make it work 2023-02-25 10:59:38 -06:00
Brad Koehn 0670df99dc first try 2023-02-25 10:45:43 -06:00
Brad Koehn 9af7b9169d minor build tweaks 2023-02-25 08:44:17 -06:00
Brad Koehn f2fa1d42d6 changed go version so we can keep up easier 2023-02-25 08:42:53 -06:00
Brad Koehn 4666db46fc documentation tweaks 2023-02-25 08:42:14 -06:00
Brad Koehn 6565723c06 update platforms 2022-05-24 20:24:01 -05:00
Brad Koehn a4ca8d4b45 got wal-g 2.0.0 working 2022-05-24 19:52:30 -05:00
Brad Koehn 25642d5ed8 support build on 1.1, nicer build script 2022-05-20 06:38:48 -05:00
Brad Koehn ac557f48c2 merged 2022-05-16 08:29:37 -05:00
Brad Koehn 9fdba2423e simplified build 2022-05-16 08:28:53 -05:00
Brad Koehn 3adadf55b3 Update README.md to point to Postgres documentation. 2022-02-25 14:12:41 +00:00
Brad Koehn 5b3cd141cb 14.2 2022-02-11 11:55:06 -06:00
Brad Koehn 2f6dc3a509 Merge branch 'bkoehn-master-patch-85483' into 'master'
Update README.md

See merge request docker/postgres-wal-g!1
2021-12-14 16:10:23 +00:00
Brad Koehn 21c53dc4dd Update README.md
Deleted Dockerfile-postgis
2021-12-14 16:09:49 +00:00
Brad Koehn f2ef1c9d00 postgres 14.1 2021-11-26 16:32:39 -06:00
Brad Koehn 4b02d05230 postgres 14 2021-11-26 16:31:33 -06:00
Brad Koehn 2d1dea3953 Update .gitlab-ci.yml 2021-11-11 01:47:59 +00:00
Brad Koehn 7936f2a660 Update .gitlab-ci.yml 2021-11-10 23:56:44 +00:00
Brad Koehn f884fca8d3 build arm64 and amd64 images 2021-11-10 16:18:29 -06:00
Brad Koehn 808d390383 gitlab buildkit tweaks 2021-11-10 16:13:05 -06:00
Brad Koehn 888a8e06bf merged 2021-11-10 15:54:30 -06:00
Brad Koehn 8e6481be9b gitlab buildkit tweaks 2021-11-10 15:32:33 -06:00
Brad Koehn bd622797b1 gitlab buildkit tweaks 2021-11-10 15:30:04 -06:00
Brad Koehn d18b5088ad gitlab buildkit tweaks 2021-11-10 15:26:05 -06:00
Brad Koehn c030b76a4c gitlab buildkit tweaks 2021-11-10 15:23:52 -06:00
Brad Koehn ed3f8308bc gitlab buildkit tweaks 2021-11-10 15:22:29 -06:00
Brad Koehn e5067b4257 trying buildkit 2021-11-10 15:19:27 -06:00
Brad Koehn e34430fd7e kaniko bump 2021-11-02 09:23:52 -05:00
Brad Koehn 67f8f0cb65 downgraded kaniko to avoid OOM issues 2021-10-11 08:12:53 -05:00
Brad Koehn a7020c5d4e upgrade to 14 2021-10-10 14:23:43 -05:00
Brad Koehn a8028d9962 Update README.md 2021-08-20 15:52:46 +00:00
Brad Koehn 99ef19d076 Update .gitlab-ci.yml 2021-08-19 21:50:00 +00:00
Brad Koehn a4118b3a0f merge from master 2021-08-12 08:44:17 -05:00
Brad Koehn 21f3485321 bump to 13.4 2021-08-12 08:42:02 -05:00
Brad Koehn 0b977ac06b Fix a typo. 2021-06-01 13:14:31 +00:00
Brad Koehn 0043e3f3a4 Update README.md archiving link. 2021-06-01 13:11:07 +00:00
Brad Koehn b5dbec4366 got build to work with v1.0 complexities. ouch 2021-05-31 10:50:39 -05:00
Brad Koehn 8af3605145 new filename 2021-05-31 09:11:18 -05:00
Brad Koehn fdb7f1c6bf upgraded wal-g to 1.0 2021-05-31 09:04:32 -05:00
Brad Koehn 6e75b71775 bump postgre 2021-05-13 08:29:22 -05:00
Brad Koehn 80706a20c7 Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2021-04-13 15:16:59 -05:00
Brad Koehn 1ca880cf44 bump kaniko 2021-04-13 15:16:47 -05:00
Brad Koehn b66f2886bb Update .gitlab-ci.yml file 2021-02-28 18:00:13 +00:00
Brad Koehn 55b02b6caa wal-g version bump 2020-11-30 08:40:27 -06:00
Brad Koehn 3160eaf1b6 upgrade to pg13.1 2020-11-18 11:14:21 -06:00
Brad Koehn ae5912f70f upgrade to pg13.1 2020-11-18 10:10:36 -06:00
Brad Koehn f648887066 merged 2020-10-12 11:53:57 -05:00
Brad Koehn 4a4d87ba5d added documentation 2020-10-12 10:04:15 -05:00
Brad Koehn 7fa04795a8 Update README.md 2020-09-26 17:51:52 +00:00
Brad Koehn 89f76bb78b pg 13 2020-09-26 07:40:15 -05:00
Brad Koehn 642632c60c postgres 12.4 2020-08-17 13:58:41 -05:00
Brad Koehn f301fad22e version bump 12.3 2020-05-16 06:27:57 -05:00
Brad Koehn 365ef7da9f works with current kaniko and modern docker auth; removed 9.6 build 2020-02-28 10:11:52 -06:00
Brad Koehn ceb542e680 upgraded to support new recovery paradigm in postgres 12; won't work on 9.6 anymore 2020-02-16 08:34:49 -06:00
Brad Koehn 83459c3eee Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2019-11-30 12:28:13 -06:00
Brad Koehn e3cee34644 upgraded to 12.1 2019-11-20 12:54:16 -06:00
Brad Koehn 6ce0b371be Update README.md 2019-10-31 19:09:48 +00:00
Brad Koehn f92168528e added support for WALG_RELEASE build arg 2019-10-21 17:23:14 -05:00
Brad Koehn 10af957331 made WAL-G Version an argument 2019-10-21 17:18:34 -05:00
Brad Koehn d8e1e1f39b migrated to postgres 12 builds 2019-10-21 17:17:01 -05:00
Brad Koehn 56aa0e2ca2 upgraded to PG 11.5 2019-08-30 13:37:36 -05:00
Brad Koehn 30f3363b8e Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2019-06-11 15:28:25 -05:00
Brad Koehn 72c13d458e Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2019-06-11 15:27:58 -05:00
Brad Koehn 6f6dd9bca6 bumped wal-g version 2019-06-10 15:21:52 -05:00
Brad Koehn fc6bb76110 11.3 2019-06-10 12:30:58 -05:00
Brad Koehn d3feaff8e1 Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2019-05-13 12:56:14 -05:00
Brad Koehn e779a43c2f Update .gitlab-ci.yml 2019-05-13 17:55:14 +00:00
Brad Koehn cc2096c4b9 upgraded postgres 11 and wal-g 2019-04-16 10:27:15 -05:00
Brad Koehn a554117ba1 upgraded to 11.2 2019-03-04 14:49:41 -06:00
Brad Koehn a08e138569 added gnupg 2019-02-20 13:25:38 -06:00
Brad Koehn 18b0d9b0ee Merge branch 'master' of ssh://gitlab.koehn.com:2201/docker/postgres-wal-g 2019-02-20 12:25:19 -06:00
Brad Koehn 5b59617f84 upgraded wal-g to fix some bugs 2019-02-20 11:33:36 -06:00
Brad Koehn c3425c6064 use PGDATA in post-recovery.sh too 2019-02-19 14:39:48 -06:00
9 changed files with 175 additions and 93 deletions

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
name: ci
on:
push:
tags:
- '*'
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Get Postgres and WAL-G versions
env:
TAG: ${{ gitea.ref_name }}
id: versions
run: |
echo "::set-output name=postgres::${TAG:0:4}"
echo "::set-output name=walg::${TAG:5:6}"
- name: Install Docker
run: curl -fsSL https://get.docker.com | sh
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: git.koehn.com
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v5
needs: [versions, ssh]
with:
build-args: |
BASE=${{ steps.versions.outputs.postgres }}
WAL_G=${{ steps.versions.outputs.walg }}
push: true
platforms: linux/amd64,linux/arm64
tags: git.koehn.com/docker/postgres-wal-g:${{ gitea.ref_name }}
-25
View File
@@ -1,25 +0,0 @@
stages:
- build
build-9.6:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"index.docker.io\":{\"username\":\"$DOCKER_LOGIN\",\"password\":\"$DOCKER_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination koehn/postgres-wal-g:9.6-$CI_COMMIT_TAG --build-arg BASE=9.6
only:
- tags
build-11.1:
stage: build
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
script:
- echo "{\"auths\":{\"index.docker.io\":{\"username\":\"$DOCKER_LOGIN\",\"password\":\"$DOCKER_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination koehn/postgres-wal-g:11.1-$CI_COMMIT_TAG --build-arg BASE=11.1
only:
- tags
+18 -4
View File
@@ -1,10 +1,24 @@
ARG BASE
ARG BASE=latest
FROM golang:1-bookworm AS build
ARG WALG_RELEASE=master
RUN apt-get update && apt-get install -qqy --no-install-recommends --no-install-suggests cmake gnutls-bin liblzo2-dev libsodium23 libsodium-dev && \
cd /go/src/ && \
git clone -b $WALG_RELEASE --recurse-submodules https://github.com/wal-g/wal-g.git && \
cd wal-g && \
GOBIN=/go/bin go mod tidy && \
GOBIN=/go/bin USE_LIBSODIUM=1 USE_LZO=1 make install_and_build_pg
FROM postgres:$BASE
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update -qq && \
apt-get install -qqy curl ca-certificates vim && \
cd /usr/local/bin && curl -L https://github.com/wal-g/wal-g/releases/download/v0.2.2/wal-g.linux-amd64.tar.gz | tar xzf -
apt-get update && \
apt-get install -qqy curl ca-certificates libsodium23 vim
COPY --from=build /go/src/wal-g/main/pg/wal-g /usr/local/bin/wal-g
COPY wal-g /wal-g
+55 -48
View File
@@ -1,48 +1,55 @@
# Postgres WAL-G
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
helpful scripts. It allows you to simply and easily create continuous
archives of Postgres databases in S3-compatible storage.
## Environment
To use the image, you'll need to configure a bucket on your favorite S3-
compatible provider, and set a few environment variables:
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
to your bucket
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
[WAL-G documentation](https://github.com/wal-g/wal-g) for details)
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
## Configuration
In your `/varlib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
settings](https://www.postgresql.org/docs/9.1/continuous-archiving.html).
Importantly, you should set `archive_mode = on` and
`archive_command = 'wal-g wal-push %p'`. This will
tell Postgres to have WAL-G send WAL files to S3.
## Full Backups
To run a full backup, simply run `/wal-g/backup.sh`.
## Continuous Backups
These will happen automatically once you've started Postgres with your edited
`postgresql.conf` file (see
[Configuration](https://gitlab.koehn.com/docker/postgres-wal-g#configuration), above).
## Recovery
Testing recovery is simple: run a new Docker container with the correct
environment variables set and run `/wal-g/recover.sh`. It will:
1. Recover from the most recent full backup
2. Configure Postgres to not accept incoming connections or perform streaming
backups until the recovery is complete (important for testing!)
3. Configure Postgres to apply all the WAL files
4. Shut down Postgres, re-enable incoming connections and streaming backups
At this point you should have high confidence that the recovery was successful.
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
pushing additional WAL files to S3!
## Postgres Versions
Currently I build for Postgres 9.6 and Postgres 11. Be advised that 9.6 is the
earliest version that WAL-G supports.
# Postgres WAL-G
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
helpful scripts. It allows you to simply and easily create continuous, encrypted
archives of Postgres databases in S3-compatible storage.
## Environment
To use the image, you'll need to configure a bucket on your favorite S3-
compatible provider, and set a few environment variables:
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
to your bucket
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
[WAL-G documentation](https://github.com/wal-g/wal-g/blob/master/docs/PostgreSQL.md) for details)
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
* `WALG_LIBSODIUM_KEY` to encrypt the files stored in S3
## Configuration
In your `/var/lib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
settings](https://www.postgresql.org/docs/current/continuous-archiving.html).
Importantly, you should set `archive_mode = on` and
`archive_command = 'wal-g wal-push %p'`. This will
tell Postgres to have WAL-G send WAL files to S3.
## Full Backups
To run a full backup, simply run `/wal-g/backup.sh`.
## Continuous Backups
These will happen automatically once you've started Postgres with your edited
`postgresql.conf` file (see
[Configuration](#configuration), above).
## Recovery
Testing recovery is simple: run a new Docker container with the correct
environment variables set and run `/wal-g/recover.sh`. It will:
1. Recover from the most recent full backup
2. Configure Postgres to not accept incoming connections or perform streaming
backups until the recovery is complete (important for testing!)
3. Configure Postgres to apply all the WAL files
4. Shut down Postgres, re-enable incoming connections and streaming backups
At this point you should have high confidence that the recovery was successful.
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
pushing additional WAL files to S3!
## Postgres Versions
Currently I build for Postgres 16, but you can build for whatever version that wal-g supports.
## Kubernetes Deployments and Justfile
For an example of how to use this in Kubernetes (I happen to use k3s), you can check
out my deployment of this image [here](https://git.koehn.com/k3s-home/postgres).
That link also contains a `justfile` that has some useful recipes for creating
database, creating backups, testing backups, verifying backups, etc.
+8 -8
View File
@@ -2,18 +2,18 @@
set -e
REV=$1
# e.g., 14.3
PG_VERSION=$1
#e.g., v2.0.1
WALG_VERSION=$2
IMAGE_NAME=koehn/postgres-wal-g
build_image() {
BASE=$1
IMAGE=$IMAGE_NAME:$BASE-$REV
docker build --pull -t "$IMAGE" --build-arg BASE=$BASE .
docker push $IMAGE
IMAGE=$IMAGE_NAME:$BASE-$WALG_VERSION
docker buildx build -t $IMAGE --push . --build-arg BASE=$PG_VERSION --build-arg WALG_RELEASE=$WALG_VERSION --ulimit memlock=16384:16384 --platform linux/amd64,linux/arm64 --sbom=true --provenance=true
}
build_image "11.1" "$REV"
build_image "9.6"
build_image "$PG_VERSION" "$WALG_VERSION"
wait
+3
View File
@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}
+2
View File
@@ -1,5 +1,7 @@
#!/bin/bash
# A simple script to push a backup of your database.
if [ -z ${PGDATA+x} ]; then
export PGDATA=/var/lib/postgresql/data/pgsql
fi
+8 -4
View File
@@ -2,12 +2,16 @@
set -e
export DATA=/var/lib/postgresql/data/pgsql
if [ -z ${PGDATA+x} ]; then
export PGDATA=/var/lib/postgresql/data/pgsql
fi
export PG_VERSION=$(ls /usr/lib/postgresql/)
# disable recovery mode, re-enable remote connections and archive mode
mv $DATA/pg_hba.conf.orig $DATA/pg_hba.conf
sed -i -e 's/^archive_mode = off/archive_mode = on/' $DATA/postgresql.conf
mv $PGDATA/pg_hba.conf.orig $PGDATA/pg_hba.conf
mv $PGDATA/postgresql.conf.orig $PGDATA/postgresql.conf
sed -i -e 's/^archive_mode = off/archive_mode = on/' $PGDATA/postgresql.conf
cat <<EOF
******************
@@ -17,5 +21,5 @@ cat <<EOF
******************
EOF
bash -c "sleep 3 && /usr/lib/postgresql/$PG_VERSION/bin/pg_ctl stop -D $DATA" &
bash -c "sleep 3 && /usr/lib/postgresql/$PG_VERSION/bin/pg_ctl stop -D $PGDATA" &
+36 -4
View File
@@ -1,13 +1,37 @@
#!/bin/bash
if [ $(id -u) == "0" ] ; then
echo "this command must be run as the postgres user."
# Recovery script:
# * Calls wal-g to recover the latest database
# * Configures postgres to enter recovery mode by:
# * 1. Setting signal
# * 2. Appending wal-g recovery commands onto postgresql.conf
# * 3. Configuring postgres to only allow connections from localhost, preventing concurrent updates
# * 4. Disabling archive mode so as not to corrupt S3 backups
# * Starts postgres
#
# If you get an error message, DON'T PANIC! Just read the message and do what it tells you to do.
[ -z ${AWS_ACCESS_KEY_ID+x} ] && VARS="$VARS AWS_ACCESS_KEY_ID"
[ -z ${AWS_SECRET_ACCESS_KEY+x} ] && VARS="$VARS AWS_SECRET_ACCESS_KEY"
[ -z ${AWS_ENDPOINT+x} ] && VARS="$VARS AWS_ENDPOINT"
[ -z ${AWS_REGION+x} ] && VARS="$VARS AWS_REGION"
[ -z ${WALG_S3_PREFIX+x} ] && VARS="$VARS WALG_S3_PREFIX"
[ -z ${WALG_LIBSODIUM_KEY+x} ] && VARS="$VARS WALG_LIBSODIUM_KEY"
if [ ! -z "$VARS" ] ; then
echo "The following enviornment variables must be set:$VARS"
exit 1
fi
set -e
if [ $(id -u) == "0" ] ; then
echo "this command must be run as the postgres user (\`su postgres\`)."
exit 1
fi
set -euo pipefail
if [ -z ${PGDATA+x} ]; then
echo "Setting PGDATA to /var/lib/postgresql/data/pgsql"
export PGDATA=/var/lib/postgresql/data/pgsql
fi
@@ -15,7 +39,9 @@ fi
wal-g backup-fetch $PGDATA LATEST
# enable recovery mode, disable remote connections and archive mode
cp /wal-g/recovery.conf $PGDATA/
touch $PGDATA/recovery.signal
cp $PGDATA/postgresql.conf $PGDATA/postgresql.conf.orig
cat /wal-g/recovery.conf >> $PGDATA/postgresql.conf
mv $PGDATA/pg_hba.conf $PGDATA/pg_hba.conf.orig
cp /wal-g/pg_hba.conf $PGDATA/pg_hba.conf
sed -i -e 's/^archive_mode = on/archive_mode = off/' $PGDATA/postgresql.conf
@@ -23,3 +49,9 @@ sed -i -e 's/^archive_mode = on/archive_mode = off/' $PGDATA/postgresql.conf
PG_VERSION=$(ls /usr/lib/postgresql/)
/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl start -D $PGDATA
echo "Recovery complete. Press <return> to continue."
echo "If this is a production recovery, simply restart the container."
echo ""
echo "To test the database, disable \`archive_mode\` in $PGDATA/postgresql.conf or you risk "
echo "corrupting backups of the production instance. Then run \`postgres start\` to start the instance in test mode."