Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Last active December 21, 2021 16:34
Show Gist options
  • Save xgenvn/ebc7986cbc7df0e4bc7c50f7e201be7a to your computer and use it in GitHub Desktop.
Save xgenvn/ebc7986cbc7df0e4bc7c50f7e201be7a to your computer and use it in GitHub Desktop.
pg dump & restore

Plain text format should work

docker exec -i shared_postgres_instance pg_dump -U postgres -W scons_com_vn_production > ~/backup/scons_com_vn_production.sql
docker exec -i shared_postgres_instance psql -U postgres scons_com_vn_prod -W < ~/backup/scons_com_vn_production.sql

binary format (tar, gzip) won't work using pipe

for backup, cp from container to host

docker exec -i shared_postgres_instance bash -c 'pg_dump -U postgres -F t -W scons_com_vn_production > /scons_com_vn_production.tar'
docker cp shared_postgres_instance:/scons_com_vn_production.tar ./scons_com_vn_production.tar

cp to running container first, then restore

docker cp ./scons_com_vn_production.tar shared_postgres_instance:/scons_com_vn_production.tar
docker exec -i shared_postgres_instance pg_restore -U postgres -W -d scons_tar_test -v -c -Ft /scons_com_vn_production.tar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment