docker-postgresql icon indicating copy to clipboard operation
docker-postgresql copied to clipboard

Backup concept does not work with docker-compose

Open BOW-el opened this issue 6 years ago • 0 comments

The neat concept to create a point-in-time-backup by specifying REPLICATION_MODE=backup and --volume /srv/docker/backups/postgresql.$(date +%Y%m%d%H%M%S):/var/lib/postgresql \ does not work for a docker-compose file since the volume name cannot be resolved in the yaml syntax. In order to allow for a declaration of a master and a backup container in a docker-compose file, it would be great if you could add an option, like BACKUP_SCHEDULE, that would persist the backup container continuously and creates a backup at regular time invervals defined by BACKUP_SCHEDULE in subfolders in the volume statically mounted to the container.

In order to illustrate my use case, consider the following docker-compose:

services:
  database:
    restart: always
    image: sameersbn/postgresql:latest
    environment:
      - DB_USER=XXXX
      - DB_NAME=XXXX
      - DB_EXTENSION=pg_trgm
      - USERMAP_UID=1001
      - USERMAP_GID=1001
      - REPLICATION_USER=repluser
    container_name: con_database
    env_file:
      - postgresql-env-secrets.env
    volumes:
      - '/srv/database:/var/lib/postgresql:z'
    networks:
      - net_database
  database_backup:
    restart: always
    image: sameersbn/postgresql:latest
    environment:
      - REPLICATION_MODE=backup
      - REPLICATION_SSLMODE=prefer
      - REPLICATION_HOST=database 
      - REPLICATION_PORT=5432
      - REPLICATION_USER=repluser
      - REPLICATION_PASS=XXXXX
      - BACKUP_SCHEDULE=10m
      - BACKUP_PATTERN=+%Y%m%d%H%M%S
    container_name: con_database_backup
    volumes: 
#  (THIS DOES NOT WORK)
#      - '/srv/database_backup/postgresql.$(date +%Y%m%d%H%M%S):/var
#STATIC FOLDER TO CREATE BACKUPS WITH PATTERN NAME
        - '/srv/database_backup:/var/lib/postgresql:z'      
    networks:
      - net_database    

In this setup, the backup container should ideally persist and create a backup every 10 minutes under a subfolder in the mounted volume /srv/database_backup using BACKUP_PATTERN

Would that be possible?

BOW-el avatar Jul 26 '19 10:07 BOW-el