Last active
August 29, 2015 14:01
-
-
Save misteio/038d0de8db6528e85569 to your computer and use it in GitHub Desktop.
Dump MySQL Throught SSH Tunnel
This file contains hidden or 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
#!/bin/bash | |
# | |
# SSH Connection with kill itself | |
# | |
# set some variables | |
#Tunnel ssh | |
ec2rebond="" | |
ec2rebondkey="" | |
ec2localport="" | |
user="" | |
pw="" | |
db="" | |
server="" | |
sqldump="" | |
echo "Open ssh tunnel" >> $logfile | |
ssh -f -N -i $ec2rebondkey -L $ec2localport:$server:3306 $ec2rebond | |
pidssh=$(pgrep -n -x ssh) | |
echo pidssh=$pidssh | |
echo "Insert Database" >> $logfile | |
mysql -u $user $db -h 127.0.0.1 --port=$ec2localport --password=$pw < $sqldump 2>> $errfile | |
echo "**************************************" >> $logfile | |
echo "Fermeture tunnel ssh $pidssh" | |
kill $pidssh | |
echo "**************DONE****************" >> $logfile | |
echo "" >> $logfile | |
echo "" >> $logfile | |
echo "" >> $logfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment