Oracle 删除归档日志脚本
归档日志记录着数据库的操作记录,是做数据恢复的依据,如果数据库开启了归档模式,那么就会产生大量的归档日志,当然如果有RMAN备份的话,可以在备份之后删除已经备份过的日志,如果是没有采用rman备份的话,就需要自己来删除这写归档日志。 下面的几个脚本就减轻了DBA的工作量。
Linux 平台:
0 2 * * * /home/oracle/scripts/del_archive.sh > /home/oracle/scripts/del_archive.log
[oracle@hfcc-svr-newccsdb1 ~]$ more /home/oracle/scripts/del_archive.sh
#!/usr/bin/ksh
# create by tianlesoftware
export ORACLE_HOME=/dba/oracle/product/10.2.0/db_1
export ORACLE_SID=orcl
export SHELL_DIR=/home/oracle/scripts
del_seq=`ls /u01/newccs_archive/|head -1|cut -f2 -d_`
echo $del_seq
$ORACLE_HOME/bin/sqlplus -s "sys/PWD@SID as sysdba" <<eof >/home/oracle/scripts/max
_sn.log
set head off;
set feedback;
select max(sequence#) from v/$log_history;
exit;
eof
max_sn=`cat /home/oracle/scripts/max_sn.log|awk '{print $1}'|grep ^[0-9]`
max_sn=`expr $max_sn - 5`
echo $max_sn
while [ $del_seq -lt $max_sn ]
do
rm /u01/archive/1_"$del_seq"_692846987.dbf
del_seq=`expr $del_seq + 1`
echo $del_seq
done
或者用脚本:
del_arc.sh
find /u01/backups -mtime +10 -name "*.dbf" -exec rm -rf {} /;
windows 平台:
del_arc_orcl.bat
forfiles /p d:/arc_orcl /m *.DBF /d -3 /c "cmd /c del @file"
将del_arc_orcl.bat 添加到计划任务即可.