Skip to content

Instantly share code, notes, and snippets.

@vonschnappi
Last active March 30, 2022 09:02
Show Gist options
  • Save vonschnappi/09552d21c683137a71bc7ac55876adb0 to your computer and use it in GitHub Desktop.
Save vonschnappi/09552d21c683137a71bc7ac55876adb0 to your computer and use it in GitHub Desktop.
Get Postgres dump from an AWS RDS
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