Dump a PostgreSQL Database for Backup

This is a short post - how to dump a named PostgreSQL database from a Docker container, primarily for backup purposes.

docker exec -t <CONTAINER_NAME_OR_ID> pg_dump -c -U postgres <DATABASE_NAME> | gzip > /backup/Docker/<DATABASE_NAME>_`date +%Y-%m-%d"_"%H%M%S`.gz  

This will output a tar and gzipped file ready to be imported into PostgreSQL.