As any other Unix/Linux dude or DBA you probably want to automate all tasks that can be automated, and backup is surely one thing that falls into this category. Like most people I use RMAN for backups, and to automate RMAN you should do some script work.
The first script performs a complete backup
[oracle@oradb01 ~]$ cat rman_backup_full.sh
connect target / backup incremental level 0 cumulative device type disk tag 'FULL' database; backup device type disk tag 'FULL_ARCH' archivelog all not backed up; run { allocate channel oem_backup_disk1 type disk maxpiecesize 1000 G; backup tag 'FULL_CNTRL' current controlfile; release channel oem_backup_disk1; } allocate channel for maintenance type disk; delete noprompt obsolete device type disk; release channel; exit;
The second script performs an incremental backup.
[oracle@oradb01 ~]$ cat rman_backup_incr.sh
connect target /
backup incremental level 1 cumulative device type disk tag ‘INCR’ database;
backup device type disk tag ‘INCR_ARCH’ archivelog FROM TIME ‘SYSDATE-7’;
run {
allocate channel oem_backup_disk1 type disk maxpiecesize 1000 G;
backup tag ‘INCR_CNTRL’ current controlfile;
release channel oem_backup_disk1;
}
allocate channel for maintenance type disk;
delete noprompt obsolete device type disk;
release channel;
exit;
Here is the runner scripts for backup scripts that i created above.
[oracle@primarydb ~]$ less run_rman_backup_full.sh
#!/bin/sh
RMANDATE=`date +%d_%m_%Y`
WHEN=`date +%d_%m_%Y-%H:%M:%S`
RMANLOGS=»/u01/flash_recovery_area/PRIDB/rmanlogs»
ORACLE_BIN=»/u01/oracle/app/oracle/product/11.2.0/db_1/bin»
ORACLE_SID=»DB»
echo «Backup Completed.. » $WHEN
. ~/.bash_profile
$ORACLE_BIN/rman cmdfile /home/oracle/rman_backup_full.sh log $RMANLOGS/rman_backup_full_$RMANDATE.log
WHEN=`date +%d_%m_%Y-%H:%M:%S`
echo «RMAN Backup Completed.. » $WHEN
[oracle@primarydb ~]$
[oracle@primarydb ~]$ less run_rman_backup_incr.sh
#!/bin/sh
RMANDATE=`date +%d_%m_%Y`
WHEN=`date +%d_%m_%Y-%H:%M:%S`
RMANLOGS=»/u01/flash_recovery_area/PRIDB/rmanlogs»
ORACLE_BIN=»/u01/oracle/app/oracle/product/11.2.0/db_1/bin»
ORACLE_SID=»DB»
echo «Backup Completed.. » $WHEN
. ~/.bash_profile
$ORACLE_BIN/rman cmdfile /home/oracle/rman_backup_incr.sh log $RMANLOGS/rman_backup_incr_$RMANDATE.log
WHEN=`date +%d_%m_%Y-%H:%M:%S`
echo «RMAN Backup Completed.. » $WHEN
Now, my scripts are ready to run. But first i need to check log file destination in script and then they are ready to add crontab.
We can add scripts to crontab by
[oracle@oradb01 ~]$ crontab -e [Make sure you do this as the Oracle-user, not root!]
…
00 20 * * * /bin/sh /home/oracle/Scripts/run_rman_backup_full.sh > /dev/null
00 50 * * * /bin/sh /home/oracle/Scripts/run_rman_backup_incr.sh > /dev/null
You can check your new crontab by
[oracle@oradb01 ~]$ crontab -l
00 20 * * * /bin/sh /home/oracle/Scripts/run_rman_backup_full.sh > /dev/null
00 50 * * * /bin/sh /home/oracle/Scripts/run_rman_backup_incr.sh > /dev/null
These are just examples, and you might want to use a different schedule to optimize time schedule or to adjust the scripts in terms of what you want RMAN to do for you.