Oracle数据库删除归档脚本(实例)
#!/bin/sh
applied_days=2
cat /dev/null>applied_arch.lst
sqlplus -s "/as sysdba" <<EOF>/dev/null
set feedback off
set pages 0
set head off
set timing off
set echo off
spool applied_arch.lst
select 'rm -f'||' '||name from v\$archived_log where name like '%.dbf' and SEQUENCE#<(select max(sequence#) from v\$archived_log where applied='YES') and completion_time<=sysdate-${applied_days};
spool off;
exit
EOF
## Exec the shell
cat /dev/null>applied_arch.sh
cat applied_arch.lst |grep -v spooling>applied_arch.sh
chmod u+x applied_arch.sh
sh applied_arch.sh
chmod -x applied_arch.sh
mv applied_arch.sh rm_appl_arc_`date +"%Y%m%d%H%M"`.log
rm -f applied_arch.lst##remove expired archive log from database
/oracle/product/10.2.0/db_1/bin/rman target / nocatalog<</dev/null
crosscheck archivelog all;
delete noprompt expired archivelog all;
exit
EOF
数据库删除归档脚本