Skip to content

Instantly share code, notes, and snippets.

@rkalkani
Last active June 27, 2020 10:50
Show Gist options
  • Save rkalkani/2eeb9699732b74c6d32fd533c1959ed4 to your computer and use it in GitHub Desktop.
Save rkalkani/2eeb9699732b74c6d32fd533c1959ed4 to your computer and use it in GitHub Desktop.
Snippets to backup/restore postgresql database from docker container
# Backup postgresql db from postgresql docker container
docker exec -i ${CONTAINER_NAME} pg_dump -U ${USERNAME} -w ${DB_NAME} -O -x | gzip -9 > $(date +%Y%m%d_%H%M%S)_${DB_NAME}.pgsql.gz
# Restore the postgresql db to postgresql docker container
gunzip -c ${FILENAME}.pgsql.gz | sudo docker exec -i ${CONTAINER_NAME} pg_restore -U ${USERNAME} -w -d ${DB_NAME} -C --clean -Fc -O -x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment