#1. CLEAN ARCHIVELOG SHELL SCRIPT
```
#!/usr/bin/bash
#for dg del archive log
#user: oracle
set -e
export ORACLE_HOME=/opt/app/11.2.0.1/db_1
export ORACLE_SID=fchdb
export TNS_STANDBY=fchdb_zs
export ORACLE_SYS_PWD=123
export SCRIPT_DIR=/opt/app/scripts
export ARCHIVELOG_DIR=/opt/app/ARCH
export RMAN_LOG_FILE=${SCRIPT_DIR}/rman_`date +%Y%m%d`.log
# Check USER IS ORACLE
if [ `whoami` != "oracle" ]
then
echo "Error: Need user oracle to run this script."
exit 1
fi
DEL_ARCHIVELOG_SN_START=`ls -tr $ARCHIVELOG_DIR|head -1|cut -f2 -d_`
echo $DEL_ARCHIVELOG_SN_START
#连接备库查询
$ORACLE_HOME/bin/sqlplus -s "sys/${ORACLE_SYS_PWD}@${TNS_STANDBY} as sysdba" <<EOF >${SCRIPT_DIR}/ARCHIVELOG_MAX_APPLY_SN.log
set head off;
set feedback;
select max(sequence#) from v\$archived_log where applied='YES';
exit;
EOF
ARCHIVELOG_MAX_APPLY_SN=`cat ${SCRIPT_DIR}/ARCHIVELOG_MAX_APPLY_SN.log|awk '{print $1}'|grep ^[0-9]`
# 我这里是保留最近的10个归档文件,这个具体情况自己决定
ARCHIVELOG_MAX_APPLY_SN=`expr $ARCHIVELOG_MAX_APPLY_SN - 10`
echo $ARCHIVELOG_MAX_APPLY_SN
while [ $DEL_ARCHIVELOG_SN_START -lt $ARCHIVELOG_MAX_APPLY_SN ]
do
#物理删除归档日志
rm $ARCHIVELOG_DIR/1_${DEL_ARCHIVELOG_SN_START}_1107000691.dbf
DEL_ARCHIVELOG_SN_START=`expr $DEL_ARCHIVELOG_SN_START + 1`
echo $DEL_ARCHIVELOG_SN_START
done
#更新rman归档日志信息
$ORACLE_HOME/bin/rman target / log $RMAN_LOG_FILE append <<EOF
crosscheck archivelog all;
delete noprompt expired archivelog all;
EOF
set +e
```
#2. CRONTAB
```
*/30 * * * * sh /opt/app/scripts/clean_archivelog.sh >>/opt/app/scripts/clean_archivelog.log 2>&1
```
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




