几个DG维护脚本

【转自qq477765261的博客,oracle高手】http://www.easyora.net/blog/dg_scripts_list.html

 

几个DG维护脚本

 

下午给项目搭建了套DG,没啥好说的,顺手写了几个脚本,后面还需完善完善.
1.主备库开机自动启动(自动判断库运行模式,如果为Primary ,则启动到open状态,如果为Standby,则启动到recover managed standby database状态)

#!/bin/bash
#Author:Kevin.yuan
#Create_Time:2008-12-11
#Description:
#1.The script just put /etc/init.d/rc.local ==> su - oracle -c “/home/oracle/dbstart.sh
#2.The script is used to startup the datbase automatically when the OS is up.If the database is primary role,then “alter database open”, if the role is standby,then “recover managed standby database…”

#This function is used to get the database’s current role (Primary: 1 /Standby 2 Other(error) 3)
get_role()
{
sqlplus -s “/as sysdba” << !
startup mount;
spool /home/oracle/jurge_role.log
set head off
set feedback off
select database_role from v/$database;
spool off
exit;
!
role=`cat /home/oracle/jurge_role.log|tail -1`
if [ $role = "PRIMARY" ]
then
return 1
elif [ $role = "STANDBY" ]
then
return 2
else
return 3
fi
}
#—–main begin——
source /home/oracle/.bash_profile
lsnrctl start
get_role
role_stat=$?
if [ $role_stat -eq 1 ]
then
sqlplus -s “/as sysdba” << !
alter database open;
exit
!
elif [ $role_stat -eq 2 ]
then
sqlplus -s “/as sysdba” << !
alter database recover managed standby database disconnect from session;
exit
!
fi

2.定期自动删除主库/备库端已经在备库上apply过的归档日志,我不太喜欢用OS命令下的rm删除归档,容易出毛病,而且不灵便,还是喜欢调用Rman的delete archivelog命令.(适用于rac环境)

#!/bin/bash
#Create_time:2008.12.12
#Author:Kevin.yuan
#Description:Delete the archived logs which had applied on Standby database.
source /home/oracle/.bash_profile
Dir=/opt/oracle/script/standby
cd $Dir
echo “rman target / log=rman_delete_arch.log” > rman_delete_arch.sh
echo “crosscheck archivelog all;” >> rman_delete_arch.sh
sqlplus -s “sys/sys as sysdba” >> rman_delete_arch.sh << !
set head off
set feedback off
select ‘delete noprompt archivelog until logseq ‘||max(sequence#)||’ thread ‘||thread#||’;’ from v/$log_history where RESETLOGS_CHANGE#=(select resetlogs_change# from v/$database) group by thread#;
exit
!
echo “exit;” >> rman_delete_arch.sh
echo “!” >> rman_delete_arch.sh
sed -i ‘/^$/d’ rman_delete_arch.sh
##delete the archived logs
sh rman_delete_arch.sh

不过还是写了一个利用os的rm命令来删除的脚本.

#!/bin/bash
#Create_time:2008.12.11
#Author:Kevin.yuan
#Description:Delete the archived logs which had applied on Standby database Using os command.
source /home/oracle/.bash_profile
##Here is the primay/standby archive dest
Arch_dest=/archive/test
Sc_dir=/opt/oracle/script/standby
cd $Sc_dir
sqlplus -s “sys/sys@paybilldg as sysdba” > standby.log << !
set head off
set feedback off
select ‘1_’||a.SEQUENCE#||’_'||a.RESETLOGS_ID||’.dbf’ from v$archived_log a where a.APPLIED=’YES’ and first_time>sysdate-8;
exit
!
##
cat /dev/null > rm_arch.sh
for i in `ls -l $Arch_dest|grep ‘1_’|awk ‘{print $NF}’` ; do
for j in `cat standby.log` ; do
if [ $i = $j ]
then
if [ `grep $i rm_arch.sh|wc -l` -eq 0 ]
then
echo “rm -f $Arch_dest/”$i>>rm_arch.sh
fi
fi
done
done
sh rm_arch.sh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值