@echo off ::REM ----- Begin sample batch script ------- ::REM Sample batch programming script NetApp MSCS SME Backup Script ::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL ::REM by John D. Seaman, www.japan-page.net/batch ::REM --------- Set required values here -------------- ::REM Set SMTP alert destination here set _too=me @ mydomain.tld ::REM Set SMTP server variables here set _hst=mailserver.mydomain.tld set _frm=$computername% @ mydomain.tld set _msg="Error condition detected on cluster host %computername%." ::REM Initialize the alert variable. set _alert=0 ::REM Set the hostname tidbit here. This should be the part of the hostname ::REM that is common to both the physical node names and exch virtual server. ::REM For example exchange1a, exchange1b for physical nodes and exchange1 for the VS. set _hostNm=exch ::REM --------- END required values here -------------- ::REM Set debug level, (0 is normal, 1 saves log files) set _debug=0 ::REM Make sure we are running on Windows 2kx with MSCS installed. if /i not "%OS%" == "Windows_NT" ( set _abortMsg=Script can only run on NT. goto :abort ) if not exist %systemroot%\cluster ( set _abortMsg=Cluster service not installed. goto :abort ) ::REM Setup log file set _log=netApp_daily.no-verify.log echo.>%_log% echo ^|------------ Starting NetApp daily no-verify backup check ----------^| >>%_log% echo.>>%_log% echo Initialized at %time% on %date% on %hostname%... >>%_log% echo.>>%_log% echo. echo. echo ^|------------ Starting NetApp daily no-verify backup check ----------^| echo. echo Initialized at %time% on %date% on %computername% ... echo. echo ^|---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+^| >>%_log% echo.>>%_log% ::REM Make sure we have required system variables added. ::REM If not added (Control Panel, System, Advanced, Environment Variables) alarm. ::REM Since checking if a variable is null in batch doesn't always work, we look ::REM for a known string in the host name "exch". Change this for your setup. ::REM This is why batch programming is a black art. echo %clusterName% | find /i "%_hostNm%" >nul goto :var1chk%errorlevel% :var1chk0 echo. echo.>>%_log% echo Variable clusterName is defined as %clusterName%... OK echo Variable clusterName is defined as %clusterName%... OK>>%_log% goto :varCheck2 :var1chk1 echo. echo.>>%_log% echo Alert! Variable clusterName is NOT defined !! echo Alert! Variable clusterName is NOT defined !!>>%_log% set _alert=1 call :alert goto :END :varCheck2 echo %exchangeVirtualName% | find /i "%_hostNm%" >nul goto :var2chk%errorlevel% :var2chk0 echo. echo.>>%_log% echo Variable exchangeVirtualName is defined as %exchangeVirtualName%... OK echo Variable exchangeVirtualName is defined as %exchangeVirtualName%... OK>>%_log% goto :chkQuorum :var2chk1 echo. echo.>>%_log% echo Alert! Variable exchangeVirtualName is NOT defined !! echo Alert! Variable exchangeVirtualName is NOT defined !!>>%_log% set _alert=1 call :alert goto :END ::REM Decide if I have the Quorum drive :chkQuorum if exist q:\mscs ( set /a _isquorum=1 echo. echo.>>%_log% echo Node %computername% currently has the Quorum resource... echo Node %computername% currently has the Quorum resource.>>%_log% ) if not exist q:\mscs ( echo. echo.>>%_log% set /a _isquorum=0 echo Node %computername% does not hold the Quorum resource. echo Node %computername% does not hold the Quorum resource.>>%_log% ) echo. echo.>>%_log% ::REM Get node names and check node status echo. echo.>>%_log% echo ----------------------------------- echo Now checking cluster node status... echo ----------------------------------- echo ----------------------------------->>%_log% echo Now checking cluster node status...>>%_log% echo ----------------------------------->>%_log% ::REM Get node output (raw) cluster %clusname% Node /Status >_nodeStat.txt ::REM Clean it up type _nodeStat.txt | find "%_hostNm%" >_nodeStat1.txt for /f "tokens=1,2,3" %%x IN (_nodeStat1.txt) do call :SUBNode %%x %%y %%z echo. echo.>>%_log% ::REM Check cluster group status echo. echo.>>%_log% echo ------------------------------------ echo Now checking cluster group status... echo ------------------------------------ echo ------------------------------------>>%_log% echo Now checking cluster group status...>>%_log% echo ------------------------------------>>%_log% CLUSTER %clusname% GROUP /Status >_groupStat.txt type _groupStat.txt | find "PAEX" >_groupStat1.txt for /f "tokens=1,2,3,4*" %%i IN (_groupStat1.txt) do call :SUBGroup %%i %%j %%k %%l ::REM Check if Node A is active with Exchange. ::REM ::REM This is not a requirement, but if your Exchange implementaiton is Active / Passive, ::REM you may want to know when Exchange isn't running on Node A. ::REM In this version no alerts are generated. ::REM This assumes your physical node names end in "A" and "B". Use or ignore ::REM this feature at your pleasure. echo. echo.>>%_log% echo. echo.>>%_log% echo ---------------------------------------- echo Now checking the Active Exchange node... echo ---------------------------------------- echo ---------------------------------------->>%_log% echo Now checking the Active Exchange node...>>%_log% echo ---------------------------------------->>%_log% type _groupStat1.txt | find "Exchange_" >_nodeCheck.txt ::Extract active node name for Exchange cluster resource for /f "tokens=1,2,3" %%i IN (_nodeCheck.txt) do echo %%j >_exActiveNode.txt type _exActiveNode.txt | find "A " if /i %errorlevel% EQU 0 ( echo Node A is active for the Exchange Resource group... echo Node A is active for the Exchange Resource group...>>%_log% echo. echo.>>%_log% goto :checkSAStatus ) ::REM Error detected, node A is not active for the Exchange group ::REM Uncomment the following line to generate alerts ::REM set _alert=1 echo. echo.>>%_log% echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>%_log% echo Note: Node A is not active for the Exchange resource group... echo Note: Node A is not active for the Exchange resource group...>>%_log% echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!>>%_log% ::REM If Node A has failed over Exchange to Node B, allow the backups to run anyway. :checkSAStatus ::REM Detect if I have Exchange resource. If I do, run backup, otherwise we're finished. sc query MSExchangeSA >_out.txt type _out.txt | find "STATE : 4 RUNNING" goto :ExchSa%ERRORLEVEL% ::REM ------------------------------------------ ::REM MSExchangeSA service is running, do backup ::REM ------------------------------------------ :ExchSa0 ::REM If we get this far, we're good to go... :runBackup echo. echo.>>%_log% echo -------------------------------------------- echo -------------------------------------------- >>%_log% echo Beginning NetApp backup at %time%... echo Beginning NetApp backup at %time%...>>%_log% echo -------------------------------------------- echo -------------------------------------------- >>%_log% echo.>>%_log% ::REM --------------------------------------------------------- ::REM Set your backup variables here. ::REM --------------------------------------------------------- ::REM This script assumes one Storage group named SG1. ::REM Code for a two storage group backup is also commented out. echo Processing one storage group backup... echo Processing one storage group backup...>>%_log% call c:\progra~1\SNAPMA~1\SnapBackup.exe ^"%exchangeVirtualName%^" -d 5 -b 1 ^"SG1^" -nc -Daily ::REM echo Processing two storage group backup... ::REM echo Processing two storage group backup...>>%_log% ::REM call c:\progra~1\SNAPMA~1\SnapBackup.exe ^"%exchangeVirtualName%^" -d 5 -b 2 ^"SG2^" ^"SG1^" -nc -Daily echo. echo.>>%_log% echo -------------------------------------------- echo -------------------------------------------- >>%_log% echo NetApp backup completed at %time%... echo NetApp backup completed at %time%...>>%_log% echo -------------------------------------------- echo -------------------------------------------- >>%_log% ::REM Future version, grab the log file from c:\progra~1\SNAPMA~1\report\BACKUP~1 ::REM and parse it for errors. goto :alertStatus ::REM ------------------------------------------------ ::REM MSExchangeSA service is NOT running, skip backup ::REM ------------------------------------------------ :ExchSa1 echo. echo.>>%_log% echo Exchange SA not found running, skipping backup. echo Exchange SA not found running, skipping backup.>>%_log% goto :alertStatus ::REM Check error status (last step) :alertStatus if /i %_alert% EQU 1 ( echo Error detected, now sending alert... echo Error detected, now sending alert...>>%_log% call :alert ) sleep 5 goto :END ::REM ------------------- F U N C T I O N S ------------------------------------------ :SUBNode ::REM ------------------------ ::REM Detect if a node is down ::REM ------------------------ echo Status is %3... if not "%3" == "" if not "%3"=="Up" ( echo Node %1 is %3. echo Node %1 is %3>>%_log% set /a _alert=1 set _msg="ALERT! Node %1 is %3! goto :ALERT ) echo Node %1 is currently %3 echo Node %1 is currently %3>>%_log% call uptime %1 >>%_log% call uptime %1 echo.>>%_log% goto :EOF :SUBGroup ::REM ---------------------------------- ::REM Detect if resource groups are down ::REM ---------------------------------- echo. echo %1 %2 %3 %4 set _desc=Virtual Server Resource Group ::REM Handle resource group not partially down, skip local cluster group if not "%1" == "Cluster" if not "%3" == "Online" if not "%3" == "Partially" ( echo %_desc% %1 is currently %3!!>>%_log% set /a _alert=1 ) if not "%1" == "Cluster" if not "%3" == "Online" if not "%3" == "Partially" ( set _msg="Alert! %1 is currently %3!!" goto :alert ) ::REM Handle resource group partially down, skip local cluster group if not "%1" == "Cluster" if not "%3" == "Online" if "%3" == "Partially" ( echo %_desc% %1 is currently partially OFFLINE!!>>%_log% set /a _alert=1 ) if not "%1" == "Cluster" if not "%3" == "Online" if "%3" == "Partially" ( set _msg="Alert! %1 is currently partially OFFLINE!!" goto :alert ) ::REM Write resource not online, not partially down TO the log if not "%1" == "Cluster" ( echo %_desc% %1 is currently %3 echo %_desc% %1 is currently %3>>%_log% ) ::REM Handle local cluster group if "%1" == "Cluster" if not "%4" == "Online" ( echo %1 %2 %3 echo %1 %2 %3>>%_log% set /a _alert=1 ) if "%1" == "Cluster" ( echo Local Cluster Group %3 is %4 echo Local Cluster Group %3 is %4>>%_log% echo. echo.>>%_log% ) goto :EOF ::REM --------------------------------------------------------------------- :abort ::REM --------------------------- ::REM Process errors and bail out ::REM --------------------------- echo. echo An error occurred! echo. echo %_abortMsg% echo %_abortMsg%>>%_log% echo. :alert ::REM --------------------------------------------------------------- ::REM Check to see if an alert condition exists and react accordingly ::REM --------------------------------------------------------------- set _warntxt=****** A L E R T ****** A L E R T ****** if "%_alert%" == "1" ( echo.>>%_log% echo %_warntxt%>>%_log% echo.>>%_log% echo ! %_msg%>>%_log% bmail -f %_frm% -s %_hst% -t %_too% -a %_msg% -b %_msg% -m %_log% -d -h echo SMTP alert sent... echo SMTP alert sent...>>%_log% ) ::REM Reset alert status, prevents multiple SMTP error messages for the same issue set /a _alert=0 goto :EOF ::REM -------------- C L E A N -- U P ------------------- :END echo ^ echo ^ >>%_log% if /i not %_debug% EQU 1 del _*.txt /q :EOF