Created
September 2, 2021 12:19
-
-
Save keyro90/89dfc0212763b5b224d8f990367749f6 to your computer and use it in GitHub Desktop.
Postgresql dump with docker container script
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
#!/usr/bin/env bash | |
HOST="" | |
PORT="" | |
DB="" | |
USER="" | |
PASSWORD="" | |
PGSQL_VERSION="" | |
mkdir -p tmp | |
rm -rf tmp/* | |
# create pgpass. | |
echo "${HOST}:${PORT}:${DB}:${USER}:${PASSWORD}" > ./tmp/pgpass | |
# set correct permssions. | |
chmod 600 ./tmp/pgpass | |
docker kill pgsql-dump >& /dev/null | |
docker run -e POSTGRES_PASSWORD="password" -e PGPASSFILE="/tmp/pgpass" -v $(pwd)/tmp:/tmp/ --rm -it --name pgsql-dump -d postgres:"${PGSQL_VERSION}" | |
# need to rewrite parameters inside dump command and generate sql file. | |
docker exec -it pgsql-dump /usr/bin/pg_dump --host="${HOST}" --port="${PORT}" --username="${USER}" --format=p --encoding=UTF-8 -n public "${DB}" > dump.sql | |
docker kill pgsql-dump >& /dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment