Hi,
We are using vCenter 6.0 on a Windows Server.
My manager prefers to create VM snapshots before applying Windows Update.
Just would like to know is there any script that can be used to meet this need ?
As I have no previous experience with CLI commands, would it be PowerCLI ?
May I ask how many snapshots can be taken at the same time ? Is there a limit ? What is the bottleneck (ESXi Host or VMFS DataStore) ?
If we schedule to run the script (I believe it will be a Batch File), can it be scheduled task on the Windows Server running vCenter ?
Thanking you in anticipation.
PowerCLI would definitely be a good candidate to automate this through a script.
The New-Snapshot cmdlet is what you would be using.
That cmdlet has the RunAsync switch, meaning you start the snapshot in the background, while your script continues.
How many snapshots you can take in parallel depends on your environment.
It's something that testing and experience should be able to tell you.
On the scheduling part, you can use a vCenter scheduled task or you can use the Windows Task Scheduler.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Moderator: Moved to PowerCLI
PowerCLI would definitely be a good candidate to automate this through a script.
The New-Snapshot cmdlet is what you would be using.
That cmdlet has the RunAsync switch, meaning you start the snapshot in the background, while your script continues.
How many snapshots you can take in parallel depends on your environment.
It's something that testing and experience should be able to tell you.
On the scheduling part, you can use a vCenter scheduled task or you can use the Windows Task Scheduler.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD,
Thanks for your advice.
You mention that if we use the RunAsync switch, we can start the snapshot in the background, while your script continues. As the script is for creating snapshots for all VMs, do you mean the snapshot for VM1 will be started in background while we can go to next statement for creating snapshot for VM2 ?
Thanks
Yes, exactly that.
You probably will have to have some kind of queueing in place, this to avoid a potential critical load on your environment.
There are several examples of how to do that available in this forum.
Basically you would use the Get-Task cmdlet to check how many snapshots are active before starting new ones.
See this Remove-Snapshot example to seethe concept.
Re: Deleting snapshots with wait
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD,
Many thanks for your advice again.
From the "Remove-Snapshot" example, it appears that we need to determine the number of maximum job. May I ask what factors we need to consider the maximum number of jobs to be used ?
We have been using vRanger / Veeam Backup, we usually set to 8 concurrent jobs. Are they the same consideration ?
Besides, for creating snapshot, the script will be something like the following ?
$maxJobs = 5
Get-VM | Get-Snapshot |
ForEach-Object -Process {
New-Snapshot -Snapshot $_ -Confirm:$false -RunAsync
$current = Get-Task | where {$_.Name -eq 'NewSnapshot_Task' -and 'Running','Queued' -contains $_.State}
while ($current.count -gt $maxJobs) {
sleep 5
$current = Get-Task | where {$_.Name -eq 'NewSnapshot_Task' -and 'Running','Queued' -contains $_.State}
}
Thanks again.
It's a bit of a trial-and-error game, but 8 parallel background jobs would be a good starting point in that case.
There are so many factors to take into account (which ESXi node, which datastore, which VLAN, current load of the VM, ....) that it is probably sheer impossible to exactly calculate a number.
At least that is my opinion and experience.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And yes, that script is a good starting point
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD,
Many thanks for your advice.
You have mentioned that "There are several examples of how to do that available in this forum". However, I am not able to find them.
Could it be possible for you to give me the URL so that I can look into them ?
Thanks again,
While all the examples are not explicitly for creating new snapshots, they do explain and show to use the RunAsync switch.
See for example
Re: Invoke-VMScript Parallel cmdlets on multiple vms at one go
Re: limit vMotion operations by Hosts?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Since we are using VMware vSphere 6.0, may I ask which version of PowerCLI should I download & use ?
Thanks again
You can use the compatibility matrix for that.
In this case, vSphere 6.*, you can safely use the latest PowerCLI version (11.5.0).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Dear LucD,
Many thanks for your advice - Compability Matrix for PowerCLI.
Cheers