Skip to content

Instantly share code, notes, and snippets.

@alphaJohnny
Created October 12, 2017 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphaJohnny/6d5bb0cfd6c616f9b47538dd16bacdb4 to your computer and use it in GitHub Desktop.
Save alphaJohnny/6d5bb0cfd6c616f9b47538dd16bacdb4 to your computer and use it in GitHub Desktop.
#!/bin/bash
#Usage: ./mysql-dump-from-rds-command-creator.bat > dump_commands.bat
#Usage2: ./dump_commands.bat
#Expects databases.txt newline delimited list of all databases
#Goal: Export MySQL data from AWS using SSH
#Step1: Create a databases.txt file with one line per database. Can be done by piping out "show databases" command
SSHUSER=ubuntu
SSHSERVER=server.com
SSHKEYFILE="/Users/am/Library/Mobile Documents/com~apple~CloudDocs/Keys/web-serv.pem"
DBSERVER=dbserver.us-east-1.rds.amazonaws.com
DBUSER=admin
DBPASS=admin
filename='databases.txt'
exec 4<$filename
echo "#!/bin/bash"
while read -u4 p ; do
echo "ssh -i \"$SSHKEYFILE\" $SSHUSER@$SSHSERVER \"mysqldump -u$DBUSER -p$DBPASS -h$DBSERVER "$p" | gzip -9\" | gzip -d > "$p.sql
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment