天天看点

Oracle 数据库删除过期归档

#!/bin/bash

echo "----------------------------------------`date`---------------------------------------"

source ~/.bash_profile

delarchtime=`date +"20%y%m%d%h%m%s"`

rman_log_file=/home/oracle/del_arch_${delarchtime}.log

rman target / <<eof >> $rman_log_file

crosscheck archivelog all;

delete noprompt expired archivelog all;

delete noprompt archivelog all completed before 'sysdate-7';

eof

echo -e "\n"

echo "------------------------------------ finished ------------------------------------"

30 2 * * 0 /home/oracle/zzh/del_arch.sh

30 2 * * 0 nohup /home/oracle/zzh/log/delete_arch.sh >/dev/null 2>&1 &

eg:

delete noprompt archivelog until time "to_date('2019-09-02','yyyy-mm-dd')";

delete noprompt archivelog until time "to_date('2016-09-14 18:00:00','yyyy-mm-dd hh24:mi:ss')";

delete archivelog until sequence 16;

delete archivelog from time 'sysdate-1';    --> 注意这个命令,删除系统时间1天以内到现在的归档日志

delete noprompt archivelog all completed before 'sysdate';  --> 该命令清除当前所有的归档日志

delete noprompt archivelog all completed before 'sysdate-0';  --> 该命令清除当前所有的归档日志

delete noprompt archivelog all; --> 该命令清除当前所有的归档日志

delete force archivelog all completed before 'sysdate-1/24';    --> 清理一个小时前的归档日志