Skip to content

Instantly share code, notes, and snippets.

@MoritzBuetzer
Created July 11, 2016 07:30
Show Gist options
  • Save MoritzBuetzer/1daf1852a70f19e866e7987ccb99413f to your computer and use it in GitHub Desktop.
Save MoritzBuetzer/1daf1852a70f19e866e7987ccb99413f to your computer and use it in GitHub Desktop.
Simple Script to dump remote db and import it local
#!/bin/sh
# Simple Script to dump remote db and import it local
# Usage: ./getdb.sh DBNAME
remoteHost=192.168.1.100
remotePw=testingtester
clear
echo "[Step 1/4] Get $1 DB"
mysqldump -uroot -h${remoteHost} -p${remotePw} $1 > $1.sql
if mysql -u root "${1}" >/dev/null 2>&1 </dev/null
then
# exists
read -p "[Step 2/4] db exist -> wanna drop database $1 (y/n)?" yn
case $yn in
[Yy]* ) mysql -u root -e "drop database ${1}; create database $1;"; break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n.";;
esac
else
# does not exist
echo "[Step 2/4] db does not exist -> create database $1"
mysql -u root -e "create database $1"
fi
echo "[Step 3/4] import database $1"
mysql -u root $1 < $1.sql
echo "[Step 4/4] delete local $1.sql"
rm $1.sql
echo "[finished!]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment