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.