Linux automatically delete archive log shell script, oracle

Linux automatically delete archive log shell script, oracle

#clean_arch.sh

#!/bin/bash
export ORACLE_SID=orcl
export ORACLE_HOME=/home/oracle/tools/oracle11g/product/11.2.0/dbhome_1
export ORACLE_BASE=/home/oracle/tools/oracle11g
time=`date "+%Y%m%d"` 
logdir=/u01/archcleanlog 
#判断保存删除归档日志操作日志的目录是否存在
isDirectory(){
    
    
	if test -d $1
	then
		echo "$1目录存在!"
		else
			echo "$1目录不存在!,创建目录!"
			mkdir -p $1
	fi
}
#删除保存七天的删除归档日志操作日志
removeLog(){
    
    
	find $1 -type f -name "*.log" -mtime +7 -exec rm -rf {
    
    } \;
}
#删除7天前的归档日志
delete(){
    
    
	su - oracle -c "
	$ORACLE_HOME/bin/rman target /  <<EOF
	run{
	crosscheck archivelog all;
	delete noprompt expired archivelog all;
	DELETE noprompt ARCHIVELOG ALL COMPLETED BEFORE 'SYSDATE-7';
	}
	exit
	EOF" 
	echo "删除7天前的归档日志成功!" 
}
log(){
    
    
	tee -a $logdir/archClean_$time.log
}
removeLog $logdir | log
isDirectory $logdir | log
delete | log

The operation appears as follows, indicating that the deletion is successful.
Go to the /u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22 directory to view, the expired archive log has been deleted

released channel: ORA_DISK_1
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=1736 device type=DISK
List of Archived Log Copies for database with db_unique_name ORCL
=====================================================================

Key     Thrd Seq     S Low Time 
------- ---- ------- - ---------
1       1    7       A 22-OCT-20
        Name: /u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_7_hs1w0z0y_.arc

2       1    8       A 22-OCT-20
        Name: /u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_8_hs1zg4pq_.arc

3       1    9       A 22-OCT-20
        Name: /u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_9_hs1zocqd_.arc

deleted archived log
archived log file name=/u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_7_hs1w0z0y_.arc RECID=1 STAMP=1054463775
deleted archived log
archived log file name=/u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_8_hs1zg4pq_.arc RECID=2 STAMP=1054467268
deleted archived log
archived log file name=/u01/oracle/tools/oracle11g/flash_recovery_area/ORCL/archivelog/2020_10_22/o1_mf_1_9_hs1zocqd_.arc RECID=3 STAMP=1054467499
Deleted 3 objects

Guess you like

Origin blog.csdn.net/weixin_43614067/article/details/109470928