From 101949343a3eb3187e61965289b82d8e42acbd5e Mon Sep 17 00:00:00 2001 From: Miha Rekar Date: Mon, 14 Oct 2024 14:09:02 +0200 Subject: [PATCH 1/3] Use postgres alpine images --- .github/workflows/build-and-push-images.yml | 13 +++++++------ Dockerfile | 4 ++-- README.md | 4 ++-- docker-compose.yaml | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-and-push-images.yml b/.github/workflows/build-and-push-images.yml index 6b89df2..3554846 100644 --- a/.github/workflows/build-and-push-images.yml +++ b/.github/workflows/build-and-push-images.yml @@ -11,11 +11,12 @@ jobs: strategy: matrix: include: - - { postgres: 12, alpine: '3.12' } - - { postgres: 13, alpine: '3.14' } - - { postgres: 14, alpine: '3.16' } - - { postgres: 15, alpine: '3.17' } - - { postgres: 16, alpine: '3.19' } + - { postgres: 12 } + - { postgres: 13 } + - { postgres: 14 } + - { postgres: 15 } + - { postgres: 16 } + - { postgres: 17 } steps: - name: Checkout repository @@ -40,7 +41,7 @@ jobs: push: true tags: ${{ github.repository }}:${{ matrix.postgres }} build-args: | - ALPINE_VERSION=${{ matrix.alpine }} + POSTGRES_VERSION=${{ matrix.postgres }} platforms: | linux/amd64 linux/arm64 diff --git a/Dockerfile b/Dockerfile index 16915d7..0600430 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ -ARG ALPINE_VERSION -FROM alpine:${ALPINE_VERSION} +ARG POSTGRES_VERSION +FROM postgres:${POSTGRES_VERSION}-alpine ARG TARGETARCH ADD src/install.sh install.sh diff --git a/README.md b/README.md index 67e2f99..7cd1d89 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,9 @@ docker exec sh restore.sh # Development ## Build the image locally -`ALPINE_VERSION` determines Postgres version compatibility. See [`build-and-push-images.yml`](.github/workflows/build-and-push-images.yml) for the latest mapping. +`POSTGRES_VERSION` determines Postgres version. ```sh -DOCKER_BUILDKIT=1 docker build --build-arg ALPINE_VERSION=3.14 . +DOCKER_BUILDKIT=1 docker build --build-arg POSTGRES_VERSION=17 . ``` ## Run a simple test environment with Docker Compose ```sh diff --git a/docker-compose.yaml b/docker-compose.yaml index 16ac481..d26e990 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -12,11 +12,11 @@ services: build: context: . args: - ALPINE_VERSION: '3.16' + POSTGRES_VERSION: '17' environment: - SCHEDULE: '@weekly' # optional - BACKUP_KEEP_DAYS: 7 # optional - PASSPHRASE: passphrase # optional + SCHEDULE: '@weekly' # optional + BACKUP_KEEP_DAYS: 7 # optional + PASSPHRASE: passphrase # optional S3_REGION: S3_ACCESS_KEY_ID: S3_SECRET_ACCESS_KEY: From 5e37e75e5a78379c0fdc4dd96ba7b284147b4290 Mon Sep 17 00:00:00 2001 From: Miha Rekar Date: Sat, 15 Feb 2025 09:30:06 +0100 Subject: [PATCH 2/3] Run actions again From 376c3f73b02e7b572d6b275840df4114b242ce15 Mon Sep 17 00:00:00 2001 From: Miha Rekar Date: Sun, 5 Oct 2025 12:40:22 +0200 Subject: [PATCH 3/3] OG project was archived so take control of my fork --- .dir-locals.el | 4 -- .github/workflows/build-and-push-images.yml | 47 --------------------- .gitignore | 2 - LICENSE.txt | 2 +- README.md | 46 +++++++++----------- docker-compose.yaml | 28 ------------ template.env | 4 -- 7 files changed, 20 insertions(+), 113 deletions(-) delete mode 100644 .dir-locals.el delete mode 100644 .github/workflows/build-and-push-images.yml delete mode 100644 .gitignore delete mode 100644 docker-compose.yaml delete mode 100644 template.env diff --git a/.dir-locals.el b/.dir-locals.el deleted file mode 100644 index 3b14d0c..0000000 --- a/.dir-locals.el +++ /dev/null @@ -1,4 +0,0 @@ -;;; Directory Local Variables -;;; For more information see (info "(emacs) Directory Variables") - -((sh-mode . ((sh-basic-offset . 2)))) diff --git a/.github/workflows/build-and-push-images.yml b/.github/workflows/build-and-push-images.yml deleted file mode 100644 index 3554846..0000000 --- a/.github/workflows/build-and-push-images.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: build and push images - -on: - push: - branches: ['master'] - -jobs: - build-and-push-image: - runs-on: ubuntu-latest - - strategy: - matrix: - include: - - { postgres: 12 } - - { postgres: 13 } - - { postgres: 14 } - - { postgres: 15 } - - { postgres: 16 } - - { postgres: 17 } - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Log in to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push Docker image - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: ${{ github.repository }}:${{ matrix.postgres }} - build-args: | - POSTGRES_VERSION=${{ matrix.postgres }} - platforms: | - linux/amd64 - linux/arm64 diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 3bf780b..0000000 --- a/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -.idea -.env \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt index d1988db..cf50b4a 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017 Johannes Schickling +Copyright (c) 2017 Johannes Schickling, Elliott Shugerman, and Miha Rekar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 7cd1d89..cd6a97c 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ # Introduction -This project provides Docker images to periodically back up a PostgreSQL database to AWS S3, and to restore from the backup as needed. + +This is a blatant fork of https://github.com/eeshugerman/postgres-backup-s3 which was itself a fork and re-structuring of @schickling's [postgres-backup-s3](https://github.com/schickling/dockerfiles/tree/master/postgres-backup-s3) and [postgres-restore-s3](https://github.com/schickling/dockerfiles/tree/master/postgres-restore-s3). + +It was archived and I still relied on it. Plus I needed PG 18. + +# Building the image + +Obviously replace `miharekar` with your dockerhub username and `18.0` with the desired PostgreSQL version. + +``` +❯ docker build -t miharekar/postgres-backup-s3:18.0 --build-arg POSTGRES_VERSION='18.0' . && docker push miharekar/postgres-backup-s3:18.0 +``` # Usage ## Backup ```yaml services: - postgres: - image: postgres:16 - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: password - backup: - image: eeshugerman/postgres-backup-s3:16 + image: miharekar/postgres-backup-s3:18.0 environment: SCHEDULE: '@weekly' # optional BACKUP_KEEP_DAYS: 7 # optional @@ -28,7 +33,6 @@ services: POSTGRES_PASSWORD: password ``` -- Images are tagged by the major PostgreSQL version supported: `12`, `13`, `14`, `15` or `16`. - The `SCHEDULE` variable determines backup frequency. See go-cron schedules documentation [here](http://godoc.org/github.com/robfig/cron#hdr-Predefined_schedules). Omit to run the backup immediately and then exit. - If `PASSPHRASE` is provided, the backup will be encrypted using GPG. - Run `docker exec sh backup.sh` to trigger a backup ad-hoc. @@ -52,30 +56,16 @@ docker exec sh restore.sh docker exec sh restore.sh ``` -# Development -## Build the image locally -`POSTGRES_VERSION` determines Postgres version. -```sh -DOCKER_BUILDKIT=1 docker build --build-arg POSTGRES_VERSION=17 . -``` -## Run a simple test environment with Docker Compose -```sh -cp template.env .env -# fill out your secrets/params in .env -docker compose up -d -``` - # Acknowledgements -This project is a fork and re-structuring of @schickling's [postgres-backup-s3](https://github.com/schickling/dockerfiles/tree/master/postgres-backup-s3) and [postgres-restore-s3](https://github.com/schickling/dockerfiles/tree/master/postgres-restore-s3). -## Fork goals -These changes would have been difficult or impossible merge into @schickling's repo or similarly-structured forks. +As mentioned above, this project is a blatant fork of https://github.com/eeshugerman/postgres-backup-s3 + +As is the following text documenting the changes from the @schickling's [postgres-backup-s3](https://github.com/schickling/dockerfiles/tree/master/postgres-backup-s3): + - dedicated repository - automated builds - support multiple PostgreSQL versions - backup and restore with one image - -## Other changes and features - some environment variables renamed or removed - uses `pg_dump`'s `custom` format (see [docs](https://www.postgresql.org/docs/10/app-pgdump.html)) - drop and re-create all database objects on restore @@ -85,3 +75,5 @@ These changes would have been difficult or impossible merge into @schickling's r - support encrypted (password-protected) backups - support for restoring from a specific backup by timestamp - support for auto-removal of old backups + +What's new in my fork is solely support for later versions of PostgreSQL. diff --git a/docker-compose.yaml b/docker-compose.yaml deleted file mode 100644 index d26e990..0000000 --- a/docker-compose.yaml +++ /dev/null @@ -1,28 +0,0 @@ -# this file is here to facilitate development/testing -# $ docker compose up -d --build --force-recreate - -services: - postgres: - image: postgres:14 - environment: - POSTGRES_USER: user - POSTGRES_PASSWORD: password - - backup: - build: - context: . - args: - POSTGRES_VERSION: '17' - environment: - SCHEDULE: '@weekly' # optional - BACKUP_KEEP_DAYS: 7 # optional - PASSPHRASE: passphrase # optional - S3_REGION: - S3_ACCESS_KEY_ID: - S3_SECRET_ACCESS_KEY: - S3_BUCKET: - S3_PREFIX: backup - POSTGRES_HOST: postgres - POSTGRES_DATABASE: postgres - POSTGRES_USER: user - POSTGRES_PASSWORD: password diff --git a/template.env b/template.env deleted file mode 100644 index e0b5c24..0000000 --- a/template.env +++ /dev/null @@ -1,4 +0,0 @@ -S3_REGION="" -S3_ACCESS_KEY_ID="" -S3_SECRET_ACCESS_KEY="" -S3_BUCKET=""