SHELL SCRIPT TO MONITOR RESTORE PROGRESS FROM RMAN IN ORACLE

Use this shell script to get the restore progress of database from rman and get an approximate value of the progress

Here if you know the size of the database then in place of variable ‘ dbsz ‘ use the database size . This is because during restore, the output of ‘report schema’ command will be reset to 0 MB of size. This step can be followed if the restore percentage is unapproximate value exceeding the total percentage (100)

Tips: If the database size is in GB or TB, then you have to convert the values accordingly in the script. This script has size format in “MB”. So remember it.

#!/bin/bash -x
#set environment variables
_env(){
RESTORE_PROGRESS=/tmp/restore_progress.log
export PATH=/apps01/product/12.1.0/dbhome_1/bin:/usr/sbin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/oracle/.local/bin:/home/oracle/bin
export ORACLE_HOME=/apps01/product/12.1.0/dbhome_1
export ORACLE_SID=orcl19x
touch dbsize dbsize1
export SIZELOG=dbsize
export DBSIZELOG=dbsize1
}
#run while loop with rman report schema and filter only datafile size and sum the size of all datafiles
_dbs(){
while true;do
      rman cmdfile=rman_schema.cmd msglog=$SIZELOG >/dev/null 2>&1;grep -v 'TEMP' 
      dbsize|awk '{print $2}'|grep -Eo '[0-9]{1,9}'|awk '{sum+=$1;}END{print sum;}'|tee -a 
      $DBSIZELOG >/dev/null 2>&1
  break
done
dbsz="$(cat $DBSIZELOG|grep -Eo '[0-9]{1,9}')" #this variable can be replaced by database size 
cat /dev/null > $DBSIZELOG
cat /dev/null > $SIZELOG
$ORACLE_HOME/bin/sqlplus -S "/ as sysdba" << EOF
--sql to check restore status 
set lines 200
set pages 1000
col INPUT_BYTES/1024/1024 format 9999999
col OUTPUT_BYTES/1024/1024 format 9999999
col OBJECT_TYPE format a10
col 100*(MBYTES_PROCESSED/${dbsz}) format 99999999
select trunc(INPUT_BYTES/1024/1024) as inp_byte,trunc(OUTPUT_BYTES/1024/1024) as out_byte,OBJECT_TYPE,100*(MBYTES_PROCESSED/${dbsz}) as pctcomplete from v\$rman_status where status like '%RUNNING%';
EOF
exit;
}

_env
_dbs

1 Comment

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