We're here to help!

Advanced - Pre/Post Processing

Follow

1. Introduction  

It is possible to schedule your own pre- or post processing script as part of the Dbvisit Standby execution. A good example of doing this is if you want to execute your own custom code to perform certain tasks before or after Dbvisit Standby sends or apply logs; or it can be used to execute a script after you have opened the standby database read-only to start reporting extracts or any other custom code you would want to execute.
This is the new recommended way where one script is used for both pre- and post-processing. This script when executed by Dbvisit Standby, will be called with two parameters indicating if it should execute pre or post tasks and what the Dbvisit Standby process is that is being called.


In Dbvisit Standby version 8 a Dbvisit Standby Configuration (DDC) parameter is available called: DBV_PRE_POST_PROC


This parameter is set in the Primary database DDC file and should point to the script you want to execute before or after Dbvisit Standby processing.


Example Linux:

DBV_PRE_POST_PROC=/usr/local/bin/dbv_pre_post_processing.sh


Example Windows:

DBV_PRE_POST_PROC=c:\bin\dbv_pre_post_processing.cmd



Dbvisit Standby does come with a sample script to get you started.
This script is located in: DBVISIT_BASE/standby/doc

  • Linux sample script: example_pre_post_processing.sh
  • Windows sample script: example_pre_post_processing.cmd

The samples can be found at the end of this section.


These sample scripts will take two parameters which is passed by Dbvisit Standby to it:

  • Parameter 1 can be one of two possible values: [pre|post]
  • Parameter 2 can be one number from 1 to 6: [1|2|3|4|5|6]


Usage examples:

Usage: ./pre-post-dbvisit.sh [pre|post] [1|2|3|4|5|6]



Example call on Linux to perform pre- or post-process tasks when sending logs (see number explanation below)

# ./pre-post-dbvisit.sh pre 1
# ./pre-post-dbvisit.sh post 5




Example call on Windows to perform pre- or post-process tasks when sending logs (see number explanation below)

# ./pre-post-dbvisit.cmd pre 1
# ./pre-post-dbvisit.cmd post 1


Pre- and Post-processing script input parameters:
When the script is executed the first parameter that will be passed to it will be "pre" or "post" indicating if the script is executed before (pre) or after (post) Dbvisit Processing:


pre = Pre Dbvisit Processing step
post = Post Dbvisit Processing step


The second parameter that is passed is in number format. The possible values are 1 through to the number 6.

The number indicates which step Dbvisit Standby is performing:


1 = Dbvisit is executed on primary and will be sending logs to standby
2 = Dbvisit is executed on standby and will be applying logs
3 = Dbvisit Graceful Switchover is executed on primary
4 = Dbvisit Graceful Switchover is executed on standby
5 = Dbvisit Activation is executed on standby
6 = Standby Database is opened read-only



2.  Linux - Sample Script


This section will provide you with an example script that can be located in DBVISIT_BASE/standby/doc folder.

Important - these are not complete scripts as they do not execute any specific tasks, you will need to modify them to your requirements.

#!/bin/bash
#
# Description:
# ===========
# This script is provided by Dbvisit Software Limited as an example
# pre/post processing script. This script can be used to perform 
# custom tasks (pre) before Dbvisit Standby execute, or (post) following
# a successful execution.
#
# NOTE: This script is a basic template and you will need to add custom code
# to this script to perform the required tasks you want to perform as 
# part of pre or post dbvisit processing. 
#
# This script should be added to the Dbvisit Database Configuration (DDC) file
# Example: PRE_POST_PROCESSING=/usr/local/bin/pre-post-dbvisit.sh
#
# Dbvisit STandby will pass two parameters to this script
# Parameter 1 can be one of two possible values: [pre|post]
# Parameter 2 can be one number from 1 to 6: [1|2|3|4|5|6]
# 
# Usage: ./pre-post-dbvisit.sh [pre|post] [1|2|3|4|5|6]
#
# Example: ./pre-post-dbvisit.sh pre 1
#
# Parameter explanation:
# =====================
# pre = Pre Dbvisit Processing step
# post = Post Dbvisit Processing step
# 1 = Dbvisit is executed on primary and will be sending logs to standby
# 2 = Dbvisit is executed on standby and will be applying logs
# 3 = Dbvisit Graceful Switchover is executed on primary 
# 4 = Dbvisit Graceful Switchover is executed on standby
# 5 = Dbvisit Activation is executed on standby
# 6 = Standby Database is opened read-only 
#
# 
# Note: This script is an example only and should be tested first before 
# it is used in a production environment.
#
# To enable debugging, uncomment following line:
# set -x
#
###########################################
# Function to echo usage
###########################################
usage ()
{
program=`basename $0`
cat <> /dev/null
export ORAENV_ASK=YES
}
###########################################
# Function to Add text to logfile
###########################################
addLog()
{
# comment 1st line below to remove echo back to user and to only write to log
echo "`date +%d-%h-%Y:%H:%M:%S` : ${1}" 
echo "`date +%d-%h-%Y:%H:%M:%S` : ${1}" >> ${logfile}
}
### Add your custom functions here
###
##########################
##########################
####
#### MAIN PROGRAM SECTION
####
##########################
##########################
## First call function to set the environment or specific global variables
setup_parameters
## Test input values, must be 2 values, if not exit
if test $# -ne 2
then
echo "Cannot execute, 2 values must be specified as input..."
usage
exit 99
fi
if [ ${1} = "pre" ] || [ ${1} = "post" ] 
then
if ! [[ $2 =~ '^[1-6]+$' ]]
then 
echo "2nd Parameter must be a number between 1 and 6"
usage
exit 97
fi
else
echo "1st Parameter must be \"pre\" or \"post\"";
usage
exit 98
fi
### Now that values are valid, execute required code block
case ${1} in
pre) 
addLog "Start Pre Processing"
case ${2} in
1) 
addLog "Primary Database Send"
## add custom code here or call custom function
;;
2)
addLog "Standby Database Apply"
## add custom code here or call custom function
;;
3)
addLog "Primary Server Graceful Switchover"
## add custom code here or call custom function
;;
4)
addLog "Standby Server Graceful Switchover"
## add custom code here or call custom function
;;
5)
addLog "Standby Database Activate"
## add custom code here or call custom function
;;
6)
addLog "Standby Database Read-Only"
## add custom code here or call custom function
;;
esac 
;;
post)
addLog "Start post Processing"
case ${2} in
1)
addLog "Primary Database Send"
## add custom code here or call custom function
;;
2)
addLog "Standby Database Apply"
## add custom code here or call custom function
;;
3)
addLog "Primary Server Graceful Switchover"
## add custom code here or call custom function
;;
4)
addLog "Standby Server Graceful Switchover"
## add custom code here or call custom function
;;
5)
addLog "Standby Database Activate"
## add custom code here or call custom function
;;
6)
addLog "Standby Database Read-Only"
## add custom code here or call custom function
;;
esac
;;
esac


3.  Windows - Sample Script


This section will provide you with an example script that can be located in DBVISIT_BASE\standby\doc folder.

Important - these are not complete scripts as they do not execute any specific tasks, you will need to modify them to your requirements.

#!/bin/bash
#
# Description:
# ===========
# This script is provided by Dbvisit Software Limited as an example
# pre/post processing script. This script can be used to perform 
# custom tasks (pre) before Dbvisit Standby execute, or (post) following
# a successful execution.
#
# NOTE: This script is a basic template and you will need to add custom code
# to this script to perform the required tasks you want to perform as 
# part of pre or post dbvisit processing. 
#
# This script should be added to the Dbvisit Database Configuration (DDC) file
# Example: PRE_POST_PROCESSING=/usr/local/bin/pre-post-dbvisit.sh
#
# Dbvisit STandby will pass two parameters to this script
# Parameter 1 can be one of two possible values: [pre|post]
# Parameter 2 can be one number from 1 to 6: [1|2|3|4|5|6]
# 
# Usage: ./pre-post-dbvisit.sh [pre|post] [1|2|3|4|5|6]
#
# Example: ./pre-post-dbvisit.sh pre 1
#
# Parameter explanation:
# =====================
# pre = Pre Dbvisit Processing step
# post = Post Dbvisit Processing step
# 1 = Dbvisit is executed on primary and will be sending logs to standby
# 2 = Dbvisit is executed on standby and will be applying logs
# 3 = Dbvisit Graceful Switchover is executed on primary 
# 4 = Dbvisit Graceful Switchover is executed on standby
# 5 = Dbvisit Activiation is excecuted on standby
# 6 = Standby Database is opened read-only 
#
# 
# Note: This script is an example only and should be tested first before 
# it is used in a production environment.
#
# To enable debugging, uncomment following line:
# set -x
#
###########################################
# Function to echo usage
###########################################
usage ()
{
program=`basename $0`
cat <> /dev/null
export ORAENV_ASK=YES
}
###########################################
# Function to Add text to logfile
###########################################
addLog()
{
# comment 1st line below to remove echo back to user and to only write to log
echo "`date +%d-%h-%Y:%H:%M:%S` : ${1}" 
echo "`date +%d-%h-%Y:%H:%M:%S` : ${1}" >> ${logfile}
}
### Add your custom functions here
###
##########################
##########################
####
#### MAIN PROGRAM SECTION
####
##########################
##########################
## First call function to set the environment or specific global variables
setup_parameters
## Test input values, must be 2 values, if not exit
if test $# -ne 2
then
echo "Cannot execute, 2 values must be specified as input..."
usage
exit 99
fi
if [ ${1} = "pre" ] || [ ${1} = "post" ] 
then
if ! [[ $2 =~ '^[1-6]+$' ]]
then 
echo "2nd Parameter must be a number between 1 and 6"
usage
exit 97
fi
else
echo "1st Parameter must be \"pre\" or \"post\"";
usage
exit 98
fi
### Now that values are valid, execute required code block
case ${1} in
pre) 
addLog "Start Pre Processing"
case ${2} in
1) 
addLog "Primary Database Send"
## add custom code here or call custom function
;;
2)
addLog "Standby Database Apply"
## add custom code here or call custom function
;;
3)
addLog "Primary Server Graceful Switchover"
## add custom code here or call custom function
;;
4)
addLog "Standby Server Graceful Switchover"
## add custom code here or call custom function
;;
5)
addLog "Standby Database Activate"
## add custom code here or call custom function
;;
6)
addLog "Standby Database Read-Only"
## add custom code here or call custom function
;;
esac 
;;
post)
addLog "Start post Processing"
case ${2} in
1)
addLog "Primary Database Send"
## add custom code here or call custom function
;;
2)
addLog "Standby Database Apply"
## add custom code here or call custom function
;;
3)
addLog "Primary Server Graceful Switchover"
## add custom code here or call custom function
;;
4)
addLog "Standby Server Graceful Switchover"
## add custom code here or call custom function
;;
5)
addLog "Standby Database Activate"
## add custom code here or call custom function
;;
6)
addLog "Standby Database Read-Only"
## add custom code here or call custom function
;;
esac
;;
esac



Have more questions? Submit a request

Comments