NetApp Snapshots in ESX – Take 2

Alright, well I finally set aside some time to sit and think about my script that runs my snapshots (VMware Snapshots then NetApp Snapshots then remove VMware Snapshot).   The problem with my current script is that if you have multiple VMware Snapshots they all get removed… which IMO maybe isn’t a bad thing (since your not suppose to keep snapshots for that long), but I can see in some environments it may not be a good thing.

So, thanks to a comment posted by Hajo Ehlers (no website or email address left), he made me think about using the VCB utilities built into ESX to remove a specific snapshot.  What is nice about the VCB utility is that you can get a SsId (Snapshot ID) for each snapshot created on the VM.  So after grabbing this SsId you can remove your snapshot with that ID (rather than removing all of them).

Here is the new script, as you can see the creation portion of the snapshot is the same.  I attempted to use the vcbSnapshot utility to create these, but I found on my SUSE 10 guests they would fail (pre-freeze script failure).  I’m not having this problem with the vim-cmd utility, so I will stick with it.

One thing you must know is that you can either pass the username and password for the VCB utility from the command-line or you can just put it in the /etc/vmware/backuptools.conf file. Also, just like with the original script I am assuming you have set up SSH authorized keys for your ESX hosts and your NetApp filer.

#!/bin/sh -x
#set path and date
DATE=`date +%m.%d.%G.%H%M`

echo “Creating VMware Snapshots”
#create local host snapshot
for i in `vmware-vim-cmd vmsvc/getallvms | sed ‘1d’ | awk ‘{print $1}’`
vmware-vim-cmd vmsvc/snapshot.create $i Nightly Netapp.Snapshot.$DATE

#create remote host snapshot
for i in `ssh
<esx-host> vmware-vim-cmd vmsvc/getallvms | sed ‘1d’ | awk ‘{print $1}’`
ssh <esx-host> vmware-vim-cmd vmsvc/snapshot.create $i Nightly Netapp.Snapshot.$DATE

#this schedule is ran nightly so effectively I have 8 days work of nightly backups
echo “Creating NetApp snapshots”
ssh <netapp-host> snap delete vol154 vmsnap.9
<netapp-host> snap rename vol154 vmsnap.8 vmsnap.9
<netapp-host> snap rename vol154 vmsnap.7 vmsnap.8
<netapp-host> snap rename vol154 vmsnap.6 vmsnap.7
<netapp-host> snap rename vol154 vmsnap.5 vmsnap.6
<netapp-host> snap rename vol154 vmsnap.4 vmsnap.5
<netapp-host> snap rename vol154 vmsnap.3 vmsnap.4
<netapp-host> snap rename vol154 vmsnap.2 vmsnap.3
<netapp-host> snap rename vol154 vmsnap.1 vmsnap.2
<netapp-host> snap create vol154 vmsnap.1

echo “Removing VMware Snapshots”
for i in `vcbVmName -h localhost -s Any:* | grep moref`
#the above command grabs the MoRef ID for each Virtual Machine
for p in `vcbSnapshot -h localhost -f $i Nightly |grep SsId`
#the above command grabs the SsId for each snapshot named Nightly on every Virtual Machine
vcbSnapshot -h localhost -d $i $p
#the above command removes the SsId from the MoRef ID

for i in `ssh <esx-server> vcbVmName -h localhost -s Any:* | grep moref`
for p in `ssh
<esx-server> vcbSnapshot -h localhost -f $i Nightly |grep SsId`
<esx-server> vcbSnapshot -h localhost -d $i $p

Created on December 5, 2008 by Rick Scherer

Posted under Backup & Recovery, ESX 3.5 Tips, NetApp, Storage, VMware.

This blog has 14,066 views.

Tags: , , , , ,

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.00 out of 5)

15 Comments so far

  1. William
    12:07 pm on December 5th, 2008


    I was wondering is removing the snapshot from the VM is any more efficient using the VCB tools than say “vmware-cmd” or “vmware-vim-cmd”?

    I’ve written a script that backups Virtual Machines similar to how VMware VCB does it, thought you might be interested. You can definitely centralize the backup process and have this script be executed on a local system and utilizing SSH keys to connect multiple ESX/ESXi Servers. You can probably integrate that in with your NetApp code.

  2. Rick Scherer
    12:41 pm on December 5th, 2008

    Well actually the first version of my script I used vmware-cmd, then revised to vmware-vim-cmd — what I found is that there is no way to selectively choose exactly what VMware snapshot you want to remove, thus it removes ALL snapshots — which could be annoying if you did not want that to happen.

    Whats nice about the vcb tools is that you have the granularity to selectively choose exactly what snapshot you want to remove, thus making it possible for a VM to have multiple snapshots, yet still back it up and only remove the snapshot you created for the backup (and not all of them).

  3. William
    1:04 pm on December 5th, 2008

    I think it’s possible to specify which Snapshot to remove using “vmware-vim-cmd” but you’ll need to pull out the ID for a given Snapshot name. Good to know

  4. Rick Scherer
    2:32 pm on December 5th, 2008

    The ‘vmware-vim-cmd vmsvc/snapshot.get’ command does not give me a clear answer to what the SsId would be (or any form of identification for that matter).

    The vmware-cmd command does not give you an option to selectively remove, it just removes everything.

    The VCB utilities seem a lot more flexible and easier to use.

  5. isi
    5:53 am on January 27th, 2009

    your skript does not work, if there are long comments in the guests annotations field.

  6. Rick Scherer
    7:28 am on January 28th, 2009

    Hello ‘isi’ — If you copy and paste the text into a text editor (notepad, vi) the # comments do not wrap around. I was able to cut/paste/use successfully.

  7. tigeli
    2:07 pm on February 10th, 2009

    isi meant comments regarding the virtual machines, not the code comments.

  8. Rick Scherer
    4:58 pm on February 10th, 2009

    Thanks ‘tigeli’ for clearing this up. In this case you may want to use the VCB APIs to create your VM Snapshots, just as I did for the removals.

  9. geekyB
    7:37 pm on February 12th, 2009

    Netapp snapvault also can be used with vmware. Checkout the snapvault guide at GeekyFacts – Snapvault guide

  10. Rick Scherer
    8:22 pm on February 12th, 2009

    geekyB: In the scenario your guide explains, SnapMirror might be the better alternative as it only replicates the changed blocks. SnapVault would be handy if doing backups directly from ESX to a filer, but if your datastores are on a NetApp already it would be easier just to use snapshots. SnapMirror can then replicate those snapshots to an off-site filer for BC or DR.

  11. Andreas
    9:57 am on February 24th, 2009

    Hi Rick,

    this is a nice us case. We’re thinking about adding it into our eCloudManager software which allows managing NetApp storage right out of Virtual Center. In your experience, are most customers ok with enabling SSH on ESX 3(i) servers?


  12. Rick Scherer
    4:45 pm on February 24th, 2009

    Well this functionality really would only work in ESX 3 (not ESXi), since the console in ESXi is for VMware Technical Support use only.

    Most customers that have *nix experience typically have no problem using SSH. For ESX management you can also use the RCLI or Powershell. For NetApp OnTAP management you can use SSH or RSH.

  13. Andreas
    8:43 pm on February 24th, 2009

    We’re running a large SAP landscape but we don’t use VMware snapshots. We sometimes pull out crash consisten SAP clones / backups from the .snapshot directory. Where do you see the advantage of having 2 levels of snapshots? Is there some communication between VMware, the guest tools and the app?

  14. Rick Scherer
    9:00 pm on February 24th, 2009

    What operating system is your guest VMs running? One SAP on VM deployment I’ve done (on NetApp storage) was Windows based, so we use the above script to kick off a VMware based snapshot prior to the NetApp snapshot. This will ensure that the VMDK files are closed and clean, it will also use the MS VSS driver to quiesce the O/S and SQL (if your using SQL). The VM snaps are removed after the process completes.

  15. Andreas
    9:13 pm on February 24th, 2009

    We’re using mostly Windows too. I wasn’t aware of the effects a VMware snapshot has on the OS and Apps. Good stuff!

    Our product talks to VMware using SOAP and to NetApp via REST+XML. We’ll add this for the next version.

    You should check it out. eCloudManager already allows you to sis clone a SAP system in minutes. LUN management is very convenient and you can rapidly provision entire datastores full of VDI VMs.


Leave a Comment

Name (required)

Email (required)



More Blog Post