PowerShell script exchange
Post Reply
cell
Influencer
Posts: 10
Liked: 2 times
Joined: May 14, 2013 12:22 pm
Contact:

Start-VBRQuickBackup without Find-VBRViEntity

Post by cell »

Hi, i wonder if it would be possible to run Start-VBRQuickBackup -VM <IVmItem[]> without going through the process with Get-VBRServer | Find-VBRViEntity. it's very timeconsuming to search for the IVmItem on all the hosts if you got more than one.

Regards Tom
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRQuickBackup without Find-VBRViEntity

Post by veremin »

The process emulates GUI to some extent, so, I'm not sure how it might look differently: you go to virtual machine node -> select appropriate host (Get-VBRServer) -> find required VM (Find-VBRViEntity) -> start quick backup (Start-VBRQuickBackup).

In order to speed up the process you can try to provide Get-VBRServer with the name of a host the needed VM resides on, so that, the script won't query all hosts vCenter consists of.

Thanks.
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRQuickBackup without Find-VBRViEntity

Post by tsightler » 1 person likes this post

Calls to Find-VBRViEntity are fairly slow, so you want to limit them as much as possible. One of the simplest solutions, if you're sure you won't have duplicate VM names, is to make a single call at the start of the script to Find-VBRViEntity and load the resulting objects into a hash table like so:

Code: Select all

$vms = Find-VBRViEntity -VMsAndTemplates | Group-Object Name -AsHashTable
Now, you can instantly access the ViEntity object of any VM in the entire environment by name with this simple code:

Code: Select all

$vms.<vm_name>
So to do a quick backup would just be:

Code: Select all

Start-VBRQuickBackup -VM $vms.<vm_name>
If you do have a little more complex environment, especially in cases where there might be duplicate VM names in the environment, you might need to do something a little more complex, but the concept is the same, make on a single call to the long running cmdlets and load them into a variable (hash tables are great because of their speed to access individual objects).
cell
Influencer
Posts: 10
Liked: 2 times
Joined: May 14, 2013 12:22 pm
Contact:

Re: Start-VBRQuickBackup without Find-VBRViEntity

Post by cell »

Hi thanks.

if i understand this correctly, Find-VBRViEntity connects to the esx-host if i specify -Server and connects to all hots in veeam if i dont specify -Server. This is what i want to avoid if possible.
We got aprox 20 vcenters and the same amount of standalone hosts in the Infrastructure-> Vmware vsphere list. I was thinking that the value i need for Start-VBRQuickBackup could be found in veeam somewhere, etc get-vbrbackup or get-vbrjobobject and prepare the Find-VBRViEntity command without asking any hosts.


/ Tom
veremin
Product Manager
Posts: 20413
Liked: 2301 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Start-VBRQuickBackup without Find-VBRViEntity

Post by veremin »

The way you've written a script it indeed walks through all servers added to a backup console, finding all VMs present there. (Get-VBRServer | Find-VBRViEntity)

In order to improve performance, limit the scope first:

Code: Select all

$Server = Get-VBRServer -name "Name of particular server"
Then, use tricks proposed by Tom:

Code: Select all

$vms = Find-VBRViEntity -Server $Server -VMsAndTemplates | Group-Object Name -AsHashTable
Start-VBRQuickBackup -VM $vms.<vm_name>
Thanks.
tsightler
VP, Product Management
Posts: 6035
Liked: 2860 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Start-VBRQuickBackup without Find-VBRViEntity

Post by tsightler »

Perhaps I'm misunderstanding your use case, can you share a little more information about it? What information do you have available to perform the query? Server name and VM name perhaps? I mean, in all cases you'd have to have at least that to pass to Start-VBRQuickBackup, because there's no other way for it to know the specific VM.

When you said that it takes time to search for ViItem when you have more than one server it made me assume you only had a VM name and were then attempting to query each and every vc/host individually with Find-VBRViEntity, which would almost certainly take longer than just running Find-VBRViEntity without a server and grabbing everything (although perhaps not). We can't really work without the ViEntity because that's what the job uses to find the correct VM, but if you only have, for example, only the VM name, it should possible to query the job object first and use that to figure out which specific server it is on.

Maybe you can share some code to give us a better idea of what you are currently doing, and we can see if we can brainstorm a way to make it better. Another option might be to use the REST API instead of Powershell (or even call the REST API from Powershell) as it's quite a bit faster at this task.
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests