Last active
March 30, 2022 09:02
-
-
Save vonschnappi/09552d21c683137a71bc7ac55876adb0 to your computer and use it in GitHub Desktop.
Get Postgres dump from an AWS RDS
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
DATABASE_HOST="DATABASE_HOST" | |
DATABASE_USERNAME="DATABASE_USERNAME" | |
PGPASSWORD="PASSWORD" | |
DATABASE_NAME="DATABASE_NAME" | |
EC2_HOST="USER@EC2_HOST" | |
DOWNLOAD_FOLDER="/home/user/Downloads" | |
ssh -i "keypair.pem" $EC2_HOST PGPASSWORD=$PGPASSWORD pg_dump -h $DATABASE_HOST -U $DATABASE_USERNAME -f dump.sql $DATABASE_NAME | |
if [ $? -ne 0 ]; then | |
echo "There was an issue connecting to the EC2 host or database" | |
exit | |
fi | |
scp -i "keypair.pem" $EC2_HOST:dump.sql $DOWNLOAD_FOLDER | |
if [ $? -ne 0 ]; then | |
echo "There was an issue downloading the dump file" | |
exit | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment