重庆思庄Oracle、KingBase、PostgreSQL、Redhat认证学习论坛

标题: 归档删除脚本,保留7天有效归档. [打印本页]

作者: Inkcup    时间: 2 小时前
标题: 归档删除脚本,保留7天有效归档.
用于11g及以上版本
创建文件:
arch_del.rcv
arch_del.sh
自动任务:
crontab -e

============================================================
[oracle@localhost arch]$ cat arch_del.rcv
DELETE NOPROMPT ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
CROSSCHECK ARCHIVELOG ALL;
DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
EXIT;
------------------------------------------------------------------------
[oracle@localhost arch]$ cat arch_del.sh
#!/bin/bash

export ORACLE_SID=orcl
export ORACLE_HOME=/home/oracle/19c
export PATH=$ORACLE_HOME/bin:$PATH

cmd=/home/oracle/arch/arch_del.rcv
log=/home/oracle/arch/arch_del_$(date +%Y%m%d_%H%M%S).log

echo "start clear arch : $(date)" | tee ${log}

rman target / log=${log} append << EOF
@${cmd}
EOF

echo "finished clear arch : $(date)" |tee -a ${log}
-----------------------------------------------------------------------------------------
crontab -l
30 2 * * * /home/oracle/arch/arch_del.sh





欢迎光临 重庆思庄Oracle、KingBase、PostgreSQL、Redhat认证学习论坛 (http://bbs.cqsztech.com/) Powered by Discuz! X3.2