recoverLoacalDB

Because I’m lazy

#/*************************************************************************
 #> File Name: recoverLoacalDB_hellomoney.sh
 #> Author: Simon
 #> Mail: simon.xie@codewalker.me
 #> Created Time: Fri May 20 10:29:51 2016
 #************************************************************************/

#!/bin/bash 

read -p "Input Password for remote Database: " remoteDBP
read -p "Input Password for local Database: " localDBP

REMOTEDB_NAME=
REMOTEIP=
LOCALDB_NAME=
LOCALIP=

exportHellomoney(){
	echo "Downloading... wait a second..."
	mysqldump -h $REMOTEIP -u root -p$remoteDBP  REMOTEDB_NAME > /tmp/$LOCALDB_NAME.`date +%y%m%d`.sql
	echo 'Download  done.'
}
importDB(){
	echo 'Importing Database....'
	mysqldump -h $LOCALIP -u root -p$localDBP LOCALDB_NAME < /tmp/$LOCALDB_NAME.`date +%y%m%d`.sql
	echo 'Import  done.'
}
cleanTmp(){
	rm -fv /tmp/`date +%y%m%d`.sql
	echo 'Cleaning...'
}
read -p "Press Y to start: " isStart
case $isStart in
	y|Y)
		read -p "[d] only download|[r] download&Import|[i]Import|[c] do clean tmp file: " mOption
		 case $mOption in
			 d|D)
				 exportHellomoney
				 ;;
			 r|R)
				 exportHellomoney&&importDB
				 ;;
			 i|I)
				 importDB
				 ;;
			 c|C)
				 cleanTmp
				 ;;
			 *)  
				 echo 'Input error'
				 exit 0
				 ;;
		 esac
		 ;;
	*)
		echo 'Input error'
		exit 0
		;;
esac

read -p "Are you do clean? " isClear
case $isClear in
	y|Y)
		cleanTmp
		;;
	*)
		echo 'Input error'
		;;
esac
exit 1

发表评论

电子邮件地址不会被公开。 必填项已用*标注