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

Powershell: Cancel Backup to tape job

Post by patboy29 » 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
----------------------

Vitaliy S.
Product Manager
Posts: 22431
Liked: 1442 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Powershell: Cancel Backup to tape job

Post by Vitaliy S. » 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!

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » 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.

patboy29
Service Provider
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 » 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!

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » 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.

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 » 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

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » 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.

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 » Apr 23, 2014 9:28 am

The task with the script works quite well!

Thank you very much!

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » Apr 23, 2014 9:37 am

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 » 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: 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

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » 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.

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 » 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?

v.eremin
Product Manager
Posts: 16192
Liked: 1322 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Powershell: Cancel Backup to tape job

Post by v.eremin » Jul 13, 2015 12:24 pm


Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests