Forum Discussion

Rajesh_s1's avatar
Rajesh_s1
Level 6
13 years ago

NetBackup notify scripts

Hi All,

I am looking to incorporate some script which needs to trigger one batch file at the time of backup begins and once the backup completes "if its a successful backup" then it should trigger an another batch file . 

I gone through the guide but i couldn't able to understand properly .

Please let me know how can i do this 

Regards,

Rajesh

 

 

 

  • Hi All,

    Finally i am able to achive what i wanted , below is the exact script which solved my problem.

     

    @REM --------------------------------------------------------------------
    @REM main script starts here
    @REM This is a simple script that records what kind of backup was done along
    @REM with other relevent information (Client name, policy name, etc) and 
    @REM appends the information to the results file
    @REM --------------------------------------------------------------------
     
    @if %5 == 0 goto DISK
    @GOTO :EOF

    :DISK
    mountvol J:\Mount_points\DBP /d
    diskpart /s "C:\HORCM\Backup_Diskpart\diskpart.txt"
    @GOTO :EOF

     

    " Where inturn the diskpart.txt will call diskpart and offline the disk" . And now if and only if the backup status is "0" it is executing other command else not.

    One of the main thing what i noticed is we should not give %5 == "0" , correct syntax is %5 == 0 and in the next line we should give @GOTO :EOF else it was executing rest all commands at all the times.

     

    Thanks a lot Mark and Mariane for all your support.

    Regards,

    Rajesh

     

  • Hi Marianne,

    Thanks a lot , i have edited the script as below and now i am able to run my custom script. 

    Is there any way to define the script has to execute only when it is  a successful backup when status is  "0" , if the status is "1" then it should rerun the backup .

     

     

    @REM $Id: bpend_notify.bat,v 1.3 2006/08/01 20:46:43 $ 
    @REM ***************************************************************************
    @REM * $VRTScprght: Copyright 1993 - 2011 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 --------------------------------------------------------------------
    @REM main script starts here
    @REM This is a simple script that records what kind of backup was done along
    @REM with other relevent information (Client name, policy name, etc) and 
    @REM appends the information to the results file
    @REM --------------------------------------------------------------------
     
     
    cd
     
    cd "C:\Windows\System32\"
     
    diskpart1.cmd
  • Rajesh

    From the script above you will see that there is the line 5% = Status of Backup

    So you need to add a conditional line saying something to the effect

    If 5% = 0 Then Unmount

    Else End

    [Unmount]
     
    cd "C:\Windows\System32\"
     
    diskpart1.cmd

    End

    Or similar to what you had initially:

    if "%5" == "0" "C:\Windows\System32\diskpart1.cmd"

    I'm not the best at scripting but i am sure someone can guide you on the correct syntax

  • HI ,

    I tired many options but not able to achive , every time the script is getting executed even the job is failed .

    I just want to execute the customized bpend_notify scrity only when the backup is successfully complted (i,.e. when only the status is '0').

     

    Regards,

    Rajesh

  • Rajesh

    Try this:

    if "%5" == "0" goto COMMAND
    GOTO :EOF
    :COMMAND
    C:\Windows\System32\diskpart1.cmd
    @REM end of file

  • GOT IT !!

    I am no script writer either, but I just had to try for myself.

    Created bpend_notify.bat in netbackup\bin on my laptop with only the following 2 lines:

    echo "%5" >>c:\temp\junk.txt
    if "%5" == "0" "c:\temp\test.bat"

    My  c:\temp\test.bat had this line:

    @echo Backup successful >>c:\temp\junk.txt

    After a successful backup I had the following 2 lines in junk.txt:

    "0"
    Backup successful
     

    I then changed my backup selection to force a status 71.

    After the failed backup, my junk.txt looked as follows (note that I am appending to junk.txt each time, meaning that the 2 lines from the 1st backup are still there):

    "0"
    Backup successful
    "71"

    Just to really proof that test.back was NOT called, I deleted junk.txt and reran the backup. Result in junk.txt:

    "71"

    Followed by successful backup without cleaning out junk.txt first:

    "71"
    "0"
    Backup successful

     

    Conclusion?

    Only one line is needed in bpend_notify.bat:

    if "%5" == "0" "path\script"

  • Marianne - i agree and that is exactly what the last but one line of my post on 31st October says, but Rajesh did say that did not work for him - not sure why - hence my alternative today.

    Hopefully one of these will work!

  • Marianne - i do appreciate it - i have always been a physicist and believe that one practical is worth a thousand theories.

  • Great !!

    Dont forget to mark a solution to close the thread if you feel that it is appropriate

    Glad we have been able to help

  • Hi All,

    Finally i am able to achive what i wanted , below is the exact script which solved my problem.

     

    @REM --------------------------------------------------------------------
    @REM main script starts here
    @REM This is a simple script that records what kind of backup was done along
    @REM with other relevent information (Client name, policy name, etc) and 
    @REM appends the information to the results file
    @REM --------------------------------------------------------------------
     
    @if %5 == 0 goto DISK
    @GOTO :EOF

    :DISK
    mountvol J:\Mount_points\DBP /d
    diskpart /s "C:\HORCM\Backup_Diskpart\diskpart.txt"
    @GOTO :EOF

     

    " Where inturn the diskpart.txt will call diskpart and offline the disk" . And now if and only if the backup status is "0" it is executing other command else not.

    One of the main thing what i noticed is we should not give %5 == "0" , correct syntax is %5 == 0 and in the next line we should give @GOTO :EOF else it was executing rest all commands at all the times.

     

    Thanks a lot Mark and Mariane for all your support.

    Regards,

    Rajesh