How would I query backups for the existence of a server?

PowerShell script exchange

How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Mon Apr 27, 2015 1:27 pm

I would like a powershell function that would query the current backups on disk in the Veeam database for a specific guest name. So I could pass a servername and it would return a job name that holds that guest. Is there an easy way to accomplish this using built-in veeam powershell functions?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Mon Apr 27, 2015 2:07 pm

Try this example:

Code: Select all
Get-VBRJob | where {$_.GetObjectsInJob().name -eq "Name of your VM"} | select name

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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Tue Apr 28, 2015 6:08 pm

That is on the right track. It returns no jobs unless the VM I pass is specifically included in a selection list. Most times I run backup jobs based on datastores. Also it returns a job where the machine I am passing it is in the exclusion list and not the selection list. Is there a way to make it only return name if the machine is in the "backed up" resources portion of the job?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Wed Apr 29, 2015 9:39 am

What about this one:

Code: Select all
Get-VBRJob | where {$_.GetViOijs().name -eq "VM Name" -and $_.GetViOijs().Type -eq "Include"} | select name


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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Wed Apr 29, 2015 12:58 pm

This seems to work the same way as the other (though slower.) I would think maybe I would have to query restore-points in order to find out what VMs were covered by the jobs, since they are done by data-store or by folder. I only say this because I can expand a restore to list out all the VMs that are contained, but can't see anything based on just the job other than the folder or datastore.
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Wed Apr 29, 2015 1:18 pm

The example provided above should care only of selection scope, paying no attention to exclusions list. If you want to work with restore points, something like this should be helpful:

Code: Select all
Get-VBRRestorePoint -name "Name of VM" | select {$_.FindSourceJob().name} | Get-Unique


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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Wed Apr 29, 2015 1:24 pm

There we go. So now I can pass a VM name to the one-liner and it will return the job which holds a backup for that VM. Is there an easy way to use that data to query for the most recent restore-point for that particular VM?
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Wed Apr 29, 2015 2:14 pm

You can sort the resulting restore points, using CreationTime parameter:

Code: Select all
Get-VBRRestorePoint -name "VM Name" | sort creationtime -Descending | select -first 1 | select {$_.FindSourceJob().name}


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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Wed Apr 29, 2015 7:30 pm

OK great! Final question (i think). How would I exclude copy-jobs from the search? All of my copy jobs contain the word "Copy" in them, but I only want to return local backup jobs and not necessarily the copy jobs related to those backup jobs. Thanks again.
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Thu Apr 30, 2015 6:32 am

I'm currently at the office, and don't have console at hand, but feel free to try the following example and see whether it meets your requirements:

Code: Select all
Get-VBRRestorePoint -name "VM Name" | where {$_.FindSourceJob().Type -eq "Backup"} | sort creationtime -Descending | select -first 1 | select {$_.FindSourceJob().name}


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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Thu Apr 30, 2015 12:22 pm

That one doesn't seem to return any results
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Thu Apr 30, 2015 12:27 pm

I think you should replace Type parameter with with JobType one:

Code: Select all
Get-VBRRestorePoint -name "VM Name" | where {$_.FindSourceJob().JobType -eq "Backup"} | sort creationtime -Descending | select -first 1 | select {$_.FindSourceJob().name}


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

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Thu Apr 30, 2015 12:31 pm

Yep, that works now! Thanks!
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Re: How would I query backups for the existence of a server?

Veeam Logoby v.Eremin » Thu Apr 30, 2015 12:32 pm

You're welcome. Should other help be needed, don't hesitate to let me know. Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: How would I query backups for the existence of a server?

Veeam Logoby electricd7 » Thu Apr 30, 2015 2:45 pm

Maybe a silly question but I have the following in my script:

$JobName = Get-VBRRestorePoint -name "$VM" | sort creationtime -Descending | select -first 1 | select {$_.FindSourceJob().name}

Then when I go to insert $JobName in a DB, it inserts "@{$_.FindSourceJob().name=vmds_nas9}" instead of just "vmds_nas9" as I would have expected. How do I just get the JobName without the other garbage? Thanks!
electricd7
Expert
 
Posts: 103
Liked: 5 times
Joined: Tue Mar 27, 2012 10:13 pm
Full Name: Chad Killion

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests