ORACLE|ORACLE 定时清理7天前归档日志

[oracle@ORACLE122 ~]$ pwd
/home/oracle
[oracle@ORACLE122 ~]$ mkdir auto_deal
[oracle@ORACLE122 ~]$ cd auto_deal/
[oracle@ORACLE122 auto_deal]$ mkdir /home/oracle/auto_deal/data
[oracle@ORACLE122 auto_deal]$ cat auto_clear_arch.sh
----------------------------------------------------------------------------------------------------
[oracle@ORACLE122 auto_deal]$ cat auto_clear_arch.sh
#!/bin/sh
ORACLE_SID=MPMON; export ORACLE_SID
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/12.2.0/db_1; export ORACLE_HOME
PATH=.:${JAVA_HOME}/bin:${PATH}:$HOME/bin:$ORACLE_HOME/bin:
PATH=${PATH}:/usr/bin:/bin:/usr/bin/X11:/usr/local/bin
export PATH
BACK_DIR=/home/oracle/auto_deal/data
export DATE=`date +%F`
mkdir -p $BACK_DIR/$DATE
echo "----------start------------------------" > $BACK_DIR/$DATE/rman_backup.log
#echo `date '+%Y-%m-%d %H:%M:%S'` >> $BACK_DIR/$DATE/rman_backup.log
$ORACLE_HOME/bin/rman log=$BACK_DIR/$DATE/rman_backup.log target / < #检查归档
crosscheck archivelog all;
#删除无效归档
delete noprompt expired archivelog all;
#删除一天前的归档
#delete noprompt archivelog until time 'sysdate-1';
# delete force archivelog all completed before 'sysdate-1/24'; # 这里执行清除归档日志,如果不想手动输入YES,则可以添加noprompt参数
delete force noprompt archivelog all completed before 'sysdate-6';
#删除所有的归档
#delete nopromptarchivelogall;
exit;
EOF
echo "-----------end------------------------------" >> $BACK_DIR/$DATE/rman_backup.log
----------------------------------------------------------------------------------------------------
[oracle@ORACLE122 auto_deal]$ chmod +x auto_clear_arch.sh


【ORACLE|ORACLE 定时清理7天前归档日志】#每天早上5点运行 auto_clear_arch.sh
crontab –e
0 5 * * * /home/oracle/auto_deal/auto_clear_arch.sh
[oracle@ORACLE122 auto_deal]$ crontab -l
0 5 * * * /home/oracle/auto_deal/auto_clear_arch.sh

    推荐阅读