<

Go Premium for a chance to win a PS4. Enter to Win

x

Script to backup Dataguard broker configuration

Published on
3,370 Points
370 Views
Last Modified:
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux.
Script may need to be modified depending on OS-installation.

Please deploy and verify the script in a test environment.
#!/bin/ksh
# -----------------------------------------------------------------------------
# Author : Abhimanyu Suri
# Script Name : backup_dg_config.ksh
# Modified : 03/27/2017
# Purpose : Backup config file for Dataguard Broker
# Run user :
# Version : 1.0
#
# USAGE : EXEC_DIR/backup_dg_config.ksh ORACLE_SID BKP_DIR
# /u02/dba/admin_scripts/DG_CONFIG_BKP/backup_dg_config.ksh usdb /u02
#
# DATE MODIFICATION BY VERSION
# 03/27/2017 Created Abhimanyu Suri 1.0
# -----------------------------------------------------------------------------

logdir=`pwd`
scriptname=`basename $0 .ksh`

export ORACLE_SID=$1
export bkpdir=$2

function usage
{
 
 if [ -z "${ORACLE_SID}" ] || [ -z "${bkpdir}" ];
 then
 echo -e "Please provide a valid ORACLE_SID and Backup DIRECTORY\nUSAGE : EXEC_DIR/backup_dg_config.ksh ORACLE_SID BKP_DIR\nFor example: /u02/dba/admin_scripts/DG_CONFIG_BKP/backup_dg_config.ksh usdb1s_hs /u02"
 exit
 fi
 
 if [[ `cat /etc/oratab|grep -i ${ORACLE_SID}|wc -l` != 1 ]];
 then
 echo -e "Please provide a valid ORACLE_SID\nEither no entry or multiple entries exists in ORATAB for *${ORACLE_SID}*"
 echo -e "USAGE : EXEC_DIR/backup_dg_config.ksh ORACLE_SID BKP_DIR\nFor example: /u02/dba/admin_scripts/DG_CONFIG_BKP/backup_dg_config.ksh usdb1s_hs /u02"
 exit
 else
 export ORACLE_HOME=`cat /etc/oratab|grep -i ${ORACLE_SID}|cut -d ":" -f2`
 if [[ -z "${ORACLE_HOME}" ]];
 then
 echo -e "Error setting ORACLE HOME"
 exit
 fi
 fi
 
 if [[ ! -d "${bkpdir}" ]];
 then
 echo -e "Directory:"$2" is not a valid directory\nUSAGE : EXEC_DIR/backup_dg_config.ksh ORACLE_SID BKP_DIR\nFor example: /u02/dba/admin_scripts/DG_CONFIG_BKP/backup_dg_config.ksh usdb1s_hs /u02"
 exit
 fi
}>${logdir}/${scriptname}.err

function get_config_verbose
{
 echo -e "show configuration verbose"|${ORACLE_HOME}/bin/dgmgrl /
 if [ ! $? == 0 ]
 then
 echo "ERROR GETTING CONFIGURATION"
 exit
 fi
}>config_verbose_bkp.txt 2>${logdir}/${scriptname}.err

function get_src_database_verbose
{
 echo -e "show database verbose ${PRIMARY_DATABASE}"|${ORACLE_HOME}/bin/dgmgrl /
 if [ ! $? == 0 ]
 then
 echo "ERROR GETTING PRIMARY DATABASE DETAILS"
 exit
 fi
}>primary_${PRIMARY_DATABASE}_verbose.txt 2>${logdir}/${scriptname}.err

function get_stdby_database_verbose
{
 echo -e "show database verbose ${STANDBY_DATABASE}"|${ORACLE_HOME}/bin/dgmgrl /
 if [ ! $? == 0 ]
 then
 echo "ERROR GETTING STANDBY DATABASE DETAILS"
 exit
 fi
}>stdby_${STANDBY_DATABASE}_verbose.txt 2>${logdir}/${scriptname}.err

function build_config
{
 echo -e "create configuration "${CONFIG_NAME}" as primary database is '"${PRIMARY_DATABASE}"' connect identifier is "${PRIMARY_CONNECT_IDENTIFIER}";"
 cat primary_${PRIMARY_DATABASE}_verbose.txt|grep "="|grep -vi "'(monitor)'"|while read column1 remainder
 do
 echo -e "edit database "${PRIMARY_DATABASE}" set property '"${column1}"' "${remainder}";"
 done
 echo -e "add database '"${STANDBY_DATABASE}"' as connect identifier is "${STANDBY_CONNECT_IDENTIFIER}" maintained as physical;"
 cat stdby_${STANDBY_DATABASE}_verbose.txt|grep "="|grep -vi "'(monitor)'"|while read column1 remainder
 do
 echo -e "edit database "${STANDBY_DATABASE}" set property '"${column1}"' "${remainder}";"
 done
}>${bkpdir}/dgmgrl_${CONFIG_NAME}.cfg 2>${scriptname}.err

##### main

usage
get_config_verbose

if [[ `cat config_verbose_bkp.txt|grep -i "Name:"|wc -l` == 1 ]];
then
CONFIG_NAME=`cat config_verbose_bkp.txt|grep -i "Name:"|cut -d ":" -f2|tr -d ' '`
elif [[ `cat config_verbose_bkp.txt|grep -i "Configuration -"|wc -l` == 1 ]];
then
CONFIG_NAME=`cat config_verbose_bkp.txt|grep -i "Configuration -"|cut -d "-" -f2|tr -d ' '`
fi

PRIMARY_DATABASE=`cat config_verbose_bkp.txt|grep -i "Primary database"|cut -d "-" -f1|tr -d ' '`
STANDBY_DATABASE=`cat config_verbose_bkp.txt|grep -i "Physical standby database"|cut -d "-" -f1|tr -d ' '`

get_src_database_verbose
get_stdby_database_verbose

PRIMARY_CONNECT_IDENTIFIER=`cat primary_${PRIMARY_DATABASE}_verbose.txt|grep -i ConnectIdentifier|grep -v ObserverConnectIdentifier|awk -F'=' '{print $2}'|cut -d "'" -f2`
STANDBY_CONNECT_IDENTIFIER=`cat stdby_${STANDBY_DATABASE}_verbose.txt|grep -i ConnectIdentifier|grep -v ObserverConnectIdentifier|awk -F'=' '{print $2}'|cut -d "'" -f2`

build_config

rm -rf config_verbose_bkp.txt primary_${PRIMARY_DATABASE}_verbose.txt stdby_${STANDBY_DATABASE}_verbose.txt
0
Comment
0 Comments

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Join & Write a Comment

This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to recover a database from a user managed backup

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month