ECHO OFF setlocal enableextensions enabledelayedexpansion :: Last modified Keith Luken 2014/03/10 :: To remove dependence on system environment variables :: :: This script will take 3 parameters ARRAYNAME VVPATTERN and EXPIRATION :: ARRAYNAME is the array to run the command against it is also used to prefix the name of the variblae for the passwod file :: so you can use the same script against multiple arrays without modification :: VOLPATTERN is the the string to use to match volume names for snapshotting :: EXPIRATION is the length in hours of the snapshot expiration set ARRAYNAME=%1 set VVPATTERN=%2 set VCEXPIRE=%3 :: if you want toset a default expiration leave this line in if "[%3]"=="[]" (set VCEXPIRE=24) else (set VCEXPIRE=%3) :: End debug settings :: if you set DEBUG to YES then the command will not be run it will just go through motions and generate an output of the command lines it woudl have run set DEBUG=NO set PASSWORDFILE=%ARRAYNAME%_admin.pwfile rem e: rem cd "e:\program files\3par scripts" set PARAM1= set PARAM2= set /a SNAPS=0 set /a FAILS=0 set SNAPFAILED=NO set README=NO set ERRORLEVEL= :: CLEANFAILURES if set to YES will delete the exported failure log if there were failures assuming you :: have something that captured the SYSOUT/CONSOLE of job where the failures woudl be listed at the end set CLEANFAILURES=YES :: The below lines will generate a unique number based on YYMMDD_HHMMSShh :: You can modify this to shorten the name to what is needed set UNUM=%time:~0,2%%time:~3,2%%time:~6,2%%time:~9,2% if "%UNUM:~0,1%" == " " set UNUM=0%UNUM:~1,10% :: you can use the next line to add the year to the front if needed. rem set UNUM=%date:~10,4%%date:~4,2%%date:~7,2%_!UNUM! set UNUM=%date:~4,2%%date:~7,2%_!UNUM! rem echo Generating Unique number - %UNUM% if "[%ARRAYNAME%]" =="[]" ( echo :: YOU DID NOT SUPPLY AN ARRAY NAME :: exit 200 ) if "[%VVPATTERN%]"=="[]" ( echo :: YOU DID NOT SUPPLY A VOLUME PATTERN :: exit 200 ) if "[%VCEXPIRE%]"=="[]" ( echo :: YOU DID NOT SUPPLY A EXPIRATION :: exit 200 ) :: VVNAMES is the file used to export the list of volumes form the showvv command set VVNAMES=vvnames-%UNUM%.txt set SNAPLIST=SNAPLIST-%UNUM%.txt set SNAPFAILS=SNAP_FAILURES-%UNUM%.txt :: SNAPID is the format of the name of the snapshot. You need to make sure this will be unique within the volume tree or it will fail :: if also needs to be within the 31 character limit set SNAPID=%UNUM% :: SNAPME is the commandline that will be issued to create the snapshot, PARAM2 is the volume name to be snapped needs to be appended in side :snapit :: %SNAPID% will have be generated by adding the VolID followed by -SNAPID set SNAPME=createsv -sys %ARRAYNAME% -pwf %PASSWORDFILE% -ro -exp %VCEXPIRE%h -comment SCRIPTED VC- echo. if "%DEBUG%"=="YES" echo ... RUNNING IN DEBUG MODE ... echo. echo Runtime: %date% %time% echo. echo Array to process: %ARRAYNAME% echo Volumes to process: %VVPATTERN% echo Snapshot expiration: %VCEXPIRE% echo. call :cleanfiles echo -- Creating volume list echo. :: This section will run the showvv command for the pattern and export itto the work file VVNAMES echo Searching for volumes matching pattern %VVPATTERN% set RUNME=showvv -sys %ARRAYNAME% -pwf %PASSWORDFILE% -p -type base %VVPATTERN% echo. call %RUNME% >%VVNAMES% if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER :: This section will cycle through the work file VVNAMES and then call the sub to create the snapshot FOR /F "tokens=*" %%i in (%VVNAMES%) do ( rem echo. rem echo Processing line: %%i call :snapit %%i rem echo Snap Result !result! if !result! == 1 ( set result=0 set /a FAILS=!FAILS!+1 set SNAPFAILED=YES echo SNAP FAILED for,!PARAM2! >>%SNAPFAILS% )) echo. echo -- Finished processing file - %VVNAMES% echo. echo Snaps attempted= %SNAPS% echo Snaps failed= %FAILS% echo. :: If any snaps failed the run this section to read throuh the liset of failed snapshots if "%SNAPFAILED%"=="YES" ( echo. echo :: ONE OR MORE SNAPSHOTS FAILED :: echo. echo -- Following Snapswere not successful -- echo. FOR /F "tokens=*" %%s in (%SNAPFAILS%) do ( echo %%s ) echo. echo. call :cleanfiles exit 5 ) :: call the cleanup sub to get rid of the work files call :cleanfiles GOTO FINISH :: this section will cleanup the temp files and if in debug mode leave behind the list of volumes snaps were attemtped on :: if the option to CLEANUPFAILURES is not set to YES then the list of failed snaps is left behind :: that is useful if you are not capturing the sysout with a job scheduler :cleanfiles if /i "%CLEANFAILURES%"=="YES" ( rem echo -- Checking if exisits and deleting file : %SNAPFAILS% if exist %SNAPFAILS% del %SNAPFAILS% /Q if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER ) rem echo -- Checking if exisits and deleting file : %VVNAMES% if exist %VVNAMES% del %VVNAMES% /Q if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER if not "%DEBUG%"=="YES" ( rem echo -- Checking if exisits and deleting file : %SNAPLIST% if exist %SNAPLIST% del %SNAPLIST% /Q if %ERRORLEVEL% NEQ 0 GOTO ERROR_HANDLER ) GOTO :EOF :snapit set PARAM1=%1 set PARAM2=%2 if [%PARAM1%]==[] GOTO :EOF if [%PARAM2%]==[] GOTO :EOF rem echo Checking parameters: %PARAM1% %PARAM2% if /i "%PARAM2%"=="total" GOTO :EOF set result=0 set CL=!SNAPME!!PARAM1!-%SNAPID% !PARAM2! rem echo Command line: !CL! if /i "%README%"=="YES" ( rem echo Running command !CL! echo snapping:!PARAM2! if "%DEBUG%"=="YES" echo !CL! >>%SNAPLIST% if not "%DEBUG%"=="YES" call !CL! set result=!ERRORLEVEL! set /a SNAPS=!SNAPS!+1 ) :: This statment check if the line has Id and Name in it to signify the next line is the start of volumes if /i "%PARAM1%"=="Id" ( if /I "%PARAM2%"=="Name" ( set README=YES )) GOTO :EOF :ERROR_HANDLER echo. echo ...Error occured... echo. exit %ERRORLEVEL% :FINISH