How to schedule shell script for rman backup using shell script to backup oracle database.

Here we will discuss about requirement configure shell script, configure shell script to backup & schedule shell script for rman backup script to complete rman full backup using crontab in Linux, Solaris and Unix platform. Cron job will be triggered as per scheduled time.

How to schedule shell script for rman backup?

 
In this post will cover how to prepare backup script in oracle using below steps. We have already test in test instance and live environment as well for daily, weekly, monthly and yearly backup.
 
 

Below rman backup example will do the following task using script shell programming and scripting.

 
👉 Backup Oracle Home binary file using tar.
 
👉Backup the complete database, control file and all archive logs.
 
👉Crosscheck database rman backup and archive log.
 
👉Delete old backup which have taken before 4 days.
 
👉Delete expired archive log.

Here we can see example of rman backup script for crontab.

 

 

We can schedule script using crontab for rman full backup script for windows, shell script for rman duplicate & rman restore shell script.

 

Step 1: Prepare Shell Script: –

 
copy the entire shell script and create rmanbkp.sh file.
 
Shell Script: – /data01/crontab_scripts/rmanbkp.sh
 
#!/bin/ksh
#Created by Sajid Quamer
. /data05/11.2.0.4/PROD_db.env
destnation=/backup/rmanPROD/`date +”%A”_”%d-%m-%y”_”%T”`
export destnation
old=/backup/rmanPROD/Last_`date +”%A”_”%d-%m-%y”_”%T”`
export old
#cd /backup/archive_bkp/
mv $destnation $old
mkdir -p $destnation
#Cleanig OLD Backup
rm -rf $old
cd /backup/rmanPROD/
find . -name “*.rbkp” -mtime +10 -exec rm -rf {} ;
find . -name “*.tgz” -mtime +10 -exec rm -rf {} ;
 
 

Backing up Oracle Binary file.

 
 
cd $ORACLE_HOME
tar -cvzf $destnation/11.2.0.4.tgz *
rman target / nocatalog cmdfile=/data01/crontab_scripts/rmanbkp.sql log=$destnation/full_bkp_.log
cd /backup/rmanPROD/
find . -name “*.rbkp” -mtime +10 -exec rm -rf {} ;
find . -name “*.tgz” -mtime +10 -exec rm -rf {} ;
#Transfer RMAN backup to Backup Server (172.168.11.10)
#sh /acedata01/crontab_scripts/rmanFTP.sh
bkp=`date +”%A”`
cd $destnation
ftp -n 172.168.11.10 << !EOF
user orauat orauat1
prompt
bin
cd /backup/rmanPROD
mkdir $bkp
cd /backup/rmanPROD/$bkp
lcd $destnation
mput *.tgz
mput DB*
mput ARCBAK*
mput C*
mput *.log
quit
!EOF
 

Step 2: Prepare Rman Backup script: –

simply copy the below rman backup script to make rmanbkp.sql file to perform rman full backup script oracle 19c.
 
 

Rman Backup Script file:-

 
/data01/crontab_scripts/rmanbkp.sql
 
RUN
{
    sql ‘alter system archive log current’;
    BACKUP AS compressed backupset filesperset 8 DATABASE FORMAT ‘$destnation/DB_%d_%p_%T_%s.rbkp’ TAG DAILY_HOT_BACKUP;
    sql ‘alter system archive log current’;
    BACKUP AS compressed backupset ARCHIVELOG ALL NOT BACKED UP 1 TIMES FORMAT ‘$destnation/ARCBAK_%d_%p_%T_%s.rbkp’ TAG ARCHIVE_BKP;
    BACKUP AS compressed backupset CURRENT CONTROLFILE FORMAT ‘$destnation/CNT_%d_%p_%T_%s.rbkp’ TAG CONTROL_FILE;
    CROSSCHECK COPY;
    CROSSCHECK BACKUP;
    CROSSCHECK ARCHIVELOG ALL;
    DELETE ARCHIVELOG UNTIL TIME ‘sysdate-4’ BACKED UP 1 TIMES TO DEVICE TYPE DISK;
    DELETE EXPIRED BACKUP;
    DELETE NOPROMPT OBSOLETE;
    DELETE NOPROMPT EXPIRED COPY;
    DELETE NOPROMPT EXPIRED BACKUP;
    DELETE NOPROMPT EXPIRED ARCHIVELOG ALL;
}
exit;
 
 
For more information about restoration using rman backup check another post, click here.
 
 

Step 3: Schedule rman backup shell scripts: –

 
 

Crontab syntax: –

 
Basically, Crontab file has six fields for specifying minute, hour, day of month, month, day of week and the command to be run.
 
* * * * * command or scripts file to be executed.
| ||||
| | | |+—–>day of week (0 -6) (Sunday=0)
| | | +——->month (1 -12)
| | +———>day of month (1 -31)
| +———–>hour (0 -23)
+————->minute (0 -59)
 

Crontab examples to automate shell script which already have explain above. We can schedule job for rman weekly and daily backup script.

 
00 1 * * *  /data01/crontab_scripts/rmanbkp.sh #Run at 01:00  am every day
 
00 20 * * * /data01/crontab_scripts/rmanbkp.sh #Runs at 08:00  pm every day
 
00 1 * * 0  /data01/crontab_scripts/rmanbkp.sh  #Runs at 1:00 am every Sunday
 
00 1 * * 7 <command> #Runs at 1:00 am every Sunday
 
00 1 * * Sun <command> #Runs at 1:00 am every Sunday
 
30 8 30,31 * * /data01/crontab_scripts/rmanbkp.sh #Runs at 8:30 am on the last day of every month
 
30 22 01 01 * * /data01/crontab_scripts/rmanbkp.sh #Runs at 10:30 Pm on the 1st January of every year.
 
 

Referenes/Related:-

19 thoughts on “How to schedule shell script for rman backup using shell script to backup oracle database.”

  1. Hi Sir, It is well explained but can you clarify me the source and destination? also can i have contact number. also i wanted to know how to take DB location backup from one DB server to Another DB server using shell script.

    Reply
  2. Well as i understand your concern , You just want to move DB backup from source to other destination. To do so you should prepare shell script as below.

    #!/bin/ksh
    destination=/backup/rmanPROD/`date +"%A"_"%d-%m-%y"_"%T"`
    export destination
    bkp=`date +"%A"`
    cd $destination
    ftp -n 192.168.11.25 << !EOF
    user orabkp orabkppassword
    prompt
    bin
    cd /backup/rmanPROD — destination of another server.
    mkdir $bkp
    cd /backup/rmanPROD/$bkp
    lcd $destination
    mput *.tgz
    mput DB*
    mput ARCBAK*
    mput C*
    mput *.log
    quit
    !EOF

    Destination Server:- 192.168.11.25 —where you want to move backup

    You have to mention Username and password of Destination Server. You can copy above script and make shell script and put the shell script in backup shell script file. Once backup will complete , This shell script will transfer your backup from source to destination on another server.

    Reply
  3. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

    IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

    corporate training in chennai corporate training in chennai

    corporate training companies in india corporate training companies in india

    corporate training companies in chennai corporate training companies in chennai

    I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai Project Centers in Chennai

    Reply

Leave a Comment