Removing VMware Snapshots – With a Bat (PowerShell, CLI, rCLI… and Perl)

by bunchc on January 19, 2009

I’ve found a few situations in which snapshots get stuck, like glue, to a running VM, and despite your best effort to delete them, they wont go away. Like in-laws, they stick around, a bit longer than is pleasant.

If a snapshot has not been removed cleanly on the first try, you may want to create a new snapshot first (just to make sure the system knows there IS a snapshot present) before using the methods below.

Here are a few ways of getting rid of the ones that don’t want to go away:

From the Service Console (ESX)

[root@esx esx:storage1]# vmware-cmd ./VMname/VMname.vmx removesnapshots
removesnapshots() = 1

From PowerShell

PS C:\> get-vm VMname* | get-snapshot | Remove-Snapshot -Confirm:$false

Using the rCLI

C:\Program Files\VMware\VMware VI Remote CLI\bin>vmware-cmd.pl -H esx -U root –P  password /vmfs/volumes/esx:storage1/VMname/VMname.vmx removesnapshots
removesnapshot () = 1

Using the Perl Toolkit

This brought to us by Andrew, an avid Perl Toolkit user:
./snapshotmanager.pl –server your.vc.host –operation removeall –vmname some.bad.vm

Warning, depending on the size of the snapshot, it may take a LONG while for them to go away! You can get an idea of how long it’s going to take by looking at how large the snapshots are with ls -lh and note the size of your largest snapshots. They bigger than a few deciGig (for those who don’t get it, that’s a few tens of Gigs, 10G-20G)? Shame on you.

  • Nice..too technical for me...I am having some problem...I will ask my friend to take a look at this..
  • Some snapshots made my host ran out of space. However, with the bat you gave, the problem was resolved. Thank you for a bat. LoL.
  • No problem!
  • Thanks for that!
  • Awesome! Thanks for sharing!
  • please change the back ground its really hard to read
  • Hey there, thanks for the information on this, you have been a great source for me, I am really very happy to have you in the list of bookmarks I have!

    Debra
  • Hey. No problem. Thank you!
  • Some good points raised in that post. Will be back to check for more.
  • Same here. It has definitely eased my mind on the bugging problem of stuck snapshots!
  • No worries. Thanks!
  • Cody,

    If you have the Perl Toolkit installed, you can also use "snapshotmanager.pl"...

    ./snapshotmanager.pl --server your.vc.host --operation removeall --vmname some.bad.vm

    http://www.vmware.com/support/developer/viperlt...

    Andrew
  • Thanks for that Andrew, post updated to reflect this as well. Now I need to
    pickup perl and add it to the arsenal as well... WEE!
blog comments powered by Disqus

Previous post:

Next post: