<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Script to backup Dataguard broker configuration

Published on
3,274 Points
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
0 Comments

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Join & Write a Comment

This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month