How to Schedule RMAN Backups with Cron in Linux


 Introduction

As an Oracle DBA, scheduling regular backups is one of the most important tasks. Using RMAN with Linux cron jobs, you can automate database backups and ensure your data is always protected.


Step 1: Create RMAN Backup Script


1. Login as the Oracle user:


su - oracle


2. Create a backup script file:


vi /u01/backup/rman_full_backup.sh


3. Add the following content:


#!/bin/bash

export ORACLE_SID=ORA

export ORACLE_HOME=/u01/app/oracle/product/11.2.0

export PATH=$ORACLE_HOME/bin:$PATH


rman target / <<EOF

BACKUP DATABASE PLUS ARCHIVELOG;

DELETE NOPROMPT OBSOLETE;

EXIT;

EOF


4. Save and make it executable:


chmod +x /u01/backup/rman_full_backup.sh


Step 2: Test the Script Manually


Run the script to make sure it works:


/u01/backup/rman_full_backup.sh


Check the RMAN logs and confirm backup is successful.


Step 3: Schedule with Cron


1. Open crontab for the Oracle user:


crontab -e


2. Add an entry to run backup daily at 2 AM:


0 2 * * * /u01/backup/rman_full_backup.sh >> /u01/backup/rman_backup.log 2>&1


3. Save and exit.


Step 4: Verify Scheduled Jobs


List scheduled jobs:


crontab -l


Conclusion

By combining RMAN with Linux cron jobs, you can automate Oracle database backups and reduce the risk of data loss. Always monitor your logs and test recovery regularly to ensure your backup strategy is reliable.

Comments