A technical troubleshooting blog about Oracle with other Databases & Cloud Technologies.

Crontab : RMAN Backup

1 min read
close up shot of keyboard buttons

Photo by Miguel Á. Padriñán on Pexels.com

Automate RMAN Backup using Shell Script

In a real environment, you will not manually trigger all the Oracle database backups. You need an automated mechanism to trigger RMAN backups.

Create directory


On your database server, create a directory to hold RMAN backups and all related files. All the RMAN backups, logs and backup scripts are kept in one directory.


mkdir -p /u01/rman

Create RMAN backup script file

Let us create the RMAN backup script file to trigger DB FULL backup

vi /u01/rman/full_backup.sh
export ORACLE_SID=asrblg
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/19/db
export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH

rman target / nocatalog log=/u01/rman/RMAN_backup.log << EOF

run
{
allocate channel ch1 device type disk;
allocate channel ch2 device type disk;
allocate channel ch3 device type disk;
allocate channel ch4 device type disk;
sql ‘ALTER SYSTEM ARCHIVE LOG CURRENT’;
configure retention policy to recovery window of 5 days;
CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET PARALLELISM 4;
CROSSCHECK BACKUP DEVICE TYPE DISK;
CROSSCHECK ARCHIVELOG ALL;
delete noprompt archivelog all backed up 1 times to device type disk;
backup incremental level 0 as compressed backupset database archivelog all tag weekly_Full_backup delete input;
DELETE NOPROMPT OBSOLETE;
DELETE NOPROMPT EXPIRED BACKUP;
release channel ch1;
release channel ch2;
release channel ch3;
release channel ch4;
}
EOF
Change the permission 

Give execute permissions on the shell script:
chmod 775 /u01/rman/full_backup.sh
Schedule RMAN backup on crontab

Now you can go ahead and schedule the backup under the crontab. For example, we are scheduling backup to trigger at 2 am and 8 pm everyday.
crontab -e
00 02,20 * * * /u01/rman/full_backup.sh