码迷,mamicode.com
首页 > 其他好文 > 详细

del_archivelog

时间:2018-08-03 01:13:28      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:logs   eterm   cal   scripts   tin   standby   fine   feed   end   

#!/usr/bin/env bash                         
# INTRO : The script for delete physical standby applied archivelog.
#         Please set ur environment variables before use it.
#         Please execute the script on physical standby site.
#
# USAGE : ./del_archivelog.sh                                                            
#                                                                     
# TEST  : This script has been successfully tested on these platforms:                                                                     
#         Linux 
#         Physical standby
#         Oracle Database 10gR2,11gR2,Include RAC                            
#                                                       
# NOTE  : Please test this script in ur development environment 
#         before attempting to run it in production.                                     
# =================================================================================
 
#----------------------------------------------------------------------------------
###setup environment variables
export ORACLE_HOME=/oracle/app/oracle/product/11.2.0/db_1
export ORACLE_SID=standby
export PATH=$ORACLE_HOME/bin:$PATH
#export ARCHIVE_DIR=+DATA/standby/archivelog
export LOG_FILE=$HOME/scripts/logs/del_archive.log
#----------------------------------------------------------------------------------
 
###determine user 
if [ `whoami` != ‘oracle‘ ];then
echo "Warning: Please use oracle execute.">>$LOG_FILE
exit 99
fi
 
###define archivelog sequence will be deleted
sqlplus -s / as sysdba << EOF > tmp.log
set lines 100 feedback off echo off heading off;
select thread#,max(sequence#) from v\$archived_log where applied=‘YES‘ group by thread# order by thread#;
EOF
 
MAXLINE=`cat tmp.log|wc -l`
 
for (( i=1;i<$MAXLINE;i++ )); do
 
i=$(( i + 1 ))
THREAD=`sed -n "$i,$i"p tmp.log|awk -F‘ ‘ ‘{print $1}‘`
MAXSEQ=`sed -n "$i,$i"p tmp.log|awk -F‘ ‘ ‘{print $2}‘`
 
###Retains the most recent five Archive
MAXSEQ=$(( $MAXSEQ - 5 ))
 
###Delete physical standby applied archivelog
echo "****************************************************************************" >> $LOG_FILE
echo ">>> Begin deleting applied archivelogs : `date` <<<">>$LOG_FILE
 
i=$(( i - 1 ))
 
rman target / <<EOF >> $LOG_FILE
##catalog start with ‘$ARCHIVE_DIR‘ noprompt;
delete noprompt archivelog until sequence $MAXSEQ thread $THREAD;
EOF
 
echo >> $LOG_FILE
echo ">>> End delete applied archivelogs : `date` <<<">>$LOG_FILE
 
echo "****************************************************************************" >> $LOG_FILE
echo >> $LOG_FILE
 
done
 
rm -f tmp.log

 

del_archivelog

标签:logs   eterm   cal   scripts   tin   standby   fine   feed   end   

原文地址:https://www.cnblogs.com/liang545621/p/9410577.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!