# Using RMAN to Delete Oracle Database Archive Logs
Login as oracle, create the script del_arch.sh as below:
~]$ cat > /home/oracle/scripts/del_arch.sh << "END" | |
#!/bin/env bash | |
if [[ -z $1 ]]; then | |
exit 1 | |
fi | |
. ~/.bash_profile | |
ORACLE_SID=$1 | |
$ORACLE_HOME/bin/rman log=/tmp/del_arch_$1_`date +%Y%m%d`.log <<EOF | |
connect target / | |
run { | |
crosscheck archivelog all; | |
delete noprompt expired archivelog all; | |
delete noprompt archivelog all completed before 'sysdate - 1'; | |
} | |
quit | |
EOF | |
find /tmp/ -type f -name "del_arch*.log" -mtime +5 -exec rm -f {} \; | |
END | |
~]$ chmod u+x /home/oracle/scripts/del_arch.sh |
Create cron tasks.
~]$ crontab -e | |
0 0 * * * /home/oracle/scripts/del_arch.sh orcl1 | |
0 0 * * * /home/oracle/scripts/del_arch.sh coco |