同步数据库自动化脚本_MySQL

WBOY
发布: 2016-06-01 13:35:59
原创
1567 人浏览过

bitsCN.com

同步数据库自动化脚本

 

#!/bin/sh  www.bitsCN.com  

 

read -p "Please keyin your ssh host:" -t 30 host_ip

read -p "Please keyin your ssh user:" -t 30 username

read -p "Please keyin your ssh pass:" -t 30 password

read -p "Please keyin your sync table list,separated by spaces:" -t 30 table_list

 

datetime=`date +%Y%m%d%H%M%S`

src_file="/tmp/data_$datetime.sql"

tar_file="/tmp/data_$datetime.tar.gz"

 

mysqldump -h127.0.0.1 -uroot -ppass database_name $table_list > $src_file

tar czvf $tar_file $src_file

./expect_scp.sh $host_ip $username $password $tar_file

 

expect_scp.sh代码  www.bitsCN.com  

 

#!/tools/bin/expect

set timeout 10

set host [lindex $argv 0]

set username [lindex $argv 1]

set password [lindex $argv 2]

set src_file [lindex $argv 3]

#set dest_file [lindex $argv 4]

spawn scp $src_file $username@$host:/home/$username

 

expect {

"(yes/no)?"

{

send "yes/n"

expect "*assword:" { send "$password/n"}

}

"*assword:"

{

send "$password/n"

}

}

expect "100%"

expect eof

 

bitsCN.com
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板