Docker Community Forums

Share and learn in the Docker community.

How to setup full and incremental backups in docker container with postgres

I am trying to figure out how to start docker container with additional options to make incremental backups
I tried somehow to fill some enviroment variables, but it didn’t work (obviously)

    container_name: database
    image: $HOST/postgres:$POSTGRES_TAG
    restart: always
    labels:
      co.elastic.metrics/raw: "[{\"enabled\":true,\"metricsets\":[\"database\",\"bgwriter\",\"activity\",\"statement\"],\"module\":\"postgresql\",\"hosts\":[\"postgres://localhost:5432?sslmode=disable\"],\"username\":\"postgres\",\"password\":\"$DB_PASS\"}]"
    environment:
      POSTGRES_DB: portal
      POSTGRES_PASSWORD: $DB_PASS
      POSTGRES_HOST_AUTH_METHOD: 'local replication all trust'
      POSTGRES_WAL_LEVEL: 'replica'
      POSTGRES_ARCHIVE_MODE: 'on'
      POSTGRES_ARCHIVE_TIMEOUT: 60
      POSTGRES_MAX_WAL_SENDERS: 5
    ports:
      - "5432:5432"
    volumes:
      - /var/lib/postgresql/data:/var/lib/postgresql/data

How I can setup making incremental backups (wal) inside docker container?

Backup your databases
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_date +%d-%m-%Y"_"%H_%M_%S.sql
Restore your databases
cat your_dump.sql | docker exec -i your-db-container psql -U postgres

yeah, thanks for answer, you mentioned full backup

Can you help with continuous backups?

Bots like l.95 are here to annoy the users, not to give correct answers.

Not quite sure if this is what you are looking for, but in the docs for the bitnami/postgresql image it is explained how to setup master-slave replication (scroll down to “Setting up a streaming replication”).