> 数据库 > Oracle >

oracle下定时删除归档脚本

---del_arch.sh
#! /bin/bash
exec >> delarch`date +%y%m%d%H`.log
$ORACLE_HOME/bin/rman target / <crosscheck archivelog all;
delete noprompt expired archivelog all;
delete noprompt archivelog until time 'sysdate-14';
exit;
EOF

#说明:以上脚本删除14天以前所有归档日志,同时记录log
$ORACLE_HOME/bin/rman target / <等同于
$ORACLE_HOME/bin/rman <connect target sys/password@mydb
delete noprompt archivelog all completed before 'sysdate-14';
等同于
delete noprompt archivelog until time 'sysdate-14';
-------
Archivelog List Commands
RMAN>list archivelog all;
RMAN>list copy of archivelog until time ‘SYSDATE-10′;
RMAN>list copy of archivelog from time ‘SYSDATE-10′
RMAN>list copy of archivelog from time ‘SYSDATE-10′ until time ‘SYSDATE-2′;
RMAN>list copy of archivelog from sequence 1000;
RMAN>list copy of archivelog until sequence 1500;
RMAN>list copy of archivelog from sequence 1000 until sequence 1500;
-------
Archivelog Delete Commands
RMAN>delete archivelog all;
RMAN>delete archivelog until time ‘SYSDATE-10′;
RMAN>delete archivelog from time ‘SYSDATE-10′
RMAN>delete archivelog from time ‘SYSDATE-10′ until time ‘SYSDATE-2′;
RMAN>delete archivelog from sequence 1000;
RMAN>delete archivelog until sequence 1500;
RMAN>delete archivelog from sequence 1000 until sequence 1500;
Note : Also, you can use noprompt statement for do not yes-no question.
RMAN>delete noprompt archivelog until time ‘SYSDATE-10′;

AIX下计划任务
以下为rman定时删除归档日志方法:
将附件中del_arch.sh文件上传至数据库服务器,oracle用户的可读取目录,例如/home/oracle。赋予可执行权限(chmod +x del_arch.sh)
在root用户下,crontab -e
20 20 * * 3 su - oracle -c '/home/oracle/del_arch.sh' 引号内为脚本位置。(代表每周三20:20执行脚本,删除日志)


(责任编辑:IT)