Bulk VMware Snapshot Management/Removal with PowerCLI

16
Oct 2011

Bulk VMware Snapshot Management/Removal with PowerCLI

comment icon3 comment(s) |

We utilize Veeam's Backup & Replication product for local backups as well as offsite DR replication. The software is overall very good, but can have some quirks if things don't go as planned. One issue we hit is longer-running replica jobs might conflict with local jobs, causing jobs to fail, and snapshots to get locked and abandoned. Also, at times, we run into the Consolidate Helper snapshots when the ESX host is too busy, or hits another issue.
These conditions should get much better with Veeam 6 and vSphere 5, but we even had a new one pop up seemingly at random. 

Failed to retrieve "SCSI (0:1) Hard disk 2" disk information. Check VM virtual hardware configuration. 
Cannot create CSoapPath from ssh path '/vmfs/volumes/guid/machine.vmdk'. Veeam Backup will attempt to remove snapshot during the next job cycle, but you may consider removing snapshot manually. Possible causes for snapshot removal failure: - Network connectivity issue, or vCenter Server is too busy to serve the request - ESX host was unable to process snapshot removal request in a timely manner - Snapshot was already removed by another application

This is caused by a last minute change by VMware with the RTM vSphere 5 release, and Veeam is hurriedly working on an update to address the problem. The backups are working, but Veeam is unable to properly remove them for most of the VMs in the backup jobs.
Working with the vSphere Client is pretty cumbersome and clunky when trying to rapidly check machines for certain states, and in my case, are old-running snapshots. This is where I pull out the vSphere PowerCLI, a free download from VMware.

Fire up the PowerCLI powershell prompt, and start with a simple connection: 

 connect-viserver vCenterServer

Name                           Port  User
----                           ----  ----
vCenterServer                  443   domain\user

Next, use the following command to list out the current snapshots for all machines:

 get-snapshot -vm * | select VM, Name, SizeMB, @{Name="Age";Expression={((Get-Date)-$_.Created).Days}}

In my instance, I had several starting that needed to be removed starting with "VEEAM BACKUP". After ensuring all Veeam B&R jobs were idle, I ran first for verification:

 Get-Snapshot -vm * -name "VEEAM BACKUP*"

Finally, the removal command:

 Get-Snapshot -vm * -name "VEEAM BACKUP*" | remove-snapshot

Confirm
Are you sure you want to perform this action?
Performing operation "Removing snapshot." on Target"VirtualMachineSnapshot-snapshot-3979".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help(default is "Y"):A

At that point you'll receive the typical PowerShell progress bar to indicate performance, and you'll see the operations executing in your vSphere Client.
There are plenty of operations that can be performed with the PowerCLI, just figured I'd share one that's useful and relevant right now.

Comments

March 23, 2012

Keith Tademy

Veeam Failure

This is exactly what I needed to fix my issue. Thanks!

February 24, 2013

Biswajit Mukherji

This fixed my issue.

This fixed my issue.

June 4, 2014

Steve Carroll

Just what I was looking for.

Just what I was looking for. Thank you!

Search