RMAN L1 Database Backup Script

Sometimes, in addition to L0 Backup DBA also needs to take RMAN L1 backup due to many reasons like rman refresh,recovery etc. and during that time DBA needs to execute the L1 backup command but the biggest challenge comes for the DBA when the database size is huge and also the changes made after the L0 backup also huge in size which can takes many hours to complete and they can’t run that L1 backup in foreground so to overcome this challenge we can use rman automation backup script which takes database L1 backup in background.

 

Purpose of the Script -> Automate RMAN L1 Backup

Format to run the script à <Script_name.sh> <DBNAME>

Run this automation in background -> nohup ./L1_bkp_script.sh USPRIM &

 

NOTE A: Change database service name as per your environment highlighted in red.

 

NOTE B: You don’t need to set database environment and if you’ve already set then it’s also fine, just pass the correct database name along with the script name as defined above in “Format to run the script” section and the automation automatically set the environment for the database.

 

NOTE C: If you’re using this automation against RAC database then comment the line highlighted in green and uncomment the line highlighted in blue & bold.

 

NOTE D: If the database size is huge in several TB, then also use section size clause in L0 backup command.

  

BODY OF SCRIPT

 

#!/bin/bash

#set -xv

#set -n

mkdir -p /tmp/DB_L1_BKP

BKP_LOG=/tmp/DB_L1_BKP

RMAN_LOG=$BKP_LOG/L1_BKP.log

DBNAME=$1

DBNAME=`ps -ef |grep -i ora_pmon_$1 | grep -v grep | awk '{print $8}' | cut -d "_" -f3`

#DBNAME=`ps -ef |grep -i ora_pmon_$1 | grep -v grep | awk '{print $8}' | cut -d "_" -f3 | sed 's/.$//'`

DB_STATUS=`ps -ef|grep -i ora_pmon_$1 | grep -v grep | wc -l`

if [ ${DB_STATUS} -eq 1 ]

then

export ORACLE_SID=`ps -ef | grep -i ora_pmon_$1 | grep -v grep | cut -d "_" -f 3`

proid=`ps -ef | grep -i ora_pmon_$1 | grep -v grep | awk '{print $2}'`

var=`ls -l /proc/$proid/cwd | cut -d ">" -f 2 | sed 's/^ //'`

export ORACLE_HOME=`echo "${var%/*}"`

export PATH=$ORACLE_HOME/bin:$PATH

export ORACLE_BASE=`ls -l /proc/$proid/cwd | cut -d ">" -f 2 | sed 's/^ //' | awk -F "/product" '{print $1}'`

$ORACLE_HOME/bin/sqlplus -s "/ as sysdba" << EOF >>$BKP_LOG/db_info.log

set lines 300 colsep '|'

select name from v\$database;

show parameter db_unique_name;

exit;

EOF

else

echo "Database $1 Is Not Running"

exit 1;

fi

 

rman target sys/sys123@US_PRIM log=$RMAN_LOG <<EOG

run

{

allocate channel c1 device type disk connect 'sys/sys123@US_PRIM as sysdba';

allocate channel c2 device type disk connect 'sys/sys123@US_PRIM as sysdba';

backup as compressed backupset format '/u01/DB_BKP/$1_%t_%s_%U' incremental level 1 database;

}

exit;

EOG

 

######## Script Ends Here

 

                              SAMPLE OUTPUT

 

RMAN> 2> 3> 4> 5> 6>

using target database control file instead of recovery catalog

allocated channel: c1

channel c1: SID=36 device type=DISK

allocated channel: c2

channel c2: SID=271 device type=DISK

Starting backup at 28-JAN-24

channel c1: starting compressed incremental level 1 datafile backup set

channel c1: specifying datafile(s) in backup set

input datafile file number=00001 name=/u01/app/oracle/oradata/US_PRIM/datafile/o1_mf_system_lrj2vsk5_.dbf

-

Finished backup at 28-JAN-24

released channel: c1

released channel: c2

RMAN>




Post a Comment

Previous Post Next Post