PowerShell script exchange
Post Reply
patboy29
Influencer
Posts: 10
Liked: never
Joined: Oct 12, 2011 1:56 pm
Full Name: Patrick
Contact:

Powershell: Cancel Backup to tape job

Post by patboy29 »

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
----------------------
Vitaliy S.
VP, Product Management
Posts: 27377
Liked: 2800 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Powershell: Cancel Backup to tape job

Post by Vitaliy S. »

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!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

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.
patboy29
Influencer
Posts: 10
Liked: never
Joined: Oct 12, 2011 1:56 pm
Full Name: Patrick
Contact:

Re: Powershell: Cancel Backup to tape job

Post by patboy29 »

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!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

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.
horst
Enthusiast
Posts: 38
Liked: 4 times
Joined: Aug 27, 2013 6:55 am
Location: GER
Contact:

Re: Powershell: Cancel Backup to tape job

Post by horst »

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
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

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.
horst
Enthusiast
Posts: 38
Liked: 4 times
Joined: Aug 27, 2013 6:55 am
Location: GER
Contact:

Re: Powershell: Cancel Backup to tape job

Post by horst »

The task with the script works quite well!

Thank you very much!
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

Glad to hear my input was helpful. Let me know, should other help be needed.
horst
Enthusiast
Posts: 38
Liked: 4 times
Joined: Aug 27, 2013 6:55 am
Location: GER
Contact:

Re: Powershell: Cancel Backup to tape job

Post by horst »

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: http://forums.veeam.com/powershell-f26/ ... 25450.html

can I fix my problem with something like this?!
Get-VBRTapeJob | where {$_.LastState -eq "WaitingTape"} | Stop-VBRJob
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

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.
resruss
Service Provider
Posts: 56
Liked: 6 times
Joined: Apr 30, 2012 2:04 am
Contact:

Re: Powershell: Cancel Backup to tape job

Post by resruss »

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?
veremin
Product Manager
Posts: 20415
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by veremin »

Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 12 guests