Skip to content

Instantly share code, notes, and snippets.

@mbrookson
Last active July 22, 2020 20:09
Show Gist options
  • Save mbrookson/46288cda9d3d2a93c842a683d72e87cd to your computer and use it in GitHub Desktop.
Save mbrookson/46288cda9d3d2a93c842a683d72e87cd to your computer and use it in GitHub Desktop.
Backup and restore dockerised postgres database
# Backup
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_$(date +"%Y-%m-%dT%H-%M-%S").sql
# Backup gzipped
docker exec -t your-db-container pg_dumpall -c -U postgres | gzip > ./tmp/dump_$(date +"%Y-%m-%dT%H-%M-%S").gz
# -------------------------------------------------------------------------------------------------------------
# Restore
cat your_dump.sql | docker exec -i your-db-container psql -U postgres
# Restore gzipped
gzip -d ./tmp/dump_{DATE} | cat your_dump.sql | docker exec -i your-db-container psql -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment