【Oracle归档日志管理】ORACLE归档日志清理策略
- 定时任务制定
$ crontab -l #delete archivelog before 7 days 00 02 * * * sh /home/oracle/tkdba/del_arch_everyday.sh
- 脚本内容
脚本1:将包含$(date +%F)写到脚本中
$ cat /home/oracle/tkdba/del_arch_everyday.sh sh /home/oracle/tkdba/del_arch.sh >> /home/oracle/tkdba/logs/del_arch.log.$(date +%F) 2>&1
$ cat /home/oracle/tkdba/del_arch.sh
#!/bin/bash
. /home/oracle/.bash_profile
function getTime(){
CT="`date +'%F %T'`"
}
# maintenance database archivelog
START=`date +%s`
getTime
echo "${CT} [INFO] Start maintenance database: ${ORACLE_SID} ..."
echo '=================================================='
rman target / <<EOF
run{
crosscheck backup;
crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog all completed before 'sysdate-6';
delete noprompt obsolete;
}
quit;
EOF
echo '=================================================='
DELTA=$(($(date +%s) - ${START}))
getTime
echo "${CT} [INFO] Maintenance database ${ORACLE_SID} done, duration: $((${DELTA}/3600))hour $((${DELTA}%3600/60))minute $((${DELTA}%60))second. "
脚本2:操作系统清理归档文件
cat purgearch.sh#!/bin/bashcd /data/app/oracle/arch #归档目录for i in $(ls -lht|tail -1|awk '{print $8"-"$6"-"$7 "的日志将进行清理!!!"}'):doecho $i ;for file in $(ls -lht|tail -1|awk '{print $NF}'):doecho $file ;donedone