@echo off
setlocal enabledelayedexpansion
REM #################################################################################################
REM # File: bpend_notify.bat
REM # Purpose: Script is run with wait at the end of every NetBackup stream.
REM # >>> BUT, if the job is multi-plexed then this job is NOT waited for.
REM #
REM # Vers Date Who Notes
REM # ---- ---- --- -----
REM # v0.01 9-NOV-2008 DR First draft.
REM # v0.02 26-NOv-2008 DR Check for expected client and streams.
REM # v0.03 17-FEB-2009 DR Configure for SEVPR1.
REM # v0.04 19-FEB-2009 DR Added routines to stop and start PatrolAgent service.
REM # v0.05 20-FEB-2009 DR Modified for non-streamed job, thus no STREAM_* variables.
REM # v0.06 3-MAR-2009 DR Disabled stop and start of PatrolAgent.
REM #################################################################################################
set z_path=%~dp0
set z_name=%~n0
set z_log=!z_path!!z_name!.log
set z_tmp=!z_path!!z_name!.tmp
set z_expected_client=sevpr1
set z_expected_streams=1
set z_evopmode=D:\Program Files\Enterprise Vault\EVOPMODE.bat
call :log ""
call :log ""
call :log "-------------------START--------------------"
call :log "Date time: !date! !time:~0,8!"
call :log "Client: %~1"
call :log "Policy: %~2"
call :log "Sched Name: %~3"
call :log "Sched Type: %~4"
call :log "Status: %~5"
call :log "Results File: %~6"
call :log "Stream Number: !STREAM_NUMBER!"
call :log "Stream Count: !STREAM_COUNT!"
call :log "Stream PID: !STREAM_PID!"
call :log ""
if /i not "%~4"=="full" (
goto :err_not_full
)
if /i not "%~1"=="!z_expected_client!" (
goto :err_not_cluster
)
if /i not "%~5"=="0" (
goto :err_backup_not_successful
)
REM if /i not "!stream_count!"=="!z_expected_streams!" (
REM goto :err_not_correct_streams
REM )
REM if /i "!stream_number!"=="!stream_count!" (
if not exist "!z_evopmode!" goto :err_evopmode_missing
REM call :patrol stop
REM if /i "!z_error!"=="y" goto :err_patrol_stop_failed
call :log "Calling EVOPMODE READWRITE..."
call "!z_evopmode!" READWRITE >> "!z_log!"
set z_sts=%errorlevel%
call :log "Return status is: `!z_sts!`"
if /i not "!z_sts!"=="0" (
if /i not "!z_sts!"=="9009" (
goto :err_evopmode_failed
)
)
REM call :patrol start
REM if /i "!z_error!"=="y" goto :err_patrol_start_failed
REM ) else (
REM call :log "No action taken for stream `!stream_number!`..."
REM )
call :log "Informing parent job of success, by writing status 0 to results file..."
echo 0 > "%~6"
call :log "---------SUCCESS---------"
exit /b 0
:patrol
set z_action=%~1
set z_service=PatrolAgent
set z_exists=N
set z_error=N
if exist "!z_tmp!" del "!z_tmp!"
call :log "Attempting `!z_action!` for service `!z_service!`..."
net !z_action! "!z_service!" >> "!z_log!"
call :log "Status `!errorlevel!`..."
net start >> "!z_tmp!"
for /f "tokens=*" %%a in ('type "!z_tmp!"') do (
if /i "%%a"=="!z_service!" set z_exists=Y
)
call :log "Does service exist: `!z_exists!`..."
if /i "!z_action!"=="STOP" (
if /i "!z_exists!"=="Y" (
call :log "Failed to stop service `!z_service!`..."
set z_error=Y
goto :eof
)
) else (
if /i "!z_exists!"=="N" (
call :log "Failed to start service `!z_service!`..."
set z_error=Y
goto :eof
)
)
if /i "!z_exists!"=="Y" call :log "Service `!z_service!` is running..."
if /i "!z_exists!"=="N" call :log "Service `!z_service!` is stopped..."
goto :eof
REM #####################################################
REM # Reasons to quit, but not abort...
REM #
:quit_exit
call :log "Informing parent job of success, by writing status 0 to results file..."
echo 0 > "%~6"
call :log "---------QUIT------------"
exit /b 0
REM #####################################################
REM # Reasons to quit AND abort...
REM #
:err_not_full
call :log "Unexpected schedule type not full, aborting..."
goto :err_exit
:err_not_cluster
call :log "Not a backup of expected client name `!z_expected_client!`, assuming this is a plain client backup, aborting..."
goto :err_exit
:err_not_correct_streams
call :log "Not part of a `!z_expected_streams!` stream job, assuming this is a test or re-run, aborting..."
goto :err_exit
:err_evopmode_missing
call :log "The EVOPMODE script could not be found at `z_evopmode`, aborting..."
goto :err_exit
:err_evopmode_failed
call :log "The call to EVOPMODE failed, aborting..."
goto :err_exit
:err_patrol_stop_failed
call :log "Failed to stop the Patrol service, aborting..."
goto :err_exit
:err_patrol_start_failed
call :log "Failed to start the Patrol service, aborting..."
goto :err_exit
:err_backup_not_successful
call :log "The backup was not successful, aborting..."
goto :err_exit
:err_exit
call :log "Informing parent job of failure, by writing status 999 to results file..."
echo 999 > "%~6"
call :log "---------FAILURE---------"
exit /b 0
REM #####################################################
REM # Sub-routines...
REM #
:log
echo !date! !time:~0,8! !z_name:~0,12! %~1 >> "!z_log!"
goto :eof
@REM $Id: bpend_notify.bat,v 1.3 2006/08/01 20:46:43 $
@REM ***************************************************************************
@REM * $VRTScprght: Copyright 1993 - 2008 Symantec Corporation, All Rights Reserved $ *
@REM ***************************************************************************
@REM ecpyrght
@REM
@REM bpend_notify.bat
@REM
@REM This script is called by NetBackup when bpbkar is finished doing a
@REM backup on the client. It is also called after backing up the files
@REM for a user directed archive, but before the files are deleted.
@REM
@REM This script receives 6 parameters:
@REM %1 = CLIENT_NAME
@REM %2 = POLICY_NAME
@REM %3 = SCHEDULE_NAME
@REM %4 = SCHEDULE_TYPE, one of the following: FULL, INCR, CINC, UBAK, UARC
@REM %5 = Status of backup
@REM %6 = RESULT_FILE
@REM
@REM The script must reside in in the same directory as the rest of the NetBackup
@REM client binaries (install_path\netbackup\bin\bpend_notify.bat).
@REM It must also be executable by the root user.
@REM Should exit with 0 upon successful completion
@REM
@REM Naming conventions:
@REM There are three different versions of names that the scripts can use.
@REM The start notify script may use one version and the end notify script may use
@REM another, or they can both use the same version.
@REM
@REM Substitute "policy" with the NetBackup policy being used and "sched" with the
@REM schedule name. "bpend" can be substituted with "bpstart".
@REM bpend_notify.policy.sched.bat
@REM bpend_notify.policy.bat
@REM bpend_notify.bat
@REM
@REM Result files:
@REM The result file names will be dependant on the script file names.
@REM Example:
@REM Script name: Result file name:
@REM bpstart_notify.policyA.schedB.bat BPSTART_RES.policyA.schedB
@REM bpstart_notify.policyB.bat BPSTART_RES.policyB
@REM bpend_notify.bat BPEND_RES
@REM bpend_notify.policyC.bat BPEND_RES.policyC
@REM
@REM CAUTION: Writing anything to stdout or stderr will cause backup problems.
@REM Output should be redirected to the results files.
@REM
@REM --------------------------------------------------------------------