SHELL SCRIPT TO MONITOR RMAN RESTORE ORACLE

Have you ever had a shell script to monitor the restore progress of database using rman?

This is just a small script which helps you to know the current status,pending files to restore ,errors while restore and total restore percent.

Below is a short output for a rman restore

Starting restore at 18-MAY-21
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=24 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00003 to /apps01/oradata/orcl19xsysaux01.dbf
channel ORA_DISK_1: restoring datafile 00004 to /apps01/oradata/orcl19xundotbs01.dbf
channel ORA_DISK_1: restoring datafile 00006 to /apps01/oradata/orcl19xusers01.dbf
channel ORA_DISK_1: restoring datafile 00007 to /apps01/oradata/orcl19x/EXAMPLE12625.dbf
channel ORA_DISK_1: restoring datafile 00008 to /apps01/oradata/orcl19x/SYSAUX18237.dbf
channel ORA_DISK_1: reading from backup piece /apps01/product/12.1.0/dbhome_1/dbs/09vuu83f_1_1
channel ORA_DISK_1: piece handle=/apps01/product/12.1.0/dbhome_1/dbs/09vuu83f_1_1 tag=TAG20210515T182653
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:15
channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00001 to /apps01/oradata/orcl19xsystem01.dbf
channel ORA_DISK_1: restoring datafile 00002 to /apps01/oradata/orcl19x/EXAMPLE6345.dbf
channel ORA_DISK_1: restoring datafile 00005 to /apps01/oradata/orcl19xexample01.dbf
channel ORA_DISK_1: restoring datafile 00009 to /apps01/oradata/orcl19x/SYSTEM9302.dbf
channel ORA_DISK_1: restoring datafile 00010 to /apps01/oradata/orcl19x/EXAMPLE7187.dbf
channel ORA_DISK_1: reading from backup piece /apps01/product/12.1.0/dbhome_1/dbs/08vuu83e_1_1
channel ORA_DISK_1: piece handle=/apps01/product/12.1.0/dbhome_1/dbs/08vuu83e_1_1 tag=TAG20210515T182653
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:01:16
Finished restore at 18-MAY-21

Use this shell script to monitor restore and this cannot be used in all situations rather for basic restore

[oracle@orcl19x ~]$ cat restore_progress.sh
#!/bin/bash

-------------------------------------------
restore script to monitor datafile restore - Author ~ Kishan
-------------------------------------------
#Set env
_env(){
export ORACLE_SID=orcl19x
export ORACLE_HOME=/apps01/product/12.1.0/dbhome_1
restore_log=/home/oracle/rman.log
export restore_log
if [[ ! -f /home/oracle/rman.log ]]
then
touch /home/oracle/rman.log
fi
}

#check restore status
_restore_status(){
echo "================================================================"
echo "================================================================"
tot_counter=10
curr_counter=`grep 'datafile' $restore_log|grep -v 'starting datafile'|grep -v 'specifying datafile'|wc -l`
pend_counter=$((tot_counter - curr_counter))
if [ $pend_counter -le 0 ]
then
echo "All datafiles are restored"
else
echo "Out of $tot_counter datafiles ,Still $pend_counter datafiles pending to restore!";echo "================================================================";echo "Current channel and file: `grep 'datafile' $restore_log|grep -v 'starting datafile'|grep -v 'specifying datafile'|tail -1`"
fi
}
#Check restore percent
_restore_pct(){
echo "Datafiles-restore-percent :"; echo "$(($curr_counter / $tot_counter * 100))"
}


echo " "
echo " "
echo " "
echo " "


#Check for errors during restore
_error_check(){
echo "===================================================="
egrep 'ORA-|RMAN-|ERROR-' $restore_log
if [ $? -eq 0 ];then
echo "Error found.Please have a check on logs"
else
echo "No errors found"
fi
echo "====================================================";
}
echo " "
echo " "
echo " "
echo " "


_env
_restore_status
_restore_pct
_error_check

Below is a sample execution

[oracle@orcl19x ~]$ ./restore_progress.sh
================================================================
================================================================
Out of 10 datafiles ,Still 3 datafiles pending to restore!
================================================================
Current channel and file: channel ORA_DISK_1: restoring datafile 00008 to /apps01/oradata/orcl19x/SYSAUX18237.dbf
====================================================
No errors found
====================================================

Once restore complete your output looks like this

[oracle@orcl19x ~]$ ./restore_progress.sh
================================================================
================================================================
All datafiles are restored

================================================================
All datafiles are restored
====================================================
Datafiles-restore-percent :
100
====================================================
No errors found
====================================================

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s