RMAN Archive Backup Script

Sometimes, DBA needs to take RMAN Archive backup and during that time DBA needs to execute the Archive backup command but sometimes even archive backup takes time due to the high rate of archive generation and also, we don’t need to run the backup jobs in foreground so for that we can use RMAN archive backup automation script which execute the backup jobs in background.

 

Purpose of the Script -> Automate RMAN Archive Backup

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

Run this automation in background -> nohup ./ARCH_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.

 

 

BODY OF SCRIPT

 

#!/bin/bash

#set -xv

#set -n

mkdir -p /tmp/DB_ARCH_BKP

BKP_LOG=/tmp/DB_ARCH_BKP

RMAN_LOG=$BKP_LOG/ARCH_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' archivelog all;

}

exit;

EOG

 

########## Script Ends Here

 

            SAMPLE OUTPUT

 

[oracle@oratest u01]$ tail -10f /tmp/DB_ARCH_BKP/ARCH_BKP.log

input archived log thread=1 sequence=16 RECID=55 STAMP=1159298348

input archived log thread=1 sequence=17 RECID=54 STAMP=1159298348

input archived log thread=1 sequence=18 RECID=57 STAMP=1159298348

input archived log thread=1 sequence=19 RECID=58 STAMP=1159298348

input archived log thread=1 sequence=20 RECID=59 STAMP=1159298348

channel c2: starting piece 1 at 28-JAN-24

channel c1: finished piece 1 at 28-JAN-24

channel c2: backup set complete, elapsed time: 00:00:01

Finished backup at 28-JAN-24

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_lvdpwh6t_.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