使用的脚步有四个:【backup_unasyn.sh //备份所以执行的脚步
host_ip.sh //循环捕捉我服务器的ip进行
db_china.sh //服务器的hosts名
passwds.sh //登录服务器使用的密码
】
服务器结构:
IP1:113.11.226.112 IP2:113.11.226.113~116 IP3:113.11.226.118
IP1:执行脚本服务器【back_unasyn.sh、host_ip.sh、db_china.sh、passwds.sh】
Ip2:要备份的服务器
IP3:数据存放服务器
脚步展示如下所示:
[root@data ~]# vi passwds.sh
#!/bin/bash
pw1=123456
pw2=654321
============================================
[root@data ~]# vi host_ip.sh
#!/bin/bash
hosts=(
#china
113.11.226.113
113.11.226.114
113.11.226.115
113.11.226.116
)
==================================
[root@data ~]# vi db_china.sh
#!/bin/bash
#get the sh file.
shfile=$1
#set the script file path.
thepath=/root
date=`date +%Y%m%d`
source /root/host_ip.sh
source /root/passwds.sh
#set the update files.
servers=(
china1_db
china2_db //host名称对应ip
china3_db
china4_db
)
for i in ${servers[*]}
do
${thepath}/${shfile} ${i} $pw1 $pw2 $date $hosts
done
=====================================
[root@data ~]#vi backup_unasyn.sh
#!/usr/bin/expect
set host [lindex $argv 0]
set pwd1 [lindex $argv1]
set pwd2 [ lindex $argv2]
set date [lindex $argv 3]
set hosts [lindex $argv 4]
set back_host "113.11.226.118"
#======================================
set timeout 3600
# ssh to target machine
spawn ssh -p 50589 dwy@$host
expect "password:"
send "$pwd1/n"
# su as root
sleep 3
expect -re ".*"
send "su -/n"
expect "Password:"
send "$pwd2/n"
expect "#"
send "cd /home/cyanogen/backup/n"
# sftp put backup database
expect "#"
send "sftp -oPort=50589 dwy@$back_host/n"
expect "password:"
send "$pwd1/n"
expect "sftp>"
send "cd backup/n"
expect "sftp>"
send "put slg-$hosts-$date.gz/n"
expect "sftp>"
send "quit/n"
expect "#"
send "cd /var/log/n"
expect "#"
send "tail -21 secure >> /home/dwy/put_backup.log/n"
expect "#"
exit
=============================
脚本执行的过程:
./db_china.sh backup_unasyn.sh 时:
我怎样调用host_ip.sh中的ip让它进行循环,来完成我的过程。
请各位高手帮帮我,我的邮箱:dwy1008@163.com
qq:969856985