几个DG维护脚本

来源:互联网 发布:淘宝小视频用什么软件 编辑:程序博客网 时间:2024/05/22 03:27

【转自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

原创粉丝点击