cancel
Showing results for 
Search instead for 
Did you mean: 

Backup Exit Notify script

vikram_mehta08
Level 3

How would I configure the backup_exit_notify script to email me when certain clients have failed their backups and be able to filter the emails with respect to the policy names?

2 ACCEPTED SOLUTIONS

Accepted Solutions

Dollypee
Moderator
Moderator
   VIP    Certified

Opscenter is easier as far as my experience of using past 8 years. The regular opscenter is free which could retain your info for about 60 days. Quick info here : http://eval.symantec.com/mktginfo/enterprise/white_papers/b-nbu_7_opscenter_analytics_WP.en-us.pdf

View solution in original post

sdo
Moderator
Moderator
Partner    VIP    Certified

Hi Vikram,

Here's an example backup_exit_notify.cmd for Windows:

@echo off
setlocal enabledelayedexpansion

REM ************************************************************************************************
REM *    File:      backup_exit_notify.cmd
REM *    Purpose:  Called by NetBackup, when backup jobs complete.
REM *
REM *    Vers    Date        Who    Description
REM *    ----    ----        ---    -----------
REM *    v0.01    23-APR-2015    sdo    First draft.
REM ************************************************************************************************
REM *    Disclaimer
REM *    ----------
REM *    This script was developed and tested using:
REM *        - Windows 2008 R2 SP1
REM *        - NetBackup Server v7.6.0.4
REM *
REM *    This script is not endorsed, nor has it been tested, by Symantec.  Neither the author, nor
REM *    Symantec, shall accept any liability from any harm, loss, or damage caused by the use
REM *    and/or mis-use of this script, either in its original form, or in a modified form.  Use of
REM *    this script in its original, or modified, form is entirely at the end user's own risk.
REM *    This script is furnished on an example basis only, and may not be suitable for any given
REM *    environment.  
REM ************************************************************************************************
REM *    Sharing
REM *    -------
REM *    This script is free to share and modify, as long as this entire header section is kept with
REM *    the script, and maintained and updated appropriately as any changes are made.
REM ************************************************************************************************
REM *    Notes
REM *    -----
REM *    1) Mutiple instances of this script could be instantiated concurrently by NetBackup at any
REM *       given time.
REM *
REM *    2) Therefore this script has to somehow make its own working file names unique.
REM *
REM *    3) Hence we use a double random number in an attempt to make our working file names unique.
REM *
REM *    4) When this script is run by NetBackup, then it runs as root, which in Windows means that
REM *       this script runs a "NT_System_Authority".
REM *
REM *    5) Therefore, when this script runs, the value in `!temp!` will probably point towards:
REM *        C:\Windows\Temp
REM *
REM *    6) Which means that if this script has a bug, or the call to bperror fails, or the call to
REM *       the emailer fails, then small temporary files will begin to accumulate in the folder
REM *       pointed to by `!temp!`, i.e. files will begin to accumulate in:
REM *        C:\Windows\Temp
REM *
REM *    7) NetBackup does not wait for the completion of this script, and therefore does not check
REM *       for, nor take any action based upon, the final exist status of this script.
REM ************************************************************************************************
REM ************************************************************************************************


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Build some file names used by this script...

set z_path=%~dp0
set z_name=%~n0

set z_random=!random!-!random!

set z_file_csv=!temp!\!z_name!.csv
set z_file_log=!temp!\!z_name!-!z_random!.log
set z_file_txt=!temp!\!z_name!-!z_random!.txt

if exist "!z_file_log!"  del "!z_file_log!"
if exist "!z_file_txt!"  del "!z_file_txt!"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Were we called by NetBackup?

if /i not "!IS_NETBACKUP_DAEMON!"=="yes" (
  echo !date! !time:~0,8!  Script can only be called by NetBackup...
  exit /b 1
)


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Append to a log of all backup job statii...

(echo !date! !time:~0,8!,!computername!,%~1,%~2,%~3,%~4,%~5,%~6,%~7,%~8)>>"!z_file_csv!"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If not "done_trying" then exit out ?
REM *** N.B: Comment out this line if you want all 'attempts' to send an email...

if "%~7"=="0"  exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If success, or partial, then do we need to email ?
REM *** N.B: Comment out these lines if you also want emails to be sent for backup status 0 or 1...

REM if "%~5"=="0"  exit /b

REM if "%~5"=="1"  exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Build an email message body text file...

call :r_txt ""
call :r_txt "Backup job details:"
call :r_txt "  P1 - Client:         %~1"
call :r_txt "  P2 - Policy:         %~2"
call :r_txt "  P3 - Schedule:       %~3"
call :r_txt "  P4 - Schedule Type:  %~4"
call :r_txt "  P5 - Status:         %~5"
call :r_txt "  P6 - Stream:         %~6"
call :r_txt "  P7 - Done Trying:    %~7"
call :r_txt "  P8 - Primary JobID:  %~8"

if not "%~5"=="0" (
  if not "%~5"=="1" (
    call :r_txt ""
    call :r_txt ""
    call :r_txt "Backup status `%~5` error is described as:"

    echo+ >>"!z_file_txt!"

    bperror -S %~5 -r >>"!z_file_txt!" 2>&1

    set z_sts=!errorlevel!

    if not !z_sts!==0 (
      call :log "...call to bperror failed, status `!z_sts!`..."
      goto :end
    )

    echo+ >>"!z_file_txt!"
  )
)

call :r_txt ""
call :r_txt "[end]"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Send an email...

set z_recipient=someone@whocares.com

if "%~5"=="0" (
  set z_subject=Backup job success for client %~1 in policy %~2...
) else (
  if "%~5"=="1" (
    set z_subject=Backup job partial for client %~1 in policy %~2...
  ) else (
    set z_subject=Backup job failed for client %~1 in policy %~2, with status %~5...
  )
)

call :log ""
call :log "Calling emailer..."

blat "!z_file_txt!" -s "!z_subject!" -t "!z_recipient!" -p myprofile -debug >>"!z_file_log!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to email failed, status `!z_sts!`..."
  goto :end
)


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If we get here, then the call to emailer appeared to be successful, so now we can remove...
REM *** ...the email body text file, and also remove the log file for the active running instance...
REM *** ...of this script...

if exist "!z_file_log!"  del "!z_file_log!"
if exist "!z_file_txt!"  del "!z_file_txt!"


REM ************************************************************************************************
REM ************************************************************************************************

:end

exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Write some text to the email body file,...
REM *** ...but also capture it in the log file for the running instance of this script...

:r_txt
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
(echo !date! !time:~0,8!  %~1)>>"!z_file_txt!"
goto :eof


REM ************************************************************************************************
REM ************************************************************************************************

:log
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
goto :eof

.

You'll need to adjust the call to 'blat' to call your email routine instead.

HTH.

View solution in original post

12 REPLIES 12

Dollypee
Moderator
Moderator
   VIP    Certified

Hi Vikram, Do you have opscenter environment? You will be able to get bulk of various report including what you have requested leveraging opscenter alert policies. Thank you

sdo
Moderator
Moderator
Partner    VIP    Certified

@Dolly - That's a good idea.

@Vikram - are you sure that you want to follow the backup_exit_notify route?

vikram_mehta08
Level 3

@Dolly I do not have an opscenter environment. I was originally configuring nbmail.cmd to call a VBScript to send emails but @sdo recommended to use backup_exit_notify to send better formated emails.

@sdo, should I not use the backup_exit_notify method? What are some negative implications they might have on the system?

sdo
Moderator
Moderator
Partner    VIP    Certified

Shouldn't be any major negatives - it's just that configuring email via OpsCenter should (but then again it might not be) easier.  And coding will ususally be trickier, especially if you haven't done much coding before.

Are you intending to email different teams depending upon the client type, or policy name?

In my experience only a very few specific backups would warrant an email - i.e. the most critical backups.  And if things are that super critical - then there should be a managed alerting system somewehere - and OpsCenter culd be used to send SNMP traps to such a centrally managed console / 24x7 Operations Incident team. 

It all depends what it is you want to do?  Each approach has its pros and cons, but OpsCenter should be easier.

Dollypee
Moderator
Moderator
   VIP    Certified

Opscenter is easier as far as my experience of using past 8 years. The regular opscenter is free which could retain your info for about 60 days. Quick info here : http://eval.symantec.com/mktginfo/enterprise/white_papers/b-nbu_7_opscenter_analytics_WP.en-us.pdf

sdo
Moderator
Moderator
Partner    VIP    Certified

Let me know if you want some help filtering (i.e. not emailing) based upon policy names.

However, things could get a bit tricky in code...

...it all depends upon how well 'structured' your policy names are in NetBackup.  If the names are all higgledy-piggledy - and all over the place with a mix of different naming conventions / formats etc... then... it will not be worth trying to implement code/logic within the script, as it will just become a complete mess and very difficult to maintain.

If policy names are not 100% structured and tidy, then our only course of action is to use a lookup file to decide upon whether to send an email, and/or whether to not send an email.

.

If we take the policy name lookup route, then do you want your script to:

a) yes - send an email - IF - a policy name exists in a lookup file

...or...

b) no - do not send an email - IF - a policy name exists in a lookup file

...or...

c) both of the above...

.

Let me know and I'll help you add some lines of code to do that.

sdo
Moderator
Moderator
Partner    VIP    Certified

Hi Vikram,

Here's an example backup_exit_notify.cmd for Windows:

@echo off
setlocal enabledelayedexpansion

REM ************************************************************************************************
REM *    File:      backup_exit_notify.cmd
REM *    Purpose:  Called by NetBackup, when backup jobs complete.
REM *
REM *    Vers    Date        Who    Description
REM *    ----    ----        ---    -----------
REM *    v0.01    23-APR-2015    sdo    First draft.
REM ************************************************************************************************
REM *    Disclaimer
REM *    ----------
REM *    This script was developed and tested using:
REM *        - Windows 2008 R2 SP1
REM *        - NetBackup Server v7.6.0.4
REM *
REM *    This script is not endorsed, nor has it been tested, by Symantec.  Neither the author, nor
REM *    Symantec, shall accept any liability from any harm, loss, or damage caused by the use
REM *    and/or mis-use of this script, either in its original form, or in a modified form.  Use of
REM *    this script in its original, or modified, form is entirely at the end user's own risk.
REM *    This script is furnished on an example basis only, and may not be suitable for any given
REM *    environment.  
REM ************************************************************************************************
REM *    Sharing
REM *    -------
REM *    This script is free to share and modify, as long as this entire header section is kept with
REM *    the script, and maintained and updated appropriately as any changes are made.
REM ************************************************************************************************
REM *    Notes
REM *    -----
REM *    1) Mutiple instances of this script could be instantiated concurrently by NetBackup at any
REM *       given time.
REM *
REM *    2) Therefore this script has to somehow make its own working file names unique.
REM *
REM *    3) Hence we use a double random number in an attempt to make our working file names unique.
REM *
REM *    4) When this script is run by NetBackup, then it runs as root, which in Windows means that
REM *       this script runs a "NT_System_Authority".
REM *
REM *    5) Therefore, when this script runs, the value in `!temp!` will probably point towards:
REM *        C:\Windows\Temp
REM *
REM *    6) Which means that if this script has a bug, or the call to bperror fails, or the call to
REM *       the emailer fails, then small temporary files will begin to accumulate in the folder
REM *       pointed to by `!temp!`, i.e. files will begin to accumulate in:
REM *        C:\Windows\Temp
REM *
REM *    7) NetBackup does not wait for the completion of this script, and therefore does not check
REM *       for, nor take any action based upon, the final exist status of this script.
REM ************************************************************************************************
REM ************************************************************************************************


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Build some file names used by this script...

set z_path=%~dp0
set z_name=%~n0

set z_random=!random!-!random!

set z_file_csv=!temp!\!z_name!.csv
set z_file_log=!temp!\!z_name!-!z_random!.log
set z_file_txt=!temp!\!z_name!-!z_random!.txt

if exist "!z_file_log!"  del "!z_file_log!"
if exist "!z_file_txt!"  del "!z_file_txt!"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Were we called by NetBackup?

if /i not "!IS_NETBACKUP_DAEMON!"=="yes" (
  echo !date! !time:~0,8!  Script can only be called by NetBackup...
  exit /b 1
)


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Append to a log of all backup job statii...

(echo !date! !time:~0,8!,!computername!,%~1,%~2,%~3,%~4,%~5,%~6,%~7,%~8)>>"!z_file_csv!"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If not "done_trying" then exit out ?
REM *** N.B: Comment out this line if you want all 'attempts' to send an email...

if "%~7"=="0"  exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If success, or partial, then do we need to email ?
REM *** N.B: Comment out these lines if you also want emails to be sent for backup status 0 or 1...

REM if "%~5"=="0"  exit /b

REM if "%~5"=="1"  exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Build an email message body text file...

call :r_txt ""
call :r_txt "Backup job details:"
call :r_txt "  P1 - Client:         %~1"
call :r_txt "  P2 - Policy:         %~2"
call :r_txt "  P3 - Schedule:       %~3"
call :r_txt "  P4 - Schedule Type:  %~4"
call :r_txt "  P5 - Status:         %~5"
call :r_txt "  P6 - Stream:         %~6"
call :r_txt "  P7 - Done Trying:    %~7"
call :r_txt "  P8 - Primary JobID:  %~8"

if not "%~5"=="0" (
  if not "%~5"=="1" (
    call :r_txt ""
    call :r_txt ""
    call :r_txt "Backup status `%~5` error is described as:"

    echo+ >>"!z_file_txt!"

    bperror -S %~5 -r >>"!z_file_txt!" 2>&1

    set z_sts=!errorlevel!

    if not !z_sts!==0 (
      call :log "...call to bperror failed, status `!z_sts!`..."
      goto :end
    )

    echo+ >>"!z_file_txt!"
  )
)

call :r_txt ""
call :r_txt "[end]"


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Send an email...

set z_recipient=someone@whocares.com

if "%~5"=="0" (
  set z_subject=Backup job success for client %~1 in policy %~2...
) else (
  if "%~5"=="1" (
    set z_subject=Backup job partial for client %~1 in policy %~2...
  ) else (
    set z_subject=Backup job failed for client %~1 in policy %~2, with status %~5...
  )
)

call :log ""
call :log "Calling emailer..."

blat "!z_file_txt!" -s "!z_subject!" -t "!z_recipient!" -p myprofile -debug >>"!z_file_log!" 2>&1

set z_sts=!errorlevel!

if not !z_sts!==0 (
  call :log "...call to email failed, status `!z_sts!`..."
  goto :end
)


REM ************************************************************************************************
REM ************************************************************************************************
REM *** If we get here, then the call to emailer appeared to be successful, so now we can remove...
REM *** ...the email body text file, and also remove the log file for the active running instance...
REM *** ...of this script...

if exist "!z_file_log!"  del "!z_file_log!"
if exist "!z_file_txt!"  del "!z_file_txt!"


REM ************************************************************************************************
REM ************************************************************************************************

:end

exit /b


REM ************************************************************************************************
REM ************************************************************************************************
REM *** Write some text to the email body file,...
REM *** ...but also capture it in the log file for the running instance of this script...

:r_txt
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
(echo !date! !time:~0,8!  %~1)>>"!z_file_txt!"
goto :eof


REM ************************************************************************************************
REM ************************************************************************************************

:log
(echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
goto :eof

.

You'll need to adjust the call to 'blat' to call your email routine instead.

HTH.

sdo
Moderator
Moderator
Partner    VIP    Certified

Oh - here's a tip...

...upgrades and patches to NetBackup will over-write any custom scripts...

...so, take a backup of them, or keep a copy somewhere else.

vikram_mehta08
Level 3

Okay, thank you, sdo. I will be unable to configure any of my NB settings until next week, but I will look through what you recommend. My supervisor doesn't want me to install any extra software so I can't go with opscenter, but I will look at modifying the backup_exit_notify file with my policies.

 

sdo
Moderator
Moderator
Partner    VIP    Certified

 

Yes, one should never install NetBackup Server (master or media) with OpsCenter Server, so that's a good call.

Do you have a VM environment?  It should be fairly easy to install a VM for OpsCenter, it's not too hungry - but this depends upon size of the NetBackup environment(s)/domain(s) that you want to monitor/manage/report/alert on.

A typical starting point for a VM for OpsCenter, might be:

- 2 x medium vCPU

- 6GB vRAM (1GB for OS, 2 GB for OpsCenter WebGUI, 1GB for OpsCenter Java based application server, and 2GB for OpsCenter database server).

- 95GB of vDisk (35GB for C: for Windows OS, 20GB for D: for OpsCenter installation binaries and logs, 20GB for E: for OpsCenter database, 20GB for F: for OpsCenter Database Backups).

.

Anyway, back to backup_exit_notify...

If you are going to 'filter' based on logic/code (i.e. based upon 'IF' statements) inside the script then there are perhaps four ways of doing this...

1) Nested IFs to decide whether an email should be sent.

2) Nested IFs to decide whether an email should not be sent.

3) Assume an email should be sent, but then use a sequence of of IFs to decide whether to not send an email.

4) Assume an email should not be sent, but then use a sequence of IFs to decide that an email should be sent.

.

So, the two main approaches are; use nested IFs, or use a sequence of IFs.

Nested IFs can get quite messy, difficult to read, and difficult to maintain, whereas a sequence of IFs is easy on the eye, and can easily be kept in alphabetical order, and is easy to maintain.

.

If you can answer this next question, then I will demonstrate two different coding styles to you, and then you'll see why I said what I have said above...

...and the question is a multi-part question, all of which tries to determine the scale of the problem/solution:

Q1) From the entire list of policies, do you want most policies to send an email?

Q2) From the entire list of policies, do you want most policies to not send an email?

Q3) From the entire list of policies, do you want only a few policies to send an email?

Q4) From the entire list of policies, do you want only a few policies to not send an email?

If you can reply with a yes or no to the four questions above, then this will inform us of the best approach to coding the 'policy name based' logic/code/IFs for your version of your backup_exit_notify script.

vikram_mehta08
Level 3

Hello,

Sorry I have not replied since last week. I became extremely busy. What I want my backup_exit_notify script to do is email (with details) about my backup status. To answer the questions you asked, what I am trying to accomplish is not in coorelation to the policies. I want to report statuses of the backups of clients including what policy they are from. So according to backup_exit_notify, I would just need to email details like %1-%5, and also %8 if needed.

Thank you

sdo
Moderator
Moderator
Partner    VIP    Certified

Yep - the script above will do that for you.

All you have to do is modify the 'blat' line:

blat "!z_file_txt!" -s "!z_subject!" -t "!z_recipient!" -p myprofile -debug >>"!z_file_log!" 2>&1

...to use your method of calling 'blat' - or to call/use your own email script/routine.

.

Are you stuck on how to configure 'blat'?

Or, at your site/customer are you not allowed to use a third party SMTP client (like blat) and so must write your own script to send via SMTP?

Remember - many tens of thousands of NetBackup sites use 'blat', and I've never heard of a problem with it.  I would think that only the most 'secure' sites would not be able to use it.