Docker: Backup postgressql

Neste exemplo para executar um backup em num contêiner Postgres
# compose.yml

version: '3.9'
services:
  postgres:
    image: postgres:14-alpine3.16
    restart: unless-stopped
    volumes:
      - ./volumes/pg_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
# .env

POSTGRES_DB=database
POSTGRES_USER=usdb
POSTGRES_PASSWORD=pwdb!@Xpt0
Com o contêiner rodando, execute o comando abaixo:
source .env && docker-compose exec postgres pg_dump -U${POSTGRES_USER} > scripts/pgdump-$(date +%F_%T).sql; or
source .env && docker-compose exec postgres pg_dump -U${POSTGRES_USER} > scripts/pgdump-$(date +%F_%X).sql

 





Comentários