Forum Discussion

tarladak's avatar
tarladak
Level 4
10 years ago

is there any way i can cancel backup automatically through script

Hi,

I wanted to cancel on server backup automatically if it is runinng after 6AM. Is there any command i can execute or schedule?

I am using netbackup 7.5, windows 2008r2 and client is also windows2008r2.

 

Regards,

Kiran.

  • If this was my customer, my response would be exactly as per my post above. 
    I would tell them that they will need to do this as a manual task and also inform them that as their Support partner we take no resonsibility for data that cannot be restored as a result of cancelled backups.

    There is no point in running backups just to cancel it.

    If they want to write scrips, you can tell them about bpdbjobs command that can be run and piped to findstr to list active jobs and then use bpdbjobs again to cancel the job id's. 
    They can then put the script in the OS task manager to run at a certain time.
    Make them understand that this is 100% their responsibility.

    As Support partner, your SLA with the customer should be to ensure backups and restores.
    NOT cancelling jobs....

  • Ya.. agreed with Marianne that you should push back to the server owner. It is their responsibiliy to do that, not backup admin's.

    And they can simply do that by killing the bpbkar job on the server if it is after 6AM. Insert a "taskkill /f /im bpbkar32.exe"  in a task scheduler running on 6AM.

  • Automatically cancel backups?

    What is the point of running backups just to cancel it?

    Rather spend time to tune your environment and ensure backups complete within the backup window.

  • Hi Marianne,

     

    Thank you for you reply. Currently backups are running fine and completing before 4AM, but client insisting to implement this process to make sure no impact on network. 

     

    Regards,

    Kiran.

  • If this was my customer, my response would be exactly as per my post above. 
    I would tell them that they will need to do this as a manual task and also inform them that as their Support partner we take no resonsibility for data that cannot be restored as a result of cancelled backups.

    There is no point in running backups just to cancel it.

    If they want to write scrips, you can tell them about bpdbjobs command that can be run and piped to findstr to list active jobs and then use bpdbjobs again to cancel the job id's. 
    They can then put the script in the OS task manager to run at a certain time.
    Make them understand that this is 100% their responsibility.

    As Support partner, your SLA with the customer should be to ensure backups and restores.
    NOT cancelling jobs....

  • Ya.. agreed with Marianne that you should push back to the server owner. It is their responsibiliy to do that, not backup admin's.

    And they can simply do that by killing the bpbkar job on the server if it is after 6AM. Insert a "taskkill /f /im bpbkar32.exe"  in a task scheduler running on 6AM.

  • Thank you guys for suggestions. I will convey this message to my client.

  • Here's a script that will cancel unfinished backup jobs for specific clients.  Tested using NetBackup Server v7.6.1.2 on Windows 2012 R2, but it should work for your version too.

    Amend the required lines to match client names, and created a scheduled task to run it.

    @echo off
    setlocal enabledelayedexpansion
    
    set z_path=%~dp0
    set z_name=%~n0
    
    set z_file_job=!z_path!!z_name!.job
    set z_file_log=!z_path!!z_name!.log
    set z_file_tmp=!z_path!!z_name!.tmp
    
    if exist "!z_file_job!"  del "!z_file_job!"
    if exist "!z_file_tmp!"  del "!z_file_tmp!"
    
    call :log ""
    call :log "************************************************"
    call :log "Script started..."
    
    call :log ""
    call :log "Determining NetBackup installation path..."
    
    reg query "HKLM\Software\Veritas\NetBackup\CurrentVersion" /v "InstallDir" >"!z_file_tmp!" 2>&1
    set z_sts=!errorlevel!
    if not !z_sts!==0 (
      call :log "...failed to determine install directory for NetBackup, status `!z_sts!`, script aborting..."
      goto :end
    )
    for /f "tokens=1,2,* skip=1" %%a in ('type "!z_file_tmp!"') do (
      set z_installdir=%%c
    )
    
    call :log "...NetBackup installation path is:  !z_installdir!"
    call :log "...done..."
    
    set z_bpdbjobs=!z_installdir!NetBackup\bin\admincmd\bpdbjobs.exe
    
    call :log ""
    call :log "Listing activity monitor jobs..."
    
    "!z_bpdbjobs!" -most_columns -file "!z_file_job!" >nul 2>&1
    set z_sts=!errorlevel!
    if not !z_sts!==0 (
      call :log "...failed to retrieve jobs, status `!z_sts!`, script aborting..."
      goto :end
    )
    
    call :log "...done..."
    
    call :log ""
    call :log "Processing list of jobs..."
    
    set /a z_job_records=0
    set /a z_backups_unfinished=0
    set /a z_backups_cancelled=0
    
    for /f "tokens=1,2,3,4,5,6,7,8,9,10 delims=," %%a in ('type "!z_file_job!"') do (
      set z_job_jobid=%%a
      set z_job_type=%%b
      set z_job_state=%%c
      set z_job_client=%%f
    
      set /a z_job_records+=1
    
      set z_cancel=N
    
      if not "!z_job_state!"=="3" (
        if "!z_job_type!"=="0" (
          set /a z_backups_unfinished+=1
    
          call :log "...found job `!z_job_jobid!` is an unfinished backup for client `!z_job_client!`..."
    
    REM **** add more lines just here for more clients to cancel...
          if /i "!z_job_client!"=="my-long-client-name.at-my-domain.zzz"  set z_cancel=Y
          if /i "!z_job_client!"=="client01"                              set z_cancel=Y
        )
      )
    
      if /i "!z_cancel!"=="y" (
        call :log "......cancelling job..."
        "!z_bpdbjobs!" -cancel !z_job_jobid! >>"!z_file_log!" 2>&1
        set z_sts=!errorlevel!
        if !z_sts!==0 (
          call :log "......job cancelled ok..."
          set /a z_backups_cancelled+=1
        ) else (
          call :log "......failed to cancel job, status `!z_sts!`, script continuing..."
        )
      )
    )
    
    call :log "...done..."
    
    call :log ""
    call :log "Totals..."
    call :log "...job records found:    !z_job_records!"
    call :log "...backups unfinished:   !z_backups_unfinished!"
    call :log "...backups cancelled:    !z_backups_cancelled!"
    call :log "...done..."
    
    :end
    call :log ""
    call :log "Script exiting..."
    exit /b
    
    :log
    (echo !date! !time:~0,8!  %~1)
    (echo !date! !time:~0,8!  %~1)>>"!z_file_log!"
    goto :eof
  • And I agree with everyone else.  There really should be no need to run this... well, certainly not for production backups.

    But I guess if you have a big development / test server, which you'd like to get backups for if you can, but you're not worried if they fail or are cancelled, but where the backups must not be running during the day - then I guess there is a use case for a script like this.

    Use entirely at your own risk.  The script is furnished as an example only, and may not be suitable for your environment.  The recommendation is to not run it.

    The script is not endorsed by Symantec.

    .

    Instead - why not just suspend the backup?  And restart it again later?  If you want, I could try to modify the script to accept a parameter and get it to either suspend backups, or resume them.  This way you could schedule a task at 06:00 to suspend the backups, and then schedule another task to resume them later on in the evening.  I'm not entirely 100% sure that it is possible, but if you would like a script to try that...

    ...then post another new thread / question here on the forum - and I'll try to write something to do a suspend/resume for you.