Skip to content

Instantly share code, notes, and snippets.

@misteio
Last active August 29, 2015 14:01
Show Gist options
  • Save misteio/038d0de8db6528e85569 to your computer and use it in GitHub Desktop.
Save misteio/038d0de8db6528e85569 to your computer and use it in GitHub Desktop.
Dump MySQL Throught SSH Tunnel
#!/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