1. 首页
  2. IT资讯

自动删除归档日志的脚本(尤其是dataguard环境)

转自:

http://bbs.linuxtone.org/home.php?mod=space&uid=11671&do=blog&id=401

在此表示感谢,现在博客突然消失的太多,所以paste以备用。

[@more@]

自动删除归档日志的脚本(尤其是dataguard环境)

已有 236 次阅读2011-12-16 21:02 |个人分类:oracle data guard

自动删除归档日志的脚本(尤其是dataguard环境)

在归档模式下,要时刻注意磁盘空间不要被归档撑爆,尤其在dataguard环境中,更是需要定期清理已经apply的日志,以免把硬盘撑爆。在自动删除日志需要考虑几点:1. 日志必须是已经被apply的2. 日志备份已经被备份过的3. 为了保证一定的管理余地,不要apply后马上删除,而应该根据实际情况设定一个删除策略。4. 脚本要能够兼容primary和standby两种状态,且自动判断状态并执行不同的逻辑,否则在切换后,如果忘记修改脚本,那就可能杯具了。以下是我用于删除归档日志的一个脚本,运行这个脚本需要输入一个参数来控制日志的保留时间。这个脚本可用于primary端也可用于standby端,1. 对于standby端,只要在保存周期内且被apply的归档都会被删除2. 对于primary端,除了满足保存周期以及被apply条件外,还要保证归档已经被备份过才会被删除对于dataguard环境,虽然备份可以选择在primary和standby端执行,但如果压力不是非常大的话,为了管理方便,更建议在primary端执行。详细脚本如下:[oracle@dwapp1 DBA]$ cat delete_arch.sh #!/bin/bash#################################################################################################################### This script is to delete the arch logs for the standby database after it has applied the logs to the instance.###################################################################################################################source /home/oracle/.bash_profile#####################usage(){ #usageecho " USAGE: `basename $0` $retention"exit 2}ArgNum=1if [ ! $# -eq $ArgNum ];thenecho " "echo " Incorrect parameter"usagefiretention=$1script=`basename $0`dir=/tmptmpf=$dir/.$script.tmp# get archived log list for standby databasefunction GetLogListForStandby{sqlplus -S /nolog <<EOF > $tmpfconnect / as sysdbaset head offset feedback offset pages 0select name from(select name,sequence#,row_number() over(partition by a.sequence# order by name) rn,count(decode(applied,’YES’,1,null)) over (partition by a.sequence#) cn from v$archived_log awhere completion_time <sysdate-$retentionand a.resetlogs_id in (select i.resetlogs_id from v$database_incarnation i where status = ‘CURRENT’))where rn=1 and cn=1order by sequence#;exitEOFreturn}function GetDBRole{sqlplus -S /nolog <<EOF connect / as sysdbaset head offset feedback offset pages 0select controlfile_type from v$database;exitEOFreturn}# get archived log list for primary databasefunction GetLogListForPrimary{sqlplus -S /nolog <<EOF > $tmpfconnect / as sysdbaset head offset feedback offset pages 0select name from(select name,sequence#,row_number() over(partition by a.sequence# order by name) rn,sum(backup_count) over(partition by a.sequence# ) bk_cnt,count(decode(applied,’YES’,1,null)) over (partition by a.sequence#) cn from v$archived_log a where completion_time <sysdate-$retentionand a.resetlogs_id in (select i.resetlogs_id from v$database_incarnation i where status = ‘CURRENT’))where rn=1 and cn=1 and bk_cnt>0order by sequence#;exitEOFreturn}function GetDBRole{sqlplus -S /nolog <<EOFconnect / as sysdbaset head offset feedback offset pages 0select controlfile_type from v$database;exitEOFreturn}# check database roleDBROLE=`GetDBRole`NUM=0if [ $DBROLE = "CURRENT" ];thenecho "It’s a primary database ……"# get archived log list for primaryGetLogListForPrimaryelif [ $DBROLE = "STANDBY" ];thenecho "It’s a standby database ……"# get archived log list for standbyGetLogListForStandbyfiecho "deleting archived log files ……"if [ -n $tmpf ]; thenfor ARCH in `cat $tmpf`;doif [ -f $ARCH ];thenNUM=`expr $NUM + 1`rm -f $ARCHfidonefirm -f $tmpfecho "finished deleting $NUM files"使用测试:需要输入一个参数,用于设定保存周期。以下例子是删除3天前的归档[oracle@dwapp1 DBA]$ ./delete_arch.sh 3It’s a primary database ……deleting archived log files ……finished deleting 12 files设定定时任务自动执行1 */4 * * * /home/oracle/DBA/delete_arch.sh 2当然,对于非dataguard环境或者dataguard环境的primary端,更建议使用RMAN来管理归档了。
作者 space6212 http://space6212.itpub.net/post/12157/511689

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29578568/viewspace-2148010/,如需转载,请注明出处,否则将追究法律责任。

主题测试文章,只做测试使用。发布者:布吉卡,转转请注明出处:http://www.cxybcw.com/195041.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code