Sign inSign up

thomaslule/postgres-mail-backup

By thomaslule

Updated over 6 years ago

Image
0

100K+

thomaslule/postgres-mail-backup repository overview

postgres-mail-backup

A docker image that is scheduled to backup a postgres database and send the export file to a mail address.

Usage example

Docker-compose usage example:

version: "3"
services:
  postgres:
    image: postgres:12.2-alpine
    environment:
      POSTGRES_PASSWORD: admin
      PGDATA: /data/postgres
    volumes:
      - postgres_data:/data/postgres

  postgres-backup:
    image: thomaslule/postgres-mail-backup:latest
    depends_on:
      - postgres
    environment:
      MAILBACKUP_DB_CONNECTION_STRING: postgresql://postgres:admin@postgres:5432/postgres
      MAILBACKUP_CRON_SCHEDULE: "0 5 * * 0"
      MAILBACKUP_SMTP_CONFIG: '{"host":"smtp.gmail.com","auth":{"user":"[email protected]","pass":"its password"}}'
      MAILBACKUP_FROM_MAIL: [email protected]
      MAILBACKUP_TO_MAIL: [email protected]

  volumes:
    postgres_data:

For a simple usage without any encryption from a gmail address, you'll have to enable "less secure apps" on the sender account: https://myaccount.google.com/lesssecureapps?pli=1

Environment variables

MAILBACKUP_DB_CONNECTION_STRING

The connection string for your postgres database.

  • required: false
  • default: postgresql://postgres:admin@localhost:5432/postgres
MAILBACKUP_CRON_SCHEDULE

The CRON expression that describes when the export must be done.

  • required: false
  • default: 0 5 * * 0 (every sunday at 05:00)
MAILBACKUP_SMTP_CONFIG

A JSON-encoded string describing the SMTP configuration for NodeMailer. This will be passed as first argument of its createTransport function. See the doc here.

  • required: true
MAILBACKUP_FROM_MAIL

The sender mail address.

  • required: true
MAILBACKUP_TO_MAIL

The recipient mail address.

  • required: true

Limitation

This docker image uses pg_dump and if its version isn't exactly the same as the postgres server version, this tool will fail with the error aborting because of server version mismatch.

In order to have the same pg_dump version as your database, you must rebuild this image from another alpine version, you can search an alpine branch that contain the right postgres version here.

Tag summary

Content type

Image

Digest

Size

21.7 MB

Last updated

over 6 years ago

docker pull thomaslule/postgres-mail-backup