Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question
    
I ended up creating a simple shell script to do this. Copied above. –  CarpeNoctem Oct 10 '11 at 23:15
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.