Created
August 6, 2019 12:26
-
-
Save rodrigobertin/d3883a026523bc1140fe53f3e72afbfa to your computer and use it in GitHub Desktop.
Backup database postgres with docker
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 | |
export BASE=$(pwd) | |
export PASS=<pass> | |
export FILE=database.dump | |
export FILE_ST=database_st.dump | |
export DATABASE=<datbase> | |
export USER=<postgres> | |
export HOST_REMOTE=<remote> | |
echo '---------------> EXPORT DUMP Complete' | |
docker exec -it -e PGPASSWORD=${PASS} postgres pg_dump ${DATABASE} -Fc -f /tmp/${FILE} -U ${USER} -h ${HOST_REMOTE} | |
echo '---------------> EXPORT SQL Complete' | |
docker exec -it -e PGPASSWORD=${PASS} postgres pg_dump ${DATABASE} -f /tmp/${FILE}.sql -U ${USER} -h ${HOST_REMOTE} | |
echo '---------------> EXPORT DUMP Estructure' | |
docker exec -it -e PGPASSWORD=${PASS} postgres pg_dump ${DATABASE} -s -Fc -f /tmp/${FILE_ST} -U ${USER} -h ${HOST_REMOTE} | |
echo '---------------> EXPORT SQL Estructure' | |
docker exec -it -e PGPASSWORD=${PASS} postgres pg_dump ${DATABASE} -s -f /tmp/${FILE_ST}.sql -U ${USER} -h ${HOST_REMOTE} | |
echo '---------------> Copy Files' | |
docker cp postgres:/tmp/${FILE} app/bash/${FILE} | |
docker cp postgres:/tmp/${FILE}.sql app/bash/${FILE}.sql | |
docker cp postgres:/tmp/${FILE_ST} app/bash/${FILE_ST} | |
docker cp postgres:/tmp/${FILE_ST}.sql app/bash/${FILE_ST}.sql | |
echo '--------------> RESTORE DUMP' | |
docker exec -e PGPASSWORD=${PASS} -i postgres pg_restore -h 127.0.0.1 -U ${USER} --create --clean --no-acl --no-owner -d ${DATABASE} < ./app/bash/${FILE} | |
#echo '--------------> RESTORE SQL' | |
#docker exec -e PGPASSWORD=${PASS} -i postgres psql -h 127.0.0.1 -U franco -d ${DATABASE} < back_BASE_OK.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment