PowerShell script exchange
Post Reply
electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » 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?

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » 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?

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

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

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » 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?

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

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

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » Apr 30, 2015 12:22 pm

That one doesn't seem to return any results

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

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

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » Apr 30, 2015 12:31 pm

Yep, that works now! Thanks!

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » Apr 30, 2015 12:32 pm

You're welcome. Should other help be needed, don't hesitate to let me know. Thanks.

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » 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: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » May 05, 2015 1:39 pm

Anyone? Just trying to get these values into a string so I can input them into a database.

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » May 06, 2015 2:16 pm

What if instead of using select, you will put just a dot into use:

Code: Select all

(Get-VBRRestorePoint -name "$VM" | sort creationtime -Descending | select -first 1).FindSourceJob().name
Otherwise, you can subtract the unnecessary information, working with substring method.

Thanks.

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » May 06, 2015 7:24 pm

Yea that worked. Thanks

electricd7
Expert
Posts: 117
Liked: 7 times
Joined: Mar 27, 2012 10:13 pm
Full Name: Chad Killion
Contact:

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

Post by electricd7 » May 07, 2015 12:45 pm

Almost have this just how I want it. It is still returning instances of copy jobs. I think I can eliminate those if I can just exclude any job who's name includes the word "Copy" in it as I have named all the copy jobs that way. The query I am currently using is:

(Get-VBRRestorePoint -name "$VM" | sort creationtime -Descending | select -first 1).FindSourceJob().name

So I just need one more entry where I can deslect anything in the -name field which has the word "Copy" in it.

veremin
Product Manager
Posts: 17151
Liked: 1485 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

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

Post by veremin » May 07, 2015 4:05 pm

You can put into use the example that I've shown you previously; the one using JobType parameter:

Code: Select all

(Get-VBRRestorePoint -name "VM Name" | where {$_.FindSourceJob().JobType -eq "Backup"} | sort creationtime -Descending | select -first 1).FindSourceJob().name 
I'm currently out of the office, thus, typos and code inconsistencies are expected.

Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests