So if you have been creating all of the batch files in the series you're ready for this one. This script will shuffle the snapshots for a virtual server, pause the server, create a netapp snapshot, and resume the vm server. You want to make sure you're following the NetApp / VMware best practice of moving the working directory and swap location to a non-snapshot volume so your snapshots don't include unnecessary changes. I can write more about that if requested but for now I would refer you to the NetApp or VMWare sites for best practices:
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM
REM Usage
REM snapshot [vmname] [filer] [ESXi Host] [SAN Volume] [vmx location] [# of Snapshots to keep] [csv file: optional]
REM
REM This batch file performs the following tasks:
REM Deletes the oldest Snapshot for [SAN Volume]
REM Shuffles Snapshots on [filer] for [SAN Volume] using [vmname] as the Snapshot name
REM Suspends [vmx location] on [ESXi Host]
REM Sync's [ESXi Host]
REM Creates Snapshot on [filer] for [SAN Volume] using [vmname]
REM Resumes [vmxlocation] on [ESXi Host]
REM
REM This script can be used ad hoc to create Snapshots or called from a maintenance script that runs nightly
REM
REM All variables must be set below
REM
REM DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
if "%6" == "" (
goto param_error
)
Set Guestname=%1
Set SANAddress=%2
Set ESXiAddress=%3
set SANVolume=%4
Set VMXLocation=%5
set /a count=%6
if "%7" == "" (
set logname=%1
) ELSE (
set logname=%7
)
REM Begin the Script
echo ---------------------------------------------------
echo Starting at %date% %time%
echo Starting %Guestname% Snapshot at %date% %time% >> Snapshot_%logname%.log
echo ---------------------------------------------------
echo.
set /a count=count-1
set /a counta=count
echo Deleting the oldest Snapshot . . .
REM Delete the oldest Snapshot
call ncmd %SANAddress% "snap delete %SANVolume% %Guestname%_snap.%count%"
echo.
echo.
echo ---------------------------------------------------
:Loop
if /i %count% GEQ 0 (
set /a count1=%count%
set /a count=count-1
if /i %count% EQU %counta% (
goto Loop
)
REM Shuffle remaining Snapshots
echo Shuffling Snapshot %count1%
call ncmd %SANAddress% "snap rename %SANVolume% %Guestname%_snap.%count% %Guestname%_snap.%count1%"
goto Loop
) else (
echo ---------------------------------------------------
echo.
REM Suspend the VM
echo.
echo ---------------------------------------------------
echo Suspending %1
echo.
call vcmd %ESXiAddress% %VMXLocation% suspend soft >> Snapshot_%logname%.log
echo. >> Snapshot_%logname%.log
REM Sync the ESXi Server
echo.
echo.
echo ---------------------------------------------------
echo Syncronizing %3...
echo.
call ersh %ESXiAddress% "sync"
REM Create the new Snapshot
echo.
echo.
echo ---------------------------------------------------
echo Creating Snapshot on %2...
echo.
call ncmd %SANAddress% "snap create %SANVolume% %Guestname%_snap.0" >> Snapshot_%logname%.log
echo. >> Snapshot_%logname%.log
goto finish
)
:finish
REM Restart the VM
call vcmd %ESXiAddress% %VMXLocation% start soft >> Snapshot_%logname%.log
echo. >> Snapshot_%logname%.log
echo.
echo.
echo ---------------------------------------------------
echo Finished at %date% %time%
echo Finished %Guestname% Snapshot at %date% %time% >> Snapshot_%logname%.log
echo ---------------------------------------------------
echo.
goto end
:param_error
echo ERROR! You did not enter the correct number of parameters!
echo.
echo usage: snapshot [vmname] [filer] [ESXi Host] [SAN Volume] [vmx location] [# of Snapshots to keep]
echo.
echo [vmname] - You entered [%1]
echo.
echo This is the name of the virtual server
echo (ie: vmserver01)
echo.
echo [filer] - You entered [%2]
echo.
echo This is the name of the NetApp filer
echo (ie: netapp01)
echo.
echo [ESXi Host] - You entered [%3]
echo.
echo This is the name of the ESXi Host server
echo (ie: vm01)
echo.
echo [SAN Volume] - You entered [%4]
echo.
echo This is the name of the NetApp volume
echo (ie: vmserver01)
echo.
echo [vmx location] - You entered [%5]
echo.
echo This is the location of the vmx file
echo (ie: "[vmserver01] vmserver01/vmserver01.vmx")
echo You should enclose this in ""
echo also make sure you get the [datastore] vmpath correct
echo.
echo [# of Snapshots] - You entered [%6]
echo.
echo This is the number of Snapshots to keep for this VM
echo (ie: 7)
goto end
:end
Friday, April 3, 2009
srsh.bat
This batch file sends commands to the NetApp filer.
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM srsh [filer] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the filer
REM
REM This batch file will send the [command] to the [filer] using a private key. This allows a script
REM access to the filer without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM srsh [filer] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the filer
REM
REM This batch file will send the [command] to the [filer] using a private key. This allows a script
REM access to the filer without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
rescan.bat
This batch file rescans the ESXi hba for new changes. I run this twice from scripts because there is a bug in ESXi that causes you to rescan twice for some hba's:
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM rescan [ESXi Host] [hba]
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\esxcfg-rescan.pl" --server %1 --username root --password password %2
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM rescan [ESXi Host] [hba]
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\esxcfg-rescan.pl" --server %1 --username root --password password %2
register.bat
This batch file will register a vm on an ESXi server. This assumes you have configured the public/private key authentication and that you have installed the vmware cli utility for ESXi:
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM
REM This file has 2 variations on input:
REM
REM Option 1
REM register [ESXi Host] [vmxname] [Resource] [Pool]
REM if you pass 4 variables to the file it will assume you have a vm with the structure [vmxname] vmxname/vmxname.vmx
REM We use resouce pools with 2 names (ie: Maintenance Systems, Development Systems, etc) which is why there's the "%3 %4" at the end
REM
REM Option 2
REM register [ESXi Host] [vmxname] [Resource] [Pool] [full vmx path]
REM If you pass 5 varialbes the second variable is ignored and the 5th variable should be the full path to the vmx file.
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
if %5=="" (
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password -s register "[%2] %2/%2.vmx" %1 "%3 %4"
) else (
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password -s register %5 %1 "%3 %4"
)
make sure you change password to your password.
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM
REM This file has 2 variations on input:
REM
REM Option 1
REM register [ESXi Host] [vmxname] [Resource] [Pool]
REM if you pass 4 variables to the file it will assume you have a vm with the structure [vmxname] vmxname/vmxname.vmx
REM We use resouce pools with 2 names (ie: Maintenance Systems, Development Systems, etc) which is why there's the "%3 %4" at the end
REM
REM Option 2
REM register [ESXi Host] [vmxname] [Resource] [Pool] [full vmx path]
REM If you pass 5 varialbes the second variable is ignored and the 5th variable should be the full path to the vmx file.
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
if %5=="" (
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password -s register "[%2] %2/%2.vmx" %1 "%3 %4"
) else (
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password -s register %5 %1 "%3 %4"
)
make sure you change password to your password.
ersh.bat
This batch file will send commands to the ESXi host. These are command line commands to the host vs. vmware-cmd.pl commands as in my vcmd.bat sample.
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM ersh [ESXi Host] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM ersh [ESXi Host] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
vcmd
This is the script I use to send vmware-cmd commands to my VMWare host servers. This assumes you have installed the Vmware VI Remote CLI app that includes perl (I installed the package VMware-VIRemoteCLI-3.5.0-104314.exe):
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM vcmd [ESXi Host] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password %2 %3 %4 %5 %6
As you can see the usage is vcmd.bat [ESXi Host] "[command]"
You will need to change the path to the private key you created from my previous post. Make sure you enclose the command in "'s
@echo off
REM --------------------------------------------------------------------------------------------------------------
REM Usage
REM vcmd [ESXi Host] "[command]"
REM
REM Be sure to enclose the command in "" marks
REM
REM This batch file assumes that the public private key pairing has been configured on the ESXi Host
REM
REM This batch file will send the [command] to the [ESXi Host] using a private key. This allows a script
REM access to the ESXi Host without the need to login in order to automate tasks
REM
REM This batch file is called from other batch files.
REM
REM DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!!!
REM --------------------------------------------------------------------------------------------------------------
perl "C:\Program Files\VMware\VMware VI Remote CLI\bin\vmware-cmd.pl" -v -H %1 -U root -P password %2 %3 %4 %5 %6
As you can see the usage is vcmd.bat [ESXi Host] "[command]"
You will need to change the path to the private key you created from my previous post. Make sure you enclose the command in "'s
Thursday, March 19, 2009
ncmd
The following is my ncmd.bat script. This file is called from other batch files or on it's own to send commands to the NetApp filer:
@echo off
REM ---------------------------------------------------------------
REM Usage
REM ncmd [filer] "[command]"
REM
REM Remember to enclose the command in "'s
REM
REM This batch file assumes that the private key pairing has been
REM configured on the [filer]
REM
REM This batch file will send the [command] to the [filer] using a
REM private key for authentication. This allows a script to access
REM the filer in order to automate tasks
REM
REM This batch file is called from other batch files. Do not edit
REM unless you know the implications of that
REM----------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
As you can see the usage is ncmd.bat [filer] [command]
You will need to change the path to the private key you created from my previous post. Also, if you're sending multiple caommands to the filer you need to enclose them in "'s (ie: ncmd filername "vol status").
@echo off
REM ---------------------------------------------------------------
REM Usage
REM ncmd [filer] "[command]"
REM
REM Remember to enclose the command in "'s
REM
REM This batch file assumes that the private key pairing has been
REM configured on the [filer]
REM
REM This batch file will send the [command] to the [filer] using a
REM private key for authentication. This allows a script to access
REM the filer in order to automate tasks
REM
REM This batch file is called from other batch files. Do not edit
REM unless you know the implications of that
REM----------------------------------------------------------------
plink -l root %1 -i "x:\path\to\yourkey.ppk" %2
As you can see the usage is ncmd.bat [filer] [command]
You will need to change the path to the private key you created from my previous post. Also, if you're sending multiple caommands to the filer you need to enclose them in "'s (ie: ncmd filername "vol status").
NetApp / ESXi root keypair files
The following sites helped me create the files needed to perform password free logins from my management system to my NetApp filers and ESXi VMHost servers:
First download Putty and required utilities:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Read this article on creating the keypair files for your ESXi server:
http://communities.vmware.com/docs/DOC-8890
It's a little vague on modifying the oem.tgz so this size helps with that:
http://www.vm-help.com/esx/esx3i/customize_oem_tgz.php
Read this NetApp Now (login required) article to to setup on your filer:
https://now.netapp.com/Knowledgebase/solutionarea.asp?id=kb34920
Read this doc on Pageant:
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter9.html#pageant
Let me know if you have any questions.
First download Putty and required utilities:
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Read this article on creating the keypair files for your ESXi server:
http://communities.vmware.com/docs/DOC-8890
It's a little vague on modifying the oem.tgz so this size helps with that:
http://www.vm-help.com/esx/esx3i/customize_oem_tgz.php
Read this NetApp Now (login required) article to to setup on your filer:
https://now.netapp.com/Knowledgebase/solutionarea.asp?id=kb34920
Read this doc on Pageant:
http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter9.html#pageant
Let me know if you have any questions.
Client NetApp / VMware Config
My client has a clustered FAS2050. One head is controlling the internal SAS drives and the other head is controlling the 2 SATA shelfs. The head that controls the internal SAS drives I will be calling the "Fast Drives" and the head that controlls the external SATA shelfs I will be calling the "Slow Drives".
The VMHost Servers have dual port qlogic QLA2432 HBA's. I have an initiator group setup for each port. I use the first port as the "Slow Speed" connector and the second port as my "High Speed" connector. The slow speed connector maps to lun's on the slow drives and the high speed connector maps to lun's on the high speed connector.
Shared Space:
250GB NetApp Volume [VM Working Directories and Pagefile drives]
250GB NetApp LUN
*I have a swap volume on each NetApp (slow and fast drives)
Typical Server Storage:
12GB NetApp Volume
10GB NetApp LUN (Thin provisioned [no space reserve on LUN])
ESXi Config:
1:1:1 Server:NetApp Volume:Datastore
So a typical Windows Virtual Server has a root C volume of 6GB, a data D volume of 4GB, and a Swap K volume that varies depending on how much ram is assigned to the VM. The K drive is an independent persistent disk. All of the NetApp volumes have had their snapshot schedules removed and I have deleted the default snapshots. I have written a script that runs each night to pause and take a NetApp snapshot of the server. I will post the script in a later post.
On the NetApp's and VMHost machines I setup a public/private key handshake to allow for scripted commands without the need for a password. I will post some links and my process in a later post.
Because they are using ESXi and not the Enterprise version I don't have the ability to do vmotion. However, I am able to do some pretty quick re-allocations via scripting which keeps the server downtime to a minimum. I will be posting my script in a later post. The scripts do require SnapMirror.
This should give you a pretty good understanding of where I'm coming from. I'm definitely no expert but I hope I can help people through my learning process and find some people willing to help me as well.
If you have any questions or comments about this configuration, I would love to hear them. There are always many different ways to accomplish the same task and I'm always looking to find a better way to do things.
The VMHost Servers have dual port qlogic QLA2432 HBA's. I have an initiator group setup for each port. I use the first port as the "Slow Speed" connector and the second port as my "High Speed" connector. The slow speed connector maps to lun's on the slow drives and the high speed connector maps to lun's on the high speed connector.
Shared Space:
250GB NetApp Volume [VM Working Directories and Pagefile drives]
250GB NetApp LUN
*I have a swap volume on each NetApp (slow and fast drives)
Typical Server Storage:
12GB NetApp Volume
10GB NetApp LUN (Thin provisioned [no space reserve on LUN])
ESXi Config:
1:1:1 Server:NetApp Volume:Datastore
So a typical Windows Virtual Server has a root C volume of 6GB, a data D volume of 4GB, and a Swap K volume that varies depending on how much ram is assigned to the VM. The K drive is an independent persistent disk. All of the NetApp volumes have had their snapshot schedules removed and I have deleted the default snapshots. I have written a script that runs each night to pause and take a NetApp snapshot of the server. I will post the script in a later post.
On the NetApp's and VMHost machines I setup a public/private key handshake to allow for scripted commands without the need for a password. I will post some links and my process in a later post.
Because they are using ESXi and not the Enterprise version I don't have the ability to do vmotion. However, I am able to do some pretty quick re-allocations via scripting which keeps the server downtime to a minimum. I will be posting my script in a later post. The scripts do require SnapMirror.
This should give you a pretty good understanding of where I'm coming from. I'm definitely no expert but I hope I can help people through my learning process and find some people willing to help me as well.
If you have any questions or comments about this configuration, I would love to hear them. There are always many different ways to accomplish the same task and I'm always looking to find a better way to do things.
Welcome
Welcome to my blog. I will be using this as an avenue to discuss some of the projects I am currently working on. Most of my current work involves ESXi virtualization on NetApp FAS2050 SAN equipment. The client I am currently working for has invested in SAN storage first and is now starting to increase it's investment in Virtualization technology. This has turned out to be a great strategy for the company as it has helped create a good foundation for growth. In the coming weeks I hope to share some of the useful sites and information that has helped me learn what I know, and I am hoping to connect with others who can help me expand my knowledge further.
Subscribe to:
Posts (Atom)