@echo off ::REM ------------------- Begin sample batch script ------------------------ ::REM Sample batch programming script SnapKicker.cmd ::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL ::REM by John D. Seaman, www.japan-page.net/batch echo. echo Snap-Kicker v.2005.6.15 echo. echo. echo This batch script will remotely kick off a Snapmirror of all exchange echo server log LUNs once an hour during the day. This minimizes the echo potential loss of e.mail data (in the event the filer heads echo completely crap out) from 4 hours to 1 hour. echo. echo. ::REM Set debug mode here, 0 is normal, 1 is debug set _debug=1 set _alert=0 :doit ::REM Do it finally... ::REM Prepare a log file... set _log=log.txt echo. >%_log% echo SnapKicker executed at %time% on %date%.. >>%_log% echo. >>%_log% ::REM Set configuration options set _hostname=YourNearStoreHostName echo. echo Now initiating a manual snapmirror of all Exchange log LUNs... echo. ::REM Get list of all snapmirror jobs rsh %_hostname% snapmirror status >_allSnaps.txt ::REM Put list of current snapmirror lag times in the log file (not required, just fyi) echo. echo.>>%_log% echo ^|----------------------- C u r r e n t -- L a g -- T i m e s --------------------------^| echo ^|----------------------- C u r r e n t -- L a g -- T i m e s --------------------------^|>>%_log% type _allSnaps.txt type _allSnaps.txt >>%_log% echo ^|--------------------------------------------------------------------------------------^| echo ^|--------------------------------------------------------------------------------------^|>>%_log% ::REM Sort, extract listing of all SnapMirrors, filter out non-Exchange snapmirrors ::REM Assumes your snapmirrors start with "exchange" and the log file LUNs have "log" in them if exist _replSnaps.txt del /q _replSnaps.txt type _allSnaps.txt | find ":" | find /i "exchange" | find /i "log" >_allSnaps1.txt for /f "tokens=1,2,3,4,5*" %%i in (_allSnaps1.txt) do echo %%j >>_replSnaps.txt ::REM Trigger a SnapMirror (loop) echo. echo.>>%_log% echo Triggering Snapmirrors... echo Triggering Snapmirrors...>>%_log% echo. echo.>>%_log% for /f %%i in (_replSnaps.txt) do ( echo Kicking off %%i SnapMirror... echo Kicking off %%i SnapMirror... >>%_log% call rsh %_hostname% snapmirror update %%i >%_log% echo. >>%_log% ) ::REM Sleep here for 5 min to allow snapmirror replication to finish echo. echo. >>%_log% echo Now sleeping for 5 minutes to allow snapmirror replication to finish... echo Now sleeping for 5 minutes to allow snapmirror replication to finish... >>%_log% sleep 300 ::REM Get the SnapMirror status output in a loop for all NetApp devices... ::REM Generate filer list... echo filer1hostname>_filers.ini echo filer2hostname>>_filers.ini echo %_hostname%>>_filers.ini ::REM Process in a loop for /f %%i in (_filers.ini) do call :checkfiler %%i echo. echo.>>%_log% ::REM Set SMTP alert variables set _sbj="Error: SnapMirror replication problem detected" set _msg="A SnapMirror error was detected. Examine the log file for more info." set _hst=smtp.yourdomain.com set _frm=%computername%@yourdomain.com set _too=someone@yourdomain.com if /i %_alert% EQU 1 ( echo Alert condition detected, sending alert e.mail... echo Alert condition detected, sending alert e.mail...>>%_log% echo ^ echo ^>>%_log% bmail -f %_frm% -s %_hst% -t %_too% -a %_sbj% -b %_msg% -m %_log% -d -h >smtp.log echo Alert mail send call completed... echo Alert mail send call completed... >>%_log% ) echo Finished processing... echo Finished processing...>>%_log% ::REM Cleanup if /i not %_debug% EQU 1 del /q _*.txt goto :EOF ::REM ---------------- F U N C T I O N S ---------------- :checkfiler echo. echo.>>%_log% echo Now checking filer %1 echo --------------------------------------------- echo Now checking filer %1 >>%_log% echo --------------------------------------------->>%_log% ::REM Get the filer snapmirror status rsh %1 snapmirror status >_%1out.txt ::REM Strip header line (lag time), pull out SQL servers type _%1out.txt | find /v "sqlcl" | find ":" >>_%1out2.txt ::REM Get the lag time field... if exist _error.txt del /q error.txt if exist _snaplag.txt del /q _snaplag.txt for /f "tokens=1,2,3,4,5*" %%i in (_%1out2.txt) do echo %%l >>_snaplag.txt ::REM Get the first two digits of the lag time, find anything >= 4 for /f "delims=:, tokens=1,2,3*" %%i in (_snaplag.txt) do ( echo SnapMirror lag time value is %%i... if /i %%i GEQ 04 (set _alert=1) ) echo Alert status for host %1 is %_alert%... echo Alert status for host %1 is %_alert%...>>%_log% type _%1out2.txt | find /V " 00:" | find /V " 01:" | find /V " 02:" | find /V " 03:">>%_log% del /q _%1out2.txt echo.>>%_log% echo.>>%_log% goto :EOF ::REM ---------------- E N D ----- F U N C T I O N S ---------------- :EOF