Scheduling Archive Deletion and Database Full Backup 1738134436
Scheduling Archive Deletion and Database Full Backup 1738134436
As a database administrator, keeping the database optimized and ensuring backup strategies are robust is a critical part of
our daily operations. Recently, I have implemented an automated process using RMAN (Recovery Manager) to schedule
archive log deletion and full database backups, ensuring smooth operations and sufficient storage.
Test SETUP:-
/u001/scripts << Scripts Directory
/u001/scripts/logs << logfiles Directory
/u001/scripts/RMAN_BKP_FULL << Backup Directory
oemrepo << Database Name
oracle << OS User
/home/oracle << Oracle user Home Directory
================ =====================================
1⃣ Automated Archive Deletion:
To manage storage effectively, I scheduled a script to crosscheck and delete archived redo logs older than 3 days. This
ensures that the logs are no longer occupying valuable disk space after being backed up.
cat /u001/scripts/oemrepo_archive_delete.sh
ORACLE_SID=oemrepo
ORACLE_HOME=/u001/app/oracle/product/19.3/dbhome_1
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
export ORACLE_SID
d=`date '+%d%m%y'`
rman target / cmdfile=/u001/scripts/oemrepo_archive_delete_rman.rmn
log=/u001/scripts/logs/oemrepo_archive_delete_rman_$d.log
============================= ===========================
++2] archive delettion script: -
cat /u001/scripts/oemrepo_archive_delete_rman.rmn
run
{
crosscheck archivelog all;
delete force noprompt archivelog all completed before 'sysdate-3';
}
================ ===============================================
2⃣ Daily Full Database Backups:
Scheduling a daily RMAN full backup helps maintain a strong disaster recovery plan. These backups are critical for
ensuring the availability of the database, even in the event of unexpected failures.
The process is fully automated using cron jobs, running during off-peak hours to avoid impacting performance:
cat /u001/scripts/oemrepo_Rman_fullbkp.sh
ORACLE_SID=oemrepo
ORACLE_HOME==/u001/app/oracle/product/19.3/dbhome_1;export ORACLE_HOME
export ORACLE_HOME
PATH=$PATH:$ORACLE_HOME/bin
export PATH
export ORACLE_SID
d=`date '+%d%m%y'`
rman target / cmdfile=/u001/scripts/oemrepo_full.rmn log=/u001/scripts/logs/oemrepo_full_$d.log
============================ =============================================
++4] RMAN FULL backup Script : -
cat /u001/scripts/oemrepo_full.rmn
run
{
backup as copy current controlfile format '/u001/scripts/RMAN_BKP_FULL/control_before_backup_%T.ctl';
crosscheck backup;
delete backup completed before 'SYSDATE-1';
allocate channel c1 type disk;
allocate channel c2 type disk;
allocate channel c3 type disk;
allocate channel c4 type disk;
allocate channel c5 type disk;
delete backup completed before 'SYSDATE';
crosscheck backup;
backup as compressed backupset database format '/u001/scripts/RMAN_BKP_FULL/DBFULLBKP_%d_%s_%T_%p';
backup as copy current controlfile format '/u001/scripts/RMAN_BKP_FULL/control_after_backup_%T.ctl';
backup as compressed backupset archivelog ALL NOT BACKED UP 1 TIMES format
'/u001/scripts/RMAN_BKP_FULL/%d_%s_%T_%p_archive';
release channel c1;
release channel c2;
release channel c3;
release channel c4;
release channel c5;
}
=============== CRONTAB >> Set Cron here: - ========
crontab -l
#>>>>>> oemrepo archive delete through RMAN <<<<<<<<<
########################################
Benefits:
Optimized storage usage with regular archive log cleanups.
Reliable recovery strategy with consistent full database backups.
Zero manual intervention through automation.
Pro Tip: Always monitor logs and verify backups regularly to ensure the process is working as intended.
Implement log rotation to keep backup logs manageable...!
======================== ===================================================
www.linkedin.com/in/dbarashid2
--------------------------------------------- -----------------------------------------------------------------------------