RMAN L0 Database Backup Script

Sometime DBA needs to take RMAN L0 backup due to many reasons like rman refresh,rman restore etc. and sometimes application team also ask DBA to take L0 backup and during that time DBA needs to execute the L0 backup command but the biggest challenge comes for the DBA when the database size is huge which takes many hours to complete and they can’t run that L0 backup in foreground so to overcome this challenge we can use rman automation backup script which takes database L0 backup in background.

 

Purpose of the Script -> Automate RMAN L0 Backup

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

Run this automation in background -> nohup ./L0_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 brown & bold.

 

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

 

NOTE E: allocate channel as per the available CPU in the database server.

 

 

                                    BODY OF SCRIPT

#!/bin/bash

#set -xv

#set -n

mkdir -p /tmp/DB_L0_BKP

BKP_LOG=/tmp/DB_L0_BKP

RMAN_LOG=$BKP_LOG/L0_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 0 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 0 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

input datafile file number=00007 name=/u01/app/oracle/oradata/US_PRIM/datafile/o1_mf_users_lrj30xtc_.dbf

-

Starting Control File and SPFILE Autobackup at 28-JAN-24

piece handle=/u01/app/oracle/fast_recovery_area/US_PRIM/autobackup/2024_01_28/o1_mf_s_1159298726_lvdg4gb3_.bkp comment=NONE

Finished Control File and SPFILE Autobackup at 28-JAN-24

released channel: c1

released channel: c2

 RMAN>





Post a Comment

Previous Post Next Post