Forum Discussion

Dollypee's avatar
Dollypee
Moderator
2 months ago
Solved

Netbackup Hot catalog DR email notification in windows server

Hello Community,

Quick question: Has anyone successfully configured NetBackup hot catalog backup DR email notifications using PowerShell's Send-MailMessage cmdlet or any related commands, instead of relying on BLAT to send emails on Windows? I'm looking to transition from BLAT to utilizing PowerShell's native Send-MailMessage functionality.

  • Hi Dollypee 

    In the interests in sharing this with the wider community, here is a method that I have working in a test lab. The code could probably be improved, but it works as is. One caveat though, you will require the primary server to allow local powershell scripts to execute - I have tried to use the ExecutionPolicy directive when calling the powershell script, but this may be overridden by group policy. You milage will vary - my test system doesn't require this.

    The solution consists of two parts, the first is the command file the NetBackup looks for - mail_dr_info.cmd (the template for this is the nbmail.cmd file that lives in the goodies folder). The second part is a short powershell script that runs the cmdlet Send-MailMessage - I have called this mail_dr_info.ps1 - it just needs to match the name from the first script. 

    The first script - mail_dr_info.cmd follows:

    @REM $Header$
    @REM
    @REM bcpyrght
    @REM ***************************************************************************
    @REM * $Copyright: Copyright (c) 2022 Veritas Technologies LLC. All rights reserved $ *
    @REM ***************************************************************************
    @REM ecpyrght
    @REM                                                                          -
    @REM  HOW TO SEND DR MAIL FROM THE NT NETBACKUP SERVER                        -
    @REM                                                                          -
    @REM  NetBackup DR protection checks if the mail script                       -
    @REM  (NetBackup\Bin\mail_dr_info.cmd) exists.  If the script exists          -
    @REM  NetBackup DR protection runs it passing four parameters on the          -
    @REM  command line:                                                           -
    @REM                                                                          -
    @REM       %1 is the recipient's address                                      -
    @REM       %2 is the subject line                                             -
    @REM       %3 is the message file name                                        -
    @REM       %4 is the attached file name                                       -
    
    
    @FOR /F "tokens=2,* skip=2" %%L IN (
        'reg query "HKLM\SOFTWARE\Veritas\NetBackup\CurrentVersion" /v INSTALLDIR'
    ) DO @SET instpath=%%M
                                               
    @call powershell -ExecutionPolicy RemoteSigned -file "%instpath%NetBackup\bin\mail_dr_info.ps1" -sendto %1 -subj %2 -msgfile %3 -drfiles %4
    

    The second script - mail_dr_info.ps1 follows:

    # Grab input parameters
    param (
    	[Parameter(Mandatory=$true)]
    	[string]$sendto,
    	[string]$subj,
    	[string]$msgfile,
    	[string]$drfiles
    )
    
    $body = Get-Content $msgfile -Raw
    $from = "sender@server.domain"
    $drarray = $drfiles.Split(',')
    $smtpsrv = "smtpsrv.domain"
    
    Send-MailMessage -Subject $subj -SmtpServer $smtpsrv -From $from -To $sendto -Attachments $drarray -Body $body

    Note - there are two variables in the powershell script that need to be updated to suit your environment. 

    Enjoy
    David

     

1 Reply

  • Hi Dollypee 

    In the interests in sharing this with the wider community, here is a method that I have working in a test lab. The code could probably be improved, but it works as is. One caveat though, you will require the primary server to allow local powershell scripts to execute - I have tried to use the ExecutionPolicy directive when calling the powershell script, but this may be overridden by group policy. You milage will vary - my test system doesn't require this.

    The solution consists of two parts, the first is the command file the NetBackup looks for - mail_dr_info.cmd (the template for this is the nbmail.cmd file that lives in the goodies folder). The second part is a short powershell script that runs the cmdlet Send-MailMessage - I have called this mail_dr_info.ps1 - it just needs to match the name from the first script. 

    The first script - mail_dr_info.cmd follows:

    @REM $Header$
    @REM
    @REM bcpyrght
    @REM ***************************************************************************
    @REM * $Copyright: Copyright (c) 2022 Veritas Technologies LLC. All rights reserved $ *
    @REM ***************************************************************************
    @REM ecpyrght
    @REM                                                                          -
    @REM  HOW TO SEND DR MAIL FROM THE NT NETBACKUP SERVER                        -
    @REM                                                                          -
    @REM  NetBackup DR protection checks if the mail script                       -
    @REM  (NetBackup\Bin\mail_dr_info.cmd) exists.  If the script exists          -
    @REM  NetBackup DR protection runs it passing four parameters on the          -
    @REM  command line:                                                           -
    @REM                                                                          -
    @REM       %1 is the recipient's address                                      -
    @REM       %2 is the subject line                                             -
    @REM       %3 is the message file name                                        -
    @REM       %4 is the attached file name                                       -
    
    
    @FOR /F "tokens=2,* skip=2" %%L IN (
        'reg query "HKLM\SOFTWARE\Veritas\NetBackup\CurrentVersion" /v INSTALLDIR'
    ) DO @SET instpath=%%M
                                               
    @call powershell -ExecutionPolicy RemoteSigned -file "%instpath%NetBackup\bin\mail_dr_info.ps1" -sendto %1 -subj %2 -msgfile %3 -drfiles %4
    

    The second script - mail_dr_info.ps1 follows:

    # Grab input parameters
    param (
    	[Parameter(Mandatory=$true)]
    	[string]$sendto,
    	[string]$subj,
    	[string]$msgfile,
    	[string]$drfiles
    )
    
    $body = Get-Content $msgfile -Raw
    $from = "sender@server.domain"
    $drarray = $drfiles.Split(',')
    $smtpsrv = "smtpsrv.domain"
    
    Send-MailMessage -Subject $subj -SmtpServer $smtpsrv -From $from -To $sendto -Attachments $drarray -Body $body

    Note - there are two variables in the powershell script that need to be updated to suit your environment. 

    Enjoy
    David