Sign inSign up

richardwiden/postgresql-backup-s3

By richardwiden

•Updated 10 months ago

Image
0

3.2K

richardwiden/postgresql-backup-s3 repository overview

⁠postgres-backup-s3

Backup PostgresSQL to S3 (supports periodic backups) CI-dev-pipeline

⁠Basic Usage

$ docker run -e S3_ACCESS_KEY_ID=key -e S3_SECRET_ACCESS_KEY=secret -e S3_BUCKET=my-bucket -e S3_PREFIX=backup -e POSTGRES_DATABASE=dbname -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost itbm/postgres-backup-s3

⁠Kubernetes Deployment

apiVersion: v1
kind: Namespace
metadata:
  name: backup

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: postgresql
  namespace: backup
spec:
  selector:
    matchLabels:
      app: postgresql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: postgresql
    spec:
      containers:
      - name: postgresql
        image: itbm/postgresql-backup-s3
        imagePullPolicy: Always
        env:
        - name: POSTGRES_DATABASE
          value: ""
        - name: POSTGRES_HOST
          value: ""
        - name: POSTGRES_PORT
          value: ""
        - name: POSTGRES_PASSWORD
          value: ""
        - name: POSTGRES_USER
          value: ""
        - name: S3_ACCESS_KEY_ID
          value: ""
        - name: S3_SECRET_ACCESS_KEY
          value: ""
        - name: S3_BUCKET
          value: ""
        - name: S3_ENDPOINT
          value: ""
        - name: S3_PREFIX
          value: ""
        - name: SCHEDULE
          value: ""

⁠Environment variables

VariableDefaultRequiredDescription
POSTGRES_DATABASEYDatabase you want to backup or 'all' to backup everything
POSTGRES_HOSTYThe PostgreSQL host
POSTGRES_PORT5432The PostgreSQL port
POSTGRES_USERYThe PostgreSQL user
POSTGRES_PASSWORDYThe PostgreSQL password
POSTGRES_EXTRA_OPTSExtra postgresql options
S3_ACCESS_KEY_IDYYour AWS access key
S3_SECRET_ACCESS_KEYYYour AWS secret key
S3_BUCKETYYour AWS S3 bucket path
S3_PREFIXbackupPath prefix in your bucket
S3_REGIONus-west-1The AWS S3 bucket region
S3_ENDPOINTThe AWS Endpoint URL, for S3 Compliant APIs such as minio⁠
S3_S3V4noSet to yes to enable AWS Signature Version 4, required for minio⁠ servers
SCHEDULEBackup schedule time, see explainatons below
ENCRYPTION_PASSWORDPassword to encrypt the backup. Can be decrypted using openssl aes-256-cbc -d -in backup.sql.gz.enc -out backup.sql.gz
DELETE_OLDER_THANDelete old backups, see explanation and warning below
RESTORENoneNSet to LATEST to restore latest version or set to anything else to restore that
⁠Automatic Periodic Backups

You can additionally set the SCHEDULE environment variable like -e SCHEDULE="@daily" to run the backup automatically.

More information about the scheduling can be found here⁠.

⁠Delete Old Backups

You can additionally set the DELETE_OLDER_THAN environment variable like -e DELETE_OLDER_THAN="30 days ago" to delete old backups.

WARNING: this will delete all files in the S3_PREFIX path, not just those created by this script.

⁠Encryption

You can additionally set the ENCRYPTION_PASSWORD environment variable like -e ENCRYPTION_PASSWORD="superstrongpassword" to encrypt the backup. It can be decrypted using openssl aes-256-cbc -d -in backup.sql.gz.enc -out backup.sql.gz.

Tag summary

Content type

Image

Digest

sha256:731abb03d…

Size

155.8 MB

Last updated

over 2 years ago

docker pull richardwiden/postgresql-backup-s3