Running Dog League Blog

Technology for Techs

NetApp Snapshots with VMWare ESX/ESXi

 Without SnapManager for Virtual Infrastructure, which is released now, it is somewhat more difficult to do NetApp snapshots.   But if you are in a position where you must be creative about this, I’ve written a script to do so.   i’m sure that if you have the capital get SnapManager for Virtual Infrastructure it will be vastly superior to this.  Keep in mind this is covering a SAN based volume level snapshot, not the VMWare Snapshots, which are totally different things.   The SAN based volume snapshots are going to take up considerably less space and in no way impact performance.

There are essentially three different kinds of snapshots of virtual machines:  Hot, Warm, and Cold.   This holds true no matter if you are using VMWare Server or ESXi (or ESX for that matter)

Hot snapshots are ones that are taken while a virtual machine is running and serving data.    The advanatage of this is obvious - the backup of a virtual machine while it is running.   Many can be taken during business hours without clients noticing any differences.   The downside of them is that if you were to restore from a snapshot, it would be as if the server had the power cord was ripped out the back of it.    Whatever needs to be done for a consistency check of your data will have to be done.   Posts in the future will go into a script for this.

Warm snapshots are taken while the virtual machine is in the suspended state and all writes have been committed to the disk.   The virtual machine is only inaccessible for a short period of time (dependant on RAM and disk/cpu speed) and the hope is as long as the virtual machine is restored on a similar cpu architecture, the machine could be resumed successfully.    The pros of this is the downtime is minimal (but could be anywhere from a few seconds to a minute or more) and the snapshot is very likely to be consistent and useful.   The biggest con is that the machine has downtime.   Obviously this needs to be scheduled during nonpeak, nonproduction hours.

Cold snapshots are taken in a similar fashion to a warm snapshot, but when the machine is completely shutoff and powered off.  This is the most consistent snapshot you can take are it is basically a snapshot of files.   With the Virtual Machine powered off, after restoring - you are just turning the computer back on from a powered off state.

So, onto the script.   This utilizes putty.exe and plink.exe in order to make ssh connections to the NetApp filer and the ESX/ESXi Server.   So, ssh has to be enabled on ESXi and the NetApp filer as well.   Check my earlier post on how to enable ssh on ESXi.     This is a batch script that relies on the VMWare Remote Command Line interface that must also be installed on the Windows host.

REM NAME: ESXi and Netapp Warm Snapshot Script
REM
REM
REM Renames Volume Snapshots on SAN, Deletes the oldes one, suspends the VM on ESxi, take snapshot, REM and starts VM Backup
REM Meant to be Run At Night One an Evening
REM All variables must be set below

set /a count=[enter number of snapshots to retain]
Set Guestname=[enter name of guest]
Set SANAddress=[address of san/filer]
Set ESXiAddress=[address of ESXi host]
set SANVolume=[name of volume on filer]
Set SANPassword=[password of san]
Set ESXiPassword=[password of esxi]
Set VMXLocation=[location of vmx file]
REM Begin the Script
set /a count=count-1
set /a counta=count
plink %SANAddress% -l root -pw “%SANPassword%” “snap delete %SANVolume% %Guestname%_snap.%count%”

:Loop
if /i %count% GEQ 0 (
set /a count1=%count%
set /a count=count-1
if /i %count% EQU %counta% (
goto loop
)
plink %SANAddress% -l root -pw “%SANPassword%” “snap rename %SANVolume% %Guestname%_snap.%count% %Guestname%_snap.%count1%”
goto loop
) else (
perl “C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl” –server %ESXiAddress% –username root –password %ESXiPassword% %VMXLocation% suspend soft
plink %ESXiAddress% -l root -pw %ESXiPassword% “sync”
plink %SANAddress% -l root -pw “%SANPassword%” “snap create %SANVolume% %Guestname%_snap.0″
goto end
)

:end
 
perl “C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl” –server %ESXiAddress% –username root –password %ESXiPassword% %VMXLocation% start soft

Notes:

And for the Cold Snapshot script, it is identical, with exception that the word “suspend” is replaced with “stop”.    Let me also add that the path to the vmware-cmd.pl is going to be slightly different if you are running a 64-bit os (the Program Files (x86) folder).   Also, make sure to run through this at least once interactively at a command prompt because putty/plink will prompt you to save the key for each host you connect to.

So, this script is intented to run as a scheduled task inside of windows.   It will keep only as many snapshots as is entered in the variables, with the most recent snapshot always ending with “0″.  And, if it is not obvious, the script renames the existing backups appropriately, suspends (or powers off) the virtual machine, commits the writes to the hard disk, takes the snapshot, and then start the machine back up.

I can also post a script for VMWare Server running Windows if anyone is especially interested…just leave a comment on this post.

As soon as I’ve got the hot snapshots worked out, I’ll post the scripts out accordingly.

 

11 Comments on “NetApp Snapshots with VMWare ESX/ESXi”

  1. coreyfro

    This is awesome! And posted 1 day before I needed it.

  2. Tony

    Glad to help…if you have any problems, let me know. I’ll post some posts up concerning doing the hot backups and restores(including granular file level restores) in the near future.

  3. Cosy

    HI,

    It is nice if you can create the How TO’s. Then someone like me can follow your instructions.

    Cosy

  4. Tony

    What would you like to see explained that I didn’t do?

  5. Carl

    Hi.

    Seems to be a very neet script, I want this to work…
    Im working on a “backup and disaster recovery plan” at my company…. I’m new to this - scripting lifestyle and would appreciate you help if you have the time… ?
    You have not specified all steps in your guide, hope you can help me with this…
    I have installed “putty for ssh” and “plink remains on my desktop”, I have also installed “Remote CLI”.
    I copied your script and edited this to fit my settings, saved this file to “script.pl” and then I’m trying to run this file, nothing happens…. please HEEEEELP….

    BR
    Carl

  6. Tony

    Carl,

    This is a batch script, not a perl script, although it calls a perl script in the process. Copy the text above and modify it for your needs and just put it into something like notepad and save it with a .bat extension. Make sure the putty.exe and plink.exe executables are in the same directory. If you try running the batch script at a command prompt rather than double clicking on it, if you get any errors, you’ll be more likely to see them.

    Hope this helps.

  7. Thomas

    Hey,
    this looks like a pretty simple straightforward deal. what are your thoughts on running it to pull snaps from esxi (on dl385), to an external raid (USB) connected to a baremetal windows 2003 server (pe 1650), over GbE? From what i can see, it should be no problem.

    I am more of a windows admin, so this angle at things is vastly more common sense to me than all the RCLI, and Linux based scripting that everyone else discusses.

    Also, how would you recommend backing up the actual esxi config? If you don’t mind.

  8. Tony

    Thomas,

    One of the issues you’ll see is you can only do a lot of the scripting via the Remote CLI, so you’ll be forced to use it for a number of tasks, but it isn’t that bad.

    This is what I use to backup the config for ESXi, once again, its just remote cli in a batch script - which if you only have one box, you could just do as a scheduled task by itself, I just put one it in a batch because i’m doing it over multiple ESXi hosts.
    ————————————–
    Set ESXiPassword=[your root password here]
    REM Begin the Script
    perl “C:\Program Files\VMware\VMware VI Remote CLI\bin\vicfg-cfgbackup.pl” –server [servername goes here] –username root –password %ESXiPassword% -s
    —————————————

    Snapshoting over external raid (USB or not) changes the game somewhat. All of the snapshoting I put into this post is more about snapshoting using a SAN, in this case a Netapp SAN which inherently has the ability to do snapshots on a storage level. With just a simple RAID array, you won’t be getting any of these, so you’re reliant on the VMWare snapshots, which while they work are totally different. I don’t have much experience in it, but I know using the Remote CLI, you should be able to write something without too much trouble. Focus on the vmware-cmd remote cli utility and the “createsnapshot” option. You should be able to batch something with this similar to how I did above with snapshot names and remove them when you have a certain number of them, its just an adjustment to the script. If you run into serious problems, I could probably write something fairly quickly.

    But regardless, you still need to backup all of the VMDK files one way or another. Snapshots are just your first level backup - you still need to have them copied somewhere else on a regular basis. I’ve got SAN level tape backups and this replicated to a DR Site.

  9. Kiruha

    Хорошо, давайте обсудим это в отдельной теме. Хотя это не столь важно.

  10. Christian louboutin

    Thanks very much for sharing. It is quite useful.

  11. cheap christian louboutin shoes

    Thanks very much for sharing

Leave a Reply