Public Repository

Last pushed: 5 months ago
Short Description
This docker basically is a cron trigger to perform backups of a postgresql ddbb
Full Description



This docker basically is a cron trigger to perform backups of a postgresql ddbb. It has been done from

The image is generated from FROM postgres:9.5.1

The backup is manage by a phyton script and the backup is done in several steps:

  1. dump of ddbb ...
    env PGPASSWORD=%s pg_dump -Fc -h %s -U %s %s > %s" % (DB_PASS, DB_HOST, DB_USER, DB_NAME, backup_file))
  2. prune the old backups
    "find %s -type f -prune -mtime +7 -exec rm -f {} \;" % BACKUP_DIR
  3. Send notification mail in case is set up. The email contains the name of file, size and time take it.
  4. Call to a webhook in case that is set up.

Volumn expose

This docker expose the volumn /data/backups/ folder where is located the backups done.


Variables to can set up for the docker.

environment variables Example Description
DB_HOST 11.222.333.444 Host where is located the ddbb
DB_NAME postgres Name of ddbb
DB_USER myUser ddbb User
DB_PASS myPassword ddbb Password
CRON_SCHEDULE 0 23 * cron set up (example everyDay 23:00)
MAIL_GMAIL_USER Optional: gmail User
MAIL_GMAIL_PWD myPwdGmail Optional: gmail Password
MAIL_TO Optional: destination when is done the backup
MAIL_FROM Optional: from
WEBHOOK Optional: web hook when is done the backup
WEBHOOK_METHOD GET Optional: method to call web hook


Using docker-compose

Command line:
docker-compose up

Example of the configuration:

version: '2'
        container_name: postgresql-backup
        image: fmunozse/pg-cron-backups
          - ~/volumes/postgresql_backups/:/data/backups/
          - DB_HOST=11.222.333.444
          - DB_NAME=postgres
          - DB_USER=myUser
          - DB_PASS=myPassword
          - CRON_SCHEDULE=0 23 * * *
          - MAIL_GMAIL_PWD=myPassword

Others commands useful

Access to inside of docker:
docker exec -it postgresql-backup bash

Build the image:
docker build -t fmunozse/pg-cron-backups . or just run

Stop the docker-compose:
docker-compose stop

Docker Pull Command