NetApp Snapshots in ESX – Take 2

0 Comments Backup & Recovery, ESX 3.5 Tips, NetApp, Storage, VMware

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`
PATH=$PATH:/bin:/usr/bin

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

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

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

echo “Removing VMware Snapshots”
#REMOVE SNAPS FROM LOCAL HOST
for i in `vcbVmName -h localhost -s Any:* | grep moref`
#the above command grabs the MoRef ID for each Virtual Machine
do
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
do
vcbSnapshot -h localhost -d $i $p
#the above command removes the SsId from the MoRef ID
done
done

#REMOVE SNAPS FROM REMOTE HOST
for i in `ssh vcbVmName -h localhost -s Any:* | grep moref`
do
for p in `ssh </span></span> vcbSnapshot -h localhost -f $i Nightly |grep SsId`
do
ssh
</span> vcbSnapshot -h localhost -d $i $p
done
done
</p>