首页 > 代码库 > Linux下自动还原MySQL数据库的Shell脚本

Linux下自动还原MySQL数据库的Shell脚本

创建shell脚本topjui_source.exp,内容如下:

#!/usr/bin/expectspawn echo "###### running... ######"spawn echo $argv0spawn echo $argv1set timeout 30spawn mysql -uroot -p123456set timeout 30expect {	"hi" { send "You said hi\n"}	"hello" { send "Hello yourself\n"}	"bye" { send "That was unexpected\n"}	"mysql>" { send "use demo_topjui_com\r"}}expect {	#"mysql>" {send "source /home/backup/mysql/topjui/topjui.sql\r"}}expect "mysql>"send "exit\r"interact

加入到定时计划中,每5分钟自动还原一次topjui数据库:

*/5 * * * * /usr/bin/expect /home/shell/topjui_source.exp > /home/shell/log/topjui_source.log 2>&1

  

Linux下自动还原MySQL数据库的Shell脚本