Pre/Post Processing

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 are 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 <<EOF
Usage:
${program} [pre|post] [1|2|3|4|5|6]
[pre|post} - Specify if Pre or Post processing is being performed
[1|2|3|4|5|6] - Indicate Dbvisit operation being performed
-h - display the usage

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 
Example, to perform a task on the standby server following activation:
${program} post 5
EOF
exit 1
}
###########################################
# Function to setup parameter variables
# Description:
# Specify any global settings in this section
###########################################
setup_parameters ()
{
## Below are some example values
export PATH=$PATH:/bin:/usr/bin:/usr/local/bin
export NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'
SERVER=`uname -n`
dbvisit_base=/usr/dbvisit
logfile=${dbvisit_base}/standby/log/pre-post-dbvisit.log
}
###########################################
# Function to change database environments
# Description:
# Use oraenv to set the environment if needed
# This is optional to set the environment
###########################################
set_env ()
{
export ORAENV_ASK=NO
export ORACLE_SID=$1
. oraenv >> /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.

@echo off

REM  Description:
REM  ===========
REM  This script is provided by Dbvisit Software Limited as an example
REM  pre/post processing script for windows.  This script can be used to perform 
REM  custom tasks (pre) before Dbvisit Standby execute, or (post) following
REM  a successful execution.  
REM  
REM  This script is just a template and you will need to add custom code
REM  to this script to perform the required tasks you want to perform as 
REM  part of pre or post dbvisit processing. 
REM  Look for lines marked as follow to place custom code:
REM        REM --- add custom code here 
REM 
REM  This script should be added to the Dbvisit Database Configuration (DDC) file
REM  Example: PRE_POST_PROCESSING=c:\Program Files\dbvisit\standby\pre-post-dbvisit.cm
REM 
REM  Dbvisit STandby will pass two parameters to this script
REM   Parameter 1 can be one of two possible values:  [pre|post]
REM   Parameter 2 can be one number from 1 to 6:  [1|2|3|4|5|6]
REM  
REM  Usage:  pre-post-dbvisit.bat [pre|post] [1|2|3|4|5|6]
REM 
REM  Example: pre-post-dbvisit.bat pre 1
REM 
REM  Parameter explanation:
REM  =====================
REM   pre  = Pre Dbvisit Processing step
REM   post = Post Dbvisit Processing step
REM   1	= Dbvisit is executed on primary and will be sending logs to standby
REM   2	= Dbvisit is executed on standby and will be applying logs
REM   3	= Dbvisit Graceful Switchover is executed on primary 
REM   4	= Dbvisit Graceful Switchover is executed on standby
REM   5	= Dbvisit Activation is executed on standby
REM   6 = Standby Database is opened read-only 
REM 
REM  Note: This script is an example only and should be tested first before 
REM        it is used in a production environment.
REM

REM -- BEGIN Main Section

setlocal
pushd

REM First test both input values are not null
if "%~1"=="" (
   echo First input value cannot be empty ...
   echo:
   call :HELP
 ) & (goto :EOF)
if "%~2"=="" (
   echo Second input value cannot be empty ...
   echo:
   call :HELP
 ) & (goto :EOF)

REM Test if Usage/Help should be displayed
if /i {%1}=={/?} (call :HELP) & (goto :EOF)

REM Check if first parameter is either pre or post if not show help and exit
for %%x in ("pre" "post") do if "%1" == %%x (goto :check1_good) else (set VAL1WRONG=1)
if %VAL1WRONG%==1 (
  echo First parameter should be either "pre" for "post"
  echo:
  goto :HELP) & (goto :EOF)
  
:check1_good
REM Now check if the second parameter is between 1 and 6 if not show help and exit
for %%y in ("1" "2" "3" "4" "5" "6") do if "%2" == %%y (goto :check2_good) else (set VAL2WRONG=1)
if %VAL2WRONG%==1 (
  echo Second parameter should be either a number between 1 and 6
  echo:
  goto :HELP) & (goto :EOF)

REM Checks are good, correct input parameters provided
:check2_good

set v_type=%1
set v_code=%2

goto :setEnvironment
:EndOfSetEnvironment

REM ===================================
REM Test Input values and execute windows code block depending on input
REM ===================================

if %v_type%==pre (
  echo Going to execute pre processing
  echo:
  if %v_code%==1 (goto :pre_1) & (got :EOF)   
  if %v_code%==2 (goto :pre_2) & (got :EOF) 
  if %v_code%==3 (goto :pre_3) & (got :EOF) 
  if %v_code%==4 (goto :pre_4) & (got :EOF) 
  if %v_code%==5 (goto :pre_5) & (got :EOF) 
  if %v_code%==6 (goto :pre_6) & (got :EOF)       
 ) else (
  echo Going to execute post processing 
  echo:
  if %v_code%==1 (goto :post_1) & (got :EOF)   
  if %v_code%==2 (goto :post_2) & (got :EOF) 
  if %v_code%==3 (goto :post_3) & (got :EOF) 
  if %v_code%==4 (goto :post_4) & (got :EOF) 
  if %v_code%==5 (goto :post_5) & (got :EOF) 
  if %v_code%==6 (goto :post_6) & (got :EOF)  
)


REM === End of Checks

popd
endlocal
goto :EXIT

REM -- END Main Section

REM ##########################################
REM   Function to set Environment values
REM ##########################################
:setEnvironment

 set DBVISIT_BASE="c:\Program Files\dbvisit"
 set ORACLE_HOME=c:\app\oracle\product\11.2.0
 set TNS_ADMIN=%ORACLE_HOME%\network\admin
 set ORACLE_SID=testdb
 set PATH=%ORACLE_HOME%\bin;%PATH%
 
 for /F "tokens=1,2,3,4 delims=/- "  %%a  in  ('date /t') do set CDATE=%%d%%c%%b
 for /F "tokens=1,2,3,4 delims=/: "  %%a  in  ('time /t') do set CTIME=%%a%%b%%c
 set LOGTIME=%CDATE%-%CTIME%
 echo %LOGTIME%

GOTO :EndOfSetEnvironment
REM ##########################################

REM ##############################################
REM ## Below are all the PRE Processing Functions
REM ##############################################

REM ####### pre_1 Function ###################
:pre_1
  echo Running Pre Processing steps on primary during normal dbvisit run
  REM --- add custom code here  
goto :EXIT

REM ####### pre_2 Function ###################
:pre_2
  echo Running Pre Processing steps on standby during normal dbvisit run
  REM --- add custom code here  
goto :EXIT

REM ####### pre_3 Function ###################
:pre_3
  echo Running Pre Processing steps on primary during Graceful Switchover
  REM --- add custom code here  
goto :EXIT

REM ####### pre_4 Function ###################
:pre_4
  echo Running Pre Processing steps on stadnby during Graceful Switchover
  REM --- add custom code here  
goto :EXIT

REM ####### pre_5 Function ###################
:pre_5
  echo Running Pre Processing steps on standby during Activation
  REM --- add custom code here  
goto :EXIT

REM ####### pre_6 Function ###################
:pre_6
  echo Running Pre Processing steps on standby during open Read-Only
  REM --- add custom code here  
goto :EXIT


REM ##############################################
REM ## Below are all the POST Processing Functions
REM ##############################################

REM ####### post_1 Function ###################
:post_1
  echo Running Post Processing steps on primary during normal dbvisit run
  REM --- add custom code here  
goto :EXIT

REM ####### post_2 Function ###################
:post_2
  echo Running Post Processing steps on standby during normal dbvisit run
  REM --- add custom code here  
goto :EXIT

REM ####### post_3 Function ###################
:post_3
  echo Running Post Processing steps on primary during Graceful Switchover
  REM --- add custom code here
goto :EXIT

REM ####### post_4 Function ###################
:post_4
  echo Running Post Processing steps on stadnby during Graceful Switchover
  REM --- add custom code here  
goto :EXIT

REM ####### post_5 Function ###################
:post_5
  echo Running Post Processing steps on standby during Activation
  REM --- add custom code here
goto :EXIT

REM ####### post_6 Function ###################
:post_6
  echo Running Post Processing steps on standby during open Read-Only
  REM --- add custom code here
goto :EXIT


:HELP
  echo USAGE:
  echo  dbv_pre_post_processing.bat [pre^|post] [1^|2^|3^|4^|5^|6]
  echo:
  echo      [pre^|post]    - Specify if Pre or Post processing is being performed
  echo      [1^|2^|3^|4^|5^|6] - Indicate Dbvisit operation being performed
  echo:      
  echo      pre  ^= Pre Dbvisit Processing step
  echo      post ^= Post Dbvisit Processing step
  echo      1 ^= Dbvisit is executed on primary and will be sending logs to standby
  echo      2 ^= Dbvisit is executed on standby and will be applying logs
  echo      3 ^= Dbvisit Graceful Switchover is executed on primary 
  echo      4 ^= Dbvisit Graceful Switchover is executed on standby
  echo      5 ^= Dbvisit Activation is executed on standby
  echo      6 ^= Standby Database is opened read-only 
  echo: 
  echo  Example, to perform a task on the standby server following activation:
  echo: 
  echo     dbv_pre_post_processing.bat  post 5
goto :EOF

:EXIT
popd
endlocal
REM echo EXIT %ERRORLEVEL%
goto :EOF

ASM Aliases


One of the changes included since the 8.0.16 release is that during CSD (at the end of it) a text file is created in the standby dbvisit LOGDIR.

This file contains a list of datafile details from the primary, which would include example the ASM alias names if they were used.

The file naming is DBVISIT_BASE/standby/log/dbv_<DDC>_csd_db_file_info.txt


The file text has the following format:

DATAFIILE_TYPE (DATA/TEMP), FILE_ID, FILE_NAME, TABLESPACE_NAME,CON_ID


Example:

DATA,1,+DATA2/DBVFOUR/DATAFILE/system.263.948382091,SYSTEM,0
DATA,2,+DATA2/DBVFOUR/DATAFILE/sysaux.264.948382097,SYSAUX,0
DATA,3,+DATA2/DBVFOUR/DATAFILE/undotbs1.265.948382101,UNDOTBS1,0
DATA,4,+DATA2/DBVFOUR/DATAFILE/undotbs2.267.948382111,UNDOTBS2,0
DATA,5,+DATA2/DBVFOUR/DATAFILE/users.268.948382115,USERS,0
DATA,6,+DATA2/DBVFOUR/DATAFILE/test02.dbf,TEST1,0
DATA,8,+DATA2/dbvfour/test401.dbf,TEST4,0
TEMP,1,+DATA2/DBVFOUR/TEMPFILE/temp.2097.950291191,TEMP,0


This file can be used as part of a post-processing script (sample is located in the DBVISIT_BASE/standby/doc) folder - at the end of CSD to run a small script to take this as input and create ASM aliases if you require that on the standby server.   

We do not recommend the use of ASM aliases but to rather use true OMF naming.  But if you do want to continue with ASM aliases, we now provide the above to help you create your own post-processing script to create them as required to your needs