Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Backup/restore postgres in docker container
Backup:
docker exec -t -u postgres your-db-container pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat your_dump.sql | docker exec -i your-db-container psql -Upostgres
@tlvenn

This comment has been minimized.

Show comment
Hide comment
@tlvenn

tlvenn Apr 5, 2017

As explained in this article: http://durandom.de/docker/postgres/2016/12/20/pg_dump/ you should not pass -t to docker exec to backup your DB.

tlvenn commented Apr 5, 2017

As explained in this article: http://durandom.de/docker/postgres/2016/12/20/pg_dump/ you should not pass -t to docker exec to backup your DB.

@EvAlex

This comment has been minimized.

Show comment
Hide comment
@EvAlex

EvAlex Jun 3, 2017

Missing whitespace in restore command between "-U" and "postgres"

EvAlex commented Jun 3, 2017

Missing whitespace in restore command between "-U" and "postgres"

@ChunAllen

This comment has been minimized.

Show comment
Hide comment
@ChunAllen

ChunAllen May 14, 2018

To restore your dump file with specified user and database_name

cat your_dump.sql | docker exec -i {docker-postgres-container} psql -U {user} -d {database_name}

ChunAllen commented May 14, 2018

To restore your dump file with specified user and database_name

cat your_dump.sql | docker exec -i {docker-postgres-container} psql -U {user} -d {database_name}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment