Powershell: Cancel Backup to tape job

PowerShell script exchange

Powershell: Cancel Backup to tape job

Veeam Logoby patboy29 » Fri Jan 31, 2014 5:28 pm

Hi,
I am looking to write a Powershell script to cancel a Backup to tape jobs when the status is waiting for a tape. The problem is there are no configurable backup window in the GUI for the backup to tape. So when a tape is not present on a standalone drive, the job will never be canceled and the other B2T jobs are overlapped.

I wrote this script but it's not working. I think the GET-VBRTapeJob is not returning the state of a running backup to tape jobs. Could someone know how to get the status of a backup to tape job ?

-----------------------
Add-PSSnapin VeeamPSSnapin
$job = Get-VBRTapeJob | Where-Object {$_.State -like "WaitingTape"}
Stop-VBRJob $job
----------------------
patboy29
Influencer
 
Posts: 10
Liked: never
Joined: Wed Oct 12, 2011 1:56 pm

Re: Powershell: Cancel Backup to tape job

Veeam Logoby Vitaliy S. » Sun Feb 02, 2014 1:54 pm

Hello,

Have you had a chance to try this solution to report on the job state > Scheduled task to report on running backup jobs? That topic describes how to do that for regular jobs, but I assume the same parameters can be used for tape jobs as well.

Thanks!
Vitaliy S.
Veeam Software
 
Posts: 19558
Liked: 1102 times
Joined: Mon Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Mon Feb 03, 2014 10:05 am

Yes, the job latest state can be gotten via .GetLastState() method. However, I'm not sure whether the corresponding information ("waiting for new tape") is reflected in this field. I don't have time to test it at the moment, so, you can do it yourself and see what particular status the tape job waiting for new tape has.

If the said method doesn't help, you will be able to get what you're after, using .logger parameter of backup session. Logger parameter allows you to see the exact information that is shown in the "action" pane.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell: Cancel Backup to tape job

Veeam Logoby patboy29 » Mon Feb 03, 2014 3:35 pm

Yes, it working now. Here's the script:

Code: Select all
Add-PSSnapin VeeamPSSnapin
$jobs = Get-VBRTapeJob
foreach($jobtoshow in $jobs)
{
   if ($jobtoshow.GetLastState() -like "WaitingTape")
   {
      Stop-VBRJob $jobtoshow.name  –runasync -Confirm:$false
   }
}


Thanks for your help!
patboy29
Influencer
 
Posts: 10
Liked: never
Joined: Wed Oct 12, 2011 1:56 pm

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Mon Feb 03, 2014 3:38 pm

I believe the script can be optimized even further, so that, it becomes an one-liner:

Code: Select all
Get-VBRTapeJob | ? {$_.GetLastState() -like "WaitingTape"} | Stop-VBRJob

Hope this helps.
Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell: Cancel Backup to tape job

Veeam Logoby horst » Tue Apr 15, 2014 7:24 am

hi, I`m also facing the problem with the pending backup to tape jobs, when the customer forgott to change the tape.
Could you shortly explain, how the script is used?

Do I have to create a windows task with this script that automatically runs after the start of the veaam copy to tape job?


thanks for help
horst
Enthusiast
 
Posts: 38
Liked: 4 times
Joined: Tue Aug 27, 2013 6:55 am
Location: GER

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Tue Apr 15, 2014 8:37 am

Yes, you can schedule the said script via Windows Scheduler to run some time after the tape job is executed. The script will find and stop those tape jobs that are sitting and waiting for a new tape.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell: Cancel Backup to tape job

Veeam Logoby horst » Wed Apr 23, 2014 9:28 am

The task with the script works quite well!

Thank you very much!
horst
Enthusiast
 
Posts: 38
Liked: 4 times
Joined: Tue Aug 27, 2013 6:55 am
Location: GER

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Wed Apr 23, 2014 9:37 am

Glad to hear my input was helpful. Let me know, should other help be needed.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell: Cancel Backup to tape job

Veeam Logoby horst » Wed Jul 01, 2015 6:13 am

sadly since upgrading to B&R v.8 the script doesn`t work anymore :(
any hints for me to fix this again?


Thanks

edit: I found another thread: powershell-f26/how-can-determine-tape-waiting-jobs-with-veeam-8-t25450.html

can I fix my problem with something like this?!

Get-VBRTapeJob | where {$_.LastState -eq "WaitingTape"} | Stop-VBRJob
horst
Enthusiast
 
Posts: 38
Liked: 4 times
Joined: Tue Aug 27, 2013 6:55 am
Location: GER

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Wed Jul 01, 2015 10:21 am

Yes, but make sure to upgrade your installation to the latest product version first, as issues with LastState, LastResult showing incorrect values have been fixed there.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Powershell: Cancel Backup to tape job

Veeam Logoby resruss » Mon Jul 13, 2015 1:39 am

Looking at switching a client using Veeam 8 from BackupExec to Veeam for the tape component.
Is this PowerShell script still required, or is there an option within Veeam itself to wait only 30 minutes for a tape then cancel the job for example?
resruss
Service Provider
 
Posts: 55
Liked: 6 times
Joined: Mon Apr 30, 2012 2:04 am

Re: Powershell: Cancel Backup to tape job

Veeam Logoby v.Eremin » Mon Jul 13, 2015 12:24 pm

v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests