Casey

Full-Stack Developer

#docker #postgres

Dump Postgres from a Container to a Compressed SQL File

This command assumes you have:

  • a container named postgress
  • a database named mydb
  • a user named root
  • a volume mounted at /db-backup
TIMESTAMP=$(date '+%Y%m%d-%H%M%S')
docker-compose exec -T postgres bash -c "pg_dump mydb -U root | gzip > /db-backup/dump-$TIMESTAMP.sql.gz"