Script to remove VMWare snapshots

snapshotvirtualizationvmware-esxi

I'd like to centrally remove all non-active snapshots on a vMA host before performing central backups of VMs. I am hoping such a script exists already??? Anyone know of one?

Edit:

Here is a script using basic vMA tools to do the job:

#!/bin/bash
#
# Purpose: List all snapshots for registered and powered-on VMs found on those
#          ESXi hosts listed as VI Fastpass targets (vifptarget -l).
#
# Author: Ryan Bowlby


# VIFP ESXi hosts
esxi_hosts=$( /usr/bin/vifp listservers | awk '$2 ~ /ESXi/ { print $1 }' )

# Have to specify an esxi target before the "--server" opt works.
# http://www.virtuallyghetto.com/2011/01/how-to-automate-cron-vi-fastpass.html
first_esxi=$( echo $esxi_hosts | awk '{print $1}' )
source /opt/vmware/vma/bin/vifptarget -s $first_esxi > /dev/null 2>&1

for host in $esxi_hosts; do
   reg_vms=$( /usr/bin/vmware-cmd --server $host -l 2>/dev/null)
   for vm in $reg_vms; do
      if /usr/bin/vmware-cmd --server $host $vm getstate | grep -q 'getstate() = on'; then
         # print VM name (everything after last /) aka vm.split('/')[-1] ;)
         vm_name="`echo $(basename $vm) | sed 's/\.vmx$//g'`"
         #vm_name=$( IFS='/'; for elem in $vm; do echo $elem; done | tail -1 | sed 's/\.vmx$//g' )
         echo $vm_name
         if /usr/bin/vmware-cmd --server $host $vm hassnapshot | grep -q "1"; then
            echo $vm_name has a snapshot, removing...
            /usr/bin/vmware-cmd --server $host $vm removesnapshots
         fi
      fi
   done
done

Best Answer

I'm not aware of a whole script to do it but page 39 of THIS VMWare SDK document shows you how to create them using vmsnapshot.pl and snapshotmanager.pl - so I'm sure you could look at these scripts (it's too late here to do that) and see what options there are.

Obviously these are supported in your vMA.

Edit - the command you want is RemoveSnapshot_Task found HERE.