Last active
July 8, 2025 17:36
-
-
Save tigusigalpa/c19d863e3cb7ff47900b3d3e88a34764 to your computer and use it in GitHub Desktop.
PostgreSQL (bitnami) dump from Docker container with custom port
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CLI command to dump the database dump from Docker container with custom port. Container based on bitnami/postgresql | |
docker exec -e PGPASSWORD="YOUR_PASSWORD" [CONTAINER_NAME] /opt/bitnami/postgresql/bin/pg_dump -p [YOUR_PORT_DEFAULT_5432] -U [POSTGRES_USER] -d [POSTGRES_DB] > backup.sql | |
# zip | |
docker exec -e PGPASSWORD="YOUR_PASSWORD" [CONTAINER_NAME] /opt/bitnami/postgresql/bin/pg_dump -p [YOUR_PORT_DEFAULT_5432] -U [POSTGRES_USER] -d [POSTGRES_DB] | zip > backup.sql | |
# zip with password | |
docker exec -e PGPASSWORD="YOUR_PASSWORD" [CONTAINER_NAME] /opt/bitnami/postgresql/bin/pg_dump -p [YOUR_PORT_DEFAULT_5432] -U [POSTGRES_USER] -d [POSTGRES_DB] | zip -e -P "ZIP_FILE_PASSWORD" backup.zip - | |
# zip with password and with named sql file (dump.sql) | |
TEMP_DIR=$(mktemp -d) && \ | |
docker exec -e PGPASSWORD="YOUR_PASSWORD" [CONTAINER_NAME] /opt/bitnami/postgresql/bin/pg_dump -p [YOUR_PORT_DEFAULT_5432] -U [POSTGRES_USER] -d [POSTGRES_DB] > "$TEMP_DIR/dump.sql" && \ | |
cd "$TEMP_DIR" && \ | |
zip -e -P "ZIP_FILE_PASSWORD" backup_$(date +%Y%m%d_%H%M%S).zip dump.sql && \ | |
mv backup_*.zip /tmp/ && \ | |
cd - && \ | |
rm -rf "$TEMP_DIR" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment