Last active
July 22, 2020 20:09
-
-
Save mbrookson/46288cda9d3d2a93c842a683d72e87cd to your computer and use it in GitHub Desktop.
Backup and restore dockerised postgres database
This file contains 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
# 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