Thursday, May 2, 2013

Creating Rman Crontab Scripts for Backup Operations

Hello everyone,

In this post, i am gonna create two rman backup scripts on O/S and i will add them to crontab.

I need two scripts form backup operations and two other scripts to run these rman backup scripts. I am separating rman backup scripts from the scripts which run them in order to get easy maintenance on scripts.


First script connects database and operates a full backup.

[oracle@primarydb ~]$ 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;


Second script connects database and operates an incremental  backup.


[oracle@primarydb ~]$ 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 ~]$ cat run_rman_backup_full.sh 

#!/bin/sh

RMANDATE=`date +%d_%m_%Y`
WHEN=`date +%d_%m_%Y-%H:%M:%S`
RMANLOGS="/fra/flash_recovery_area/PRIDB/rmanlogs"
ORACLE_BIN="/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin"
ORACLE_SID="DB"

echo "Backup Alma Islemi Basladi.. " $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 Alma Islemi Sonlandi.. " $WHEN


[oracle@primarydb ~]$


[oracle@primarydb ~]$ cat run_rman_backup_incr.sh 

#!/bin/sh

RMANDATE=`date +%d_%m_%Y`
WHEN=`date +%d_%m_%Y-%H:%M:%S`
RMANLOGS="/fra/flash_recovery_area/PRIDB/rmanlogs"
ORACLE_BIN="/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin"
ORACLE_SID="DB"

echo "Backup Alma Islemi Basladi.. " $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 Alma Islemi Sonlandi.. " $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@primarydb ~]$ crontab -e
...

00 20 * * * /bin/sh  /home/oracle/run_rman_backup_full.sh > /dev/null
00 22 * * * /bin/sh  /home/oracle/run_rman_backup_incr.sh > /dev/null


One can check crontab by


[oracle@primarydb ~]$ crontab -l

00 20 * * * /bin/sh  /home/oracle/run_rman_backup_full.sh > /dev/null
00 22 * * * /bin/sh  /home/oracle/run_rman_backup_incr.sh > /dev/null


That's all..


You can write more detailed rman and runner scripts but do not forget to separate runner scirpts and rman scripts.

Thanks for reading :)



7 comments :

  1. I have a doubt .. I tried to create a script as below

    #!/bin/ksh
    export ORACLE_SID=orcl
    Today="`date +%d%m%Y`" # month number, day of month, year
    #mkdir DCTMTEST_rman_backups_$Today
    rman target /
    RUN {
    ALLOCATE CHANNEL ch1 TYPE
    DISK FORMAT '/mnt/hgfs/Shared/oraback/orcl_archives/ORCL/backupset/full/weekly_database_%d_t%t_s%s_p';
    BACKUP DATABASE PLUS ARCHIVELOG;
    RELEASE CHANNEL ch1;
    }
    EXIT;
    EOF


    But when i ran this script , it was on the rman prompt itself , It did not run the backup command . What could be the issue ?

    ReplyDelete
  2. add eof after rman target /

    ReplyDelete
  3. i want to create script for inserting 10000 record any record (for example 1 10000 number etc.)
    in emp table and some of them should delete automatically this cycle will continue using this method
    i will understand how redo is generatin and all thos things of real time for ORACLE DBA

    ReplyDelete