cancel
Showing results for 
Search instead for 
Did you mean: 

bpend_notify scripting

Mark_Hill
Level 4
Hey Guys,
   We are going to start using this script to send emails to our mobile phone sms gateway when backups fail.
But...

We need to filter out which ones get reported. Im not a script guy, but I see that the script gets param's called POLICYNAME and CLIENTNAME, so can a statement be added using an if statement to filter certain clients/policies?

e.g. If CLIENTNAME = then continue else end

That kinda thing? Obviously I didnt use any kind of syntax there, just thinking out loud.

Ideas?

Thanks in advance.
3 REPLIES 3

rhatguy
Level 3
Sure you can put any if statements or any other normal shell commands in this script.  You'll want to reference things via their variable names though. 

# This script:
#       receives 5 parameters: CLIENTNAME POLICYNAME SCHEDNAME SCHEDTYPE STATUS
#       must be executable by the root user
#       should exit with 0 upon successful completion


so your CLIENTNAME would be referenced as $1 and STATUS would be $5.  You'll probably need at least 1 if statement for

if $5 = 0
then
don't alert....as the backup was successful
else
alert
fi

sdo
Moderator
Moderator
Partner    VIP    Certified
Hi Mark,
 
The "bpend_notify" is normally a client side script, to handle tidy up of backups streams/jobs.  You could implement your requirements in this script, but then you'll have to copy it to all clients that you want to monitor.  Also, "bpend_notify" is quite finicky, in that it must not generate any output to stdout or stderr, as any output on these channels is treated as backup data to be sent to the media server and thus may actually cause your working backups to fail.
 
Another alternative is to locate the SMSing in the script on the master server that is run whenever any backup jobs completes, and this script is known as "backup_exit_notify".
 
You didn't specify your OS or NBU versions.
 
Attached is a copy of my "backup_exit_notify.cmd" for NBU ES v5.1 MP6 on WIndows 2000 Adv Server SP$ MSCS cluster.  You'll need to tweak it a bit.
 
The key point to note is that the R: drive is our clustered catalog drive (which is SAN attached).  You may need to change this depenfing on where you keep your scripts on your master server.
 
We use different lists of client names (i.e. text files that contain client names) to determine which team is sent an email.
 
Regards,
Dave.
 
 
 
 
 
Cut below-------------------------------------------------------------------
 
@echo off
REM See foot of file for technical notes and version table.
 
setlocal enableextensions
set OUTF="%~dp0\BACKUP_EXIT_CALLED"
 

REM ---------------------------------------------------------------------------
REM - Check for proper parameter use...
REM ---------------------------------------------------------------------------

if "%6" == "" goto :BadParams
if "%7" == "" goto :GoodParams
 

:BadParams
REM ---------------------------------------------------------------------------
REM - Incorrect number of parameters...
REM ---------------------------------------------------------------------------
echo backup_exit_notify expects 6 parameters: %* >> %OUTF%

goto :end
 

:GoodParams
REM ----------------------------------------------------------------------------
REM - We only email if the job has failed, so leave if the backup was good or partial...
REM ---------------------------------------------------------------------------
if "%5" == "0" goto :end
if "%5" == "1" goto :end
 
REM ----------------------------------------------------------------------------
REM - Setup some variables to save too much hard coding...
REM ---------------------------------------------------------------------------
set z_dt=%date% %time:~0,8%
set z_blat=%windir%\System32\blat
set z_admincmd=D:\VERITAS\NetBackup\bin\admincmd
set z_name=%~n0
set z_path=R:\Scripts\%z_name%
set z_subject=NetBackup job for client '%1' failed with status '%5'.
 
REM ----------------------------------------------------------------------------
REM - Create a file to contain the email text/body...
REM ---------------------------------------------------------------------------
if exist %OUTF% del %OUTF%

echo ------------------------------------------------- >> %OUTF%
echo %z_subject% >> %OUTF%
echo ------------------------------------------------- >> %OUTF%
echo CLIENT:         %1 >> %OUTF%
echo POLICY:         %2 >> %OUTF%
echo SCHEDULE:       %3 >> %OUTF%
echo SCHEDULE TYPE:  %4 >> %OUTF%
echo STATUS:         %5 >> %OUTF%
echo STREAM:         %6 >> %OUTF%
echo DATE TIME:      %z_dt% >> %OUTF%
echo ------------------------------------------------- >> %OUTF%
echo . >> %OUTF%
echo The meaning of the exit status %5 is: >> %OUTF%
echo . >> %OUTF%
%z_admincmd%\bperror -S %5 -r >> %OUTF%
echo ------------------------------------------------- >> %OUTF%
 
REM --------------------------------------------------------------------------
REM - Always send email to NetBackup admins...
REM ---------------------------------------------------------------------------
for /f %%r in (%z_path%\support_adm.txt) do (
 %z_blat% %OUTF% -to %%r -i Netbackup -s "%z_subject%" > NUL
)
 
REM ---------------------------------------------------------------------------
REM - Are we to ignore this policy (i.e. don't inform any other support teams)...
REM ---------------------------------------------------------------------------
find /i "%2" %z_path%\ignore_pol.txt > NUL
if %errorlevel% equ 0 goto :end
 
REM ---------------------------------------------------------------------------
REM - Send to Unix admins if applicable, and forward email to the Unix
REM - monitoring account "xx" on "xx"...
REM ---------------------------------------------------------------------------
find /i "%2" %z_path%\unix_pol.txt > NUL
if %errorlevel% equ 0 (
 for /f %%r in (%z_path%\unix_adm.txt) do (
   %z_blat% %OUTF% -to %%r -i Netbackup -s "%z_subject%" > NUL
 )
 %z_blat% %OUTF% -to syschk -i Netbackup -s "%z_subject%" -server 10.xx.xx.xx:25 > NUL
)
 
REM ---------------------------------------------------------------------------
REM - Send to Windows admins if applicable...
REM ---------------------------------------------------------------------------
find /i "%2" %z_path%\win_pol.txt > NUL
if %errorlevel% equ 0 (
 for /f %%r in (%z_path%\win_adm.txt) do (
   %z_blat% %OUTF% -to %%r -i Netbackup -s "%z_subject%" > NUL
 )
)
 
REM ---------------------------------------------------------------------------
REM - Send to VMS admins if applicable...
REM ---------------------------------------------------------------------------
find /i "%2" %z_path%\vms_pol.txt > NUL
if %errorlevel% equ 0 (
 for /f %%r in (%z_path%\vms_adm.txt) do (
   %z_blat% %OUTF% -to %%r -i Netbackup -s "%z_subject%" > NUL
 )
)
 
:end
REM ---------------------------------------------------------------------------
REM - End of batch file...
REM ---------------------------------------------------------------------------

endlocal
exit /b
 
REM #################################################################################
REM # Name: backup_exit_notify.cmd
REM # Purpose: NetBackup job completion notify script.
REM # Author: Unknown
REM # Date: 24th June 2004
REM #
REM # Date   Who Description
REM # ----   --- -----------
REM # 24/06/2004  xx Initial version.
REM # 05/09/2006  DR Now only do processing if job is unsuccessful.
REM #################################################################################

@REM
@REM $Header: /ovsrc/int/CVS/src/nb/tools/backup_exit_notify.cmd,v 1.2 2002/11/20 02:10:34 $
@REM
@REM bcpyrght
@REM ***************************************************************************
@REM * $VRTScprght: Copyright 1993 - 2002 VERITAS Software Corporation, All Rights Reserved $ *
@REM ***************************************************************************
@REM ecpyrght
@REM
@REM backup_exit_notify.cmd
@REM
@REM This script is called by the NetBackup scheduler, after an individual
@REM client backup has completed (including media closure and image db
@REM validation.
@REM
@REM NOTE:  this script will always be run in "background" mode, meaning that
@REM        the NetBackup scheduler will NOT wait for it's completion.
@REM
@REM This script:
@REM receives 5 parameters:
@REM  %1 = CLIENT           - the client hostname
@REM  %2 = POLICY           - the policy label
@REM  %3 = SCHEDULE         - the schedule label
@REM  %4 = SCHEDULE_TYPE    - the type of schedule:  FULL INCR UBAK
@REM                                                 UARC
@REM  %5 = STATUS           - the backup status for this job
@REM  %6 = STREAM           - the backup stream number for this job
@REM
@REM - Main program ------------------------------------------------------------
@REM -
@REM - This script only runs on NT 4.0 and succeeding versions of NT.  You must
@REM - have command extensions enabled.  Check the following registry entry:
@REM -
@REM - HKEY_CURRENT_USER\Software\Microsoft\Command Processor\EnableExtensions
@REM -
@REM - It should be set to 0x1 or you may have problems running this script.
@REM ---------------------------------------------------------------------------

Mark_Hill
Level 4
Hey David, Thanks for the reply, Im sure we can use some of this in our situation.

Perhaps I should have mentioned that we run a Solaris Master server :p

Cheers!