容灾的半自动化的部分,自己写了下面的脚本,也算是一个基本实现,因为时间仓促,还是存在一些不足,稍后完善
整个切换的步骤分为三部分,第一部分是备份当前备库的配置文件,第二部分是使用dg broker决定是failover还是switchover 第三部分是切换之后开始替换参数文件。
所以需要的脚本为dg_pre.sh dg_post.sh
dg_pre.sh是作为基本的备份,内容如下:
#### validate input parameters
#### validate if ip address is available
#### validate if ip address is the same as standby
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo .
sleep 2
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
sleep 1
if [ -n "$ORACLE_HOME" ]; then
cp $ORACLE_HOME/network/admin/tnsnames.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/listener.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/network/admin/sqlnet.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/init*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/spfile*.ora /home/conf/${ip_std_bak}
cp $ORACLE_HOME/dbs/orapw* /home/conf/${ip_std_bak}
echo '###### INFO BACKUP DB LEVEL CONF FILES ... DONE'
fi
sleep 1
echo .
cp /etc/hosts /home/conf/${ip_std_bak}
cp /etc/sysconfig/iptables /home/conf/${ip_std_bak}
cp /etc/sysconfig/network /home/conf/${ip_std_bak}
cp /etc/sysconfig/network-scripts/ifcfg-${eth_code} /home/conf/${ip_std_bak}
cp /etc/sysctl.conf /home/conf/${ip_std_bak}
cp /etc/security/limits.conf /home/conf/${ip_std_bak}
echo '###### INFO BACKUP OS LEVEL CONF FILES ... DONE'
sleep 1
####
dg_post是作为切换之后的补充,脚本如下:
#### validate input parameters
new_ip=$1
if [ ! $new_ip ];then
echo 'Target IP ADDRESS is needed ... '
exit;
fi
if [ ! -d /home/conf/$new_ip ];then
echo 'TARGET IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'$new_ip
exit;
fi
#### validate if ip address is available
#### get current ip address
curr_ipadd=`cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
echo '###### INFO Current IP ADDRESS IS : '$curr_ipadd
sleep 1 ;
if [ ! -d /home/conf/$curr_ipadd ];then
echo 'SOURCE IP CONF FILES NOT FOUND,SHOULD BE /home/conf/'${curr_ipadd}_std_bak
exit;
fi
#### validate if ip address is the same as standby
#if [[ ${new_ip} -eq ${curr_ipadd} ]];then
#echo 'SOURCE AND TARGET IP ADDRESS SHOULD NOT BE THE SAME ...'
#fi
echo .
ip_std_bak=${curr_ipadd}_std_bak
##get network card name
eth_code=`/sbin/ifconfig |grep -B1 ${curr_ipadd}|head -1|awk '{print $1}'`
echo '###### INFO Current NETWORK CARD NAME IS : '$eth_code
/sbin/ifconfig|grep -B1 `cat /etc/hosts|grep \`hostname\`|awk '{print $1}'`
if [ ! $eth_code ];then
echo 'WARNING... NETWORK CARD CODE IS EMPTY ...'
exit
fi
sleep 1 ;
echo .
#### backup all conf files
mkdir -p /home/conf/${ip_std_bak};
ORACLE_HOME=`cat /etc/oratab | tail -1 | awk -F: '{print \$2}' `
echo '###### INFO Current ORACLE_HOME is : '$ORACLE_HOME
echo .
if [ -n "$ORACLE_HOME" ]; then
echo '###### INFO RESTORE DB LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/tnsnames.ora $ORACLE_HOME/network/admin/tnsnames.ora
cp /home/conf/${new_ip}/listener.ora $ORACLE_HOME/network/admin/listener.ora
cp /home/conf/${new_ip}/sqlnet.ora $ORACLE_HOME/network/admin/sqlnet.ora > /dev/null 2>&1
fi
sleep 1 ;
echo '###### INFO RESTORE OS LEVEL CONF FILES'
echo .
cp /home/conf/${new_ip}/hosts /etc/hosts
cp /home/conf/${new_ip}/iptables /etc/sysconfig/iptables
cp /home/conf/${new_ip}/network /etc/sysconfig/network
sleep 1 ;
####change IP address
echo '###### INFO IP ADDRESS BEFORE CHANGE AS BELOW'
cat /home/conf/${ip_std_bak}/ifcfg-${eth_code} |tee /home/conf/tmp_eth.lst
sed -i "s/${curr_ipadd}/${new_ip}/g" /home/conf/tmp_eth.lst
sleep 1;
echo .
echo '###### INFO IP ADDRESS CHANGED AS BELOW'
cat /home/conf/tmp_eth.lst
cp /home/conf/tmp_eth.lst /etc/sysconfig/network-scripts/ifcfg-${eth_code}
cp /home/conf/$new_ip/network /etc/sysconfig/network
sleep 1;
echo .
new_hostname=`cat /etc/hosts|grep $new_ip|awk '{print $2}'`
echo $new_hostname
sleep 1;
hostname $new_hostname
ifdown ${eth_code}
sleep 1;
ifup ${eth_code}
sleep 1;
service network restart
dg_pre.sh运行的基本日志如下:
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO BACKUP DB LEVEL CONF FILES ... DONE
.
###### INFO BACKUP OS LEVEL CONF FILES ... DONE
dg_post.sh的日志如下:
# cat dg_post.log
###### INFO Current IP ADDRESS IS : 10.127.133.46
.
###### INFO Current NETWORK CARD NAME IS : eth0
eth0 Link encap:Ethernet HWaddr 84:2B:2B:69:EF:F8
inet addr:10.127.133.46 Bcast:10.127.133.255 Mask:255.255.255.0
.
###### INFO Current ORACLE_HOME is : /U01/app/oracle/product/11.2.0.2/db_1
.
###### INFO RESTORE DB LEVEL CONF FILES
.
###### INFO RESTORE OS LEVEL CONF FILES
.
###### INFO IP ADDRESS BEFORE CHANGE AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.46
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
###### INFO IP ADDRESS CHANGED AS BELOW
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.127.133.45
NETMASK=255.255.255.0
#GATEWAY=10.127.133.254
ONBOOT=yes
TYPE=Ethernet
.
BX_133_45
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth1: [ OK ]
后续继续完善。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23718752/viewspace-1984190/,如需转载,请注明出处,否则将追究法律责任。