-
- Enthusiast
- Posts: 39
- Liked: never
- Joined: Dec 09, 2010 1:25 pm
- Full Name: Corey
- Contact:
Query Job Completion
Is there any way to query if a backup job has completed from the command line? I think I can use PowerShell? Maybe I'm blind (high possibility), but I can't seem to locate the white papers for this...
Basically I would like to build a script which runs near the end of the backup window. It will query all Veeam Backup jobs one by one and output if they are completed or not. If they are not, the script will sleep for 15 minutes. If the jobs are complete the script will execute another command.
This will be used to kick off our HP Data Protector software to backup our repositories to tape. I have the white paper which was introduced a few years ago but unfortunately it does not fit my needs.
Basically I would like to build a script which runs near the end of the backup window. It will query all Veeam Backup jobs one by one and output if they are completed or not. If they are not, the script will sleep for 15 minutes. If the jobs are complete the script will execute another command.
This will be used to kick off our HP Data Protector software to backup our repositories to tape. I have the white paper which was introduced a few years ago but unfortunately it does not fit my needs.
-
- Chief Product Officer
- Posts: 31812
- Liked: 7302 times
- Joined: Jan 01, 2006 1:01 am
- Location: Baar, Switzerland
- Contact:
Re: Query Job Completion
Sure, please check the PowerShell subforum.
-
- Veeam Software
- Posts: 21139
- Liked: 2141 times
- Joined: Jul 11, 2011 10:22 am
- Full Name: Alexander Fogelson
- Contact:
Re: Query Job Completion
Corey, you can use this script to monitor current job status. Thanks.
-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: Query Job Completion
In powershell you can do the following:
v6
v5
v6
Code: Select all
$job = Get-VBRJob -name "Jobname"
$job.GetLastState()
Code: Select all
$job = Get-VBRJob | ?{$_.name -eq "Job Name"}
$job.GetLastState()
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
-
- Enthusiast
- Posts: 39
- Liked: never
- Joined: Dec 09, 2010 1:25 pm
- Full Name: Corey
- Contact:
Re: Query Job Completion
You guys rock. I was looking for white papers and then I must have mistypes something in the forum search box, because I just tried again and found dozens of posts. Thanks!!!
-
- Enthusiast
- Posts: 39
- Liked: never
- Joined: Dec 09, 2010 1:25 pm
- Full Name: Corey
- Contact:
Re: Query Job Completion
This script appears to query all jobs and continue runing until all jobs are stopped - am I correct? The big issue with this is it seems to take replica's into account as well. Is there a way to only query backup jobs? I tried -BackupTargetType but that didn't do the trick.
Just so you know, I'm extremely new to PowerShell. I'm making the transition from VBScript (yeah yeah, I know... I'm behind the times...)
Just so you know, I'm extremely new to PowerShell. I'm making the transition from VBScript (yeah yeah, I know... I'm behind the times...)
Code: Select all
Add-PSSnapin Veeampssnapin
$JobActive=0
Do {
foreach ($v in (Get-VBRJob))
{
$JobStatus = ($v.GetLastState())
If ($JobStatus -notlike "Stopped"){$JobActive ++}
}}
while($JobActive -notlike "0")
#Insert backup command here
-
- Veteran
- Posts: 293
- Liked: 19 times
- Joined: Apr 13, 2011 12:45 pm
- Full Name: Thomas McConnell
- Contact:
Re: Query Job Completion
Change your Get-VBRJob to this
Code: Select all
Get-VBRJob | ?{$_.IsBackup -eq $true}
-
- Enthusiast
- Posts: 39
- Liked: never
- Joined: Dec 09, 2010 1:25 pm
- Full Name: Corey
- Contact:
Re: Query Job Completion
I added some Write-Host entries to help with troubleshooting. I ran the script below while a backup job was running. While the job is running the script outputs "Working 0" then "Working 1" and then "Working 2" and so on. I then stopped the backup job to see if the script would output "Run Script!". The job was stopped for 15 minutes and the script never stopped or outputted "Run Script!". Did I screw something up?
Code: Select all
Add-PSSnapin -Name Veeampssnapin -ErrorAction SilentlyContinue
$JobActive=0
Do {
foreach ($v in (Get-VBRJob | ?{$_.IsBackup -eq $true}))
{
$JobStatus = ($v.GetLastState())
If ($JobStatus -notlike "Stopped"){
Write-Host $JobStatus $JobActive
$JobActive ++
}
}}
while($JobActive -notlike "0")
#Insert backup command here
Write-Host "Run Script!"
-
- Veteran
- Posts: 282
- Liked: 26 times
- Joined: Nov 10, 2010 6:51 pm
- Full Name: Seth Bartlett
- Contact:
Re: Query Job Completion
You never decrement JobActive. So when it gets set to stopped, you do not --
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
-
- Influencer
- Posts: 10
- Liked: never
- Joined: Mar 28, 2011 2:13 pm
- Full Name: Justin Teager
- Contact:
Re: Query Job Completion
So wait, are you trying to do like a "post-all-my-jobs" command? If so, you could probably just do something like
Does that make sense?
Code: Select all
asnp VeeamPSSnapin -ErrorAction SilentlyContinue
while(get-vbrjob | ?{$_.IsBackup -and $_.GetLastState() -notlike "Stopped"}){
sleep(10) # That value is in seconds -- this is so it doesn't tank your box :)
}
write-host "This is only printing if no jobs are running"
-
- Veteran
- Posts: 293
- Liked: 19 times
- Joined: Apr 13, 2011 12:45 pm
- Full Name: Thomas McConnell
- Contact:
Re: Query Job Completion
Nicely done JT
-
- Enthusiast
- Posts: 39
- Liked: never
- Joined: Dec 09, 2010 1:25 pm
- Full Name: Corey
- Contact:
Re: Query Job Completion
Nice! Thanks! I'm so far behind when it comes to PoweShell
So basically what I'm going to do is kick off the script at midnight every night. It will cotninue to run and check every X amount of seconds to see if a job is running (I'll probably change this to every 10 minutes or something). When the jobs are all stopped, it will kick off a command to run an on-demand HP Data Protector job which will send our entire backup repository to tape.
So basically what I'm going to do is kick off the script at midnight every night. It will cotninue to run and check every X amount of seconds to see if a job is running (I'll probably change this to every 10 minutes or something). When the jobs are all stopped, it will kick off a command to run an on-demand HP Data Protector job which will send our entire backup repository to tape.
-
- Influencer
- Posts: 11
- Liked: never
- Joined: Jul 23, 2011 6:23 am
- Full Name: David Lee
- Contact:
Re: Query Job Completion
Have you considered using a post job activity on the backup which runs last in your backup set ?
We do this for any of our customers who are looking to use a backup to tape solution for their Veeam Data and have found it to be very reliable and compatible with pretty much any backup system which has some level of PowerShell Interaction support.
Provided you can write a PowerShell script or similar to initiate the backup on your tape backup system you can simply define a script to run when the final Veeam job completes.
By using a script to first output whether jobs are running and then having another script check the output is a less than optimal method to do what your trying to achieve imho
In Veeam v6 you can define the Post Job Script to only run on a specific day so if your only doing this on a weekend for example you don't need to add a check into the script to find out what day it is before executing you can just define the schedule within the Veeam Job.
Obviously everyones situation is different and it may be hard to define which backup will complete last in a given backup window for some but for many standard re-occurring schedules I have found the post job activity feature to be a very reliable method to get Veeam data written to tape.
We do this for any of our customers who are looking to use a backup to tape solution for their Veeam Data and have found it to be very reliable and compatible with pretty much any backup system which has some level of PowerShell Interaction support.
Provided you can write a PowerShell script or similar to initiate the backup on your tape backup system you can simply define a script to run when the final Veeam job completes.
By using a script to first output whether jobs are running and then having another script check the output is a less than optimal method to do what your trying to achieve imho
In Veeam v6 you can define the Post Job Script to only run on a specific day so if your only doing this on a weekend for example you don't need to add a check into the script to find out what day it is before executing you can just define the schedule within the Veeam Job.
Obviously everyones situation is different and it may be hard to define which backup will complete last in a given backup window for some but for many standard re-occurring schedules I have found the post job activity feature to be a very reliable method to get Veeam data written to tape.
Who is online
Users browsing this forum: No registered users and 14 guests