/postgres-backup

Cron-automated Postgres backup running on Docker

Primary LanguageShellMIT LicenseMIT

postgres-backup

Cron-automated Postgres backup running on Docker

Clone project

git clone git@github.com:rspective/postgres-backup.git
cd postgres-backup

Image build

You need to be logged in your Docker Hub account locally

docker build ./
docker tag [IMAGE_ID] rspective/postgres_backup:[TAG_NAME]
docker push rspective/postgres_backup

Image build - M1 processors

A bit nicer and quicker way to build amdx64 (standard Intel) and arm platforms (M1):

docker buildx create --use 
docker buildx build --platform linux/amd64,linux/arm64 --push -t rspective/postgres_backup:<TAG-ID> .

More details can be found in this article

Using image

All variables are required, there is no default values

service_name:
    image: rspective/postgres_backup:[TAG_NAME]
    container_name: [CUSTOM_NAME]
    links:
      - pg # link your DB from other service
    environment:
      - POSTGRES_HOST=pg # DB alias
      - POSTGRES_PORT=5432 # DB port
      - POSTGRES_USER=db_username
      - POSTGRES_PASSWORD=db_password
      - POSTGRES_DB=db_name
      - CRON_TIME= */1 * * * * # CRON settings, max resolution - once in a minute - don't wrap it with quotes!
      - MAX_BACKUPS=30 # if there is more backup files than limit, the oldest one will be removed
      - WAL_DIRECTORY=/data/wal # location of WAL files
      - S3_BUCKET=test
      - S3_ACCESS_KEY=abcdef # login
      - S3_SECRET=abcdef # pass
      - S3_HOST=s3.netcloud.cloud
      - S3_PGP_KEY=younameit
      - SLACK_WEBHOOK=https://hooks.slack.com/services/123123123/123123123/kjqekqjweSAddaS23eadsDAS # if set you will see notifications from success and failure
      - PUB_KEY=base64_encoded_key
      - SIGNER_PRIVATE_KEY=base64_encoded_private_key
    volumes:
      - ./database/backup:/backup # backup files
      - ./database/failed:/_failed # failure logs

Helpful links