March 21, 2014

EMC Symmetrix TimeFinder DOS Batch File

This is included just for the “blast from the past” factor. This is a Windows NT/DOS shell batch file I wrote a decade ago to automate EMC Symmetrix TimeFinder operations. Good thing TimeFinder is much, much easier to use now! This demonstrates the true value of Microsoft’s VSS API!

@echo off

REM EMCBCV.BAT V. 1.23
REM
REM Usage:
REM "EMCBCV.BAT [est|split|verify] "
REM 
REM EMCBCV.BAT is a wrapper for the TimeFinder-CLI for Windows NT command, 
REM BCV.EXE.  It verifies input, logs use, and uses standard TF-CLI device 
REM files.
REM 
REM History:
REM 12/28/1999 - SLF - V1.0
REM 12/29/1999 - SLF - V1.1 - Added errorlevel checking
REM 01/28/2000 - SLF - V1.2 - Added logging, comments
REM 05/26/2000 - SLF - V1.23 - Updated slightly, no functional changes

REM COMMAND is the first command line option
set COMMAND=%1
REM GROUP is the second command line option
set GROUP=%2
REM EMCBASE is the base directory for the following
REM set EMCBASE=C:Program FilesEMC
set EMCBASE=D:TEMP
REM BCVBIN is the location of the EMC TF-CLI binaries
set BCVBIN="%EMCBASE%Symclibinariesbcv.exe"
REM SCRIPTSDIR is the location of this script and the device files
set SCRIPTSDIR="%EMCBASE%scripts"
REM LOGFILE is the log file
set LOGFILE="%EMCBASE%scriptsemcbcv.log"
REM Save old value of BCV_GK_FILE for restoring later
set OLD_GK_FILE=%BCV_GK_FILE%

REM Date and time stamp the log file
echo. | date | find "current" >> %LOGFILE%
echo. | time | find "current" >> %LOGFILE%
echo Starting EMCBCV.BAT with COMMAND=%COMMAND% and GROUP=%GROUP% >> %LOGFILE%

REM Verify COMMAND
if "%COMMAND%"=="restore" goto restore
if "%COMMAND%"=="est" goto est
if "%COMMAND%"=="establish" goto est
if "%COMMAND%"=="split" goto split
if "%COMMAND%"=="verify" goto verify
if "%COMMAND%"=="help" goto help

REM Unrecognized COMMAND
echo Error: Incorrect or null command
echo Error: Incorrect or null command (COMMAND=%COMMAND%) >> %LOGFILE%

:help
REM Print usage message
echo Usage: "EMCBCV.BAT [est|split|verify] "
goto end

:restore
REM COMMAND is "restore"
echo This batch file does not allow the restore command to be specified.
echo It must be run manually.  View the batch file source for details.
echo Usage: "EMCBCV.BAT [est|split|verify] "
echo Attempted to perform a BCV restore.  Denied. >> %LOGFILE%
goto end

:est
REM COMMAND is "est" or "establish"
REM FLAGS=-i means incremental establish, null FLAGS means full establish
set FLAGS=-i
echo Attempting to perform a BCV establish
echo Attempting to perform a BCV establish (FLAGS=%FLAGS%) >> %LOGFILE%
goto next1

:split
REM COMMAND is "split"
echo Attempting to perform a BCV split
echo Attempting to perform a BCV split >> %LOGFILE%
goto next1

:verify
echo Attempting to perform a BCV verify
echo Attempting to perform a BCV verify >> %LOGFILE%
goto next1

:next1
REM Verify GROUP
if "%GROUP%"=="arev1gm" goto arev1gm
if "%GROUP%"=="fibshr1g" goto fibshr1g
if "%GROUP%"=="fibshr1s" goto fibshr1s

REM Unrecognized GROUP
echo Error: Incorrect or null group
echo Error: Incorrect or null group (GROUP=%GROUP%) >> %LOGFILE%
goto end

:arev1gm
REM For each GROUP, assign required variables
echo Using group %group%
REM BCV_GK_FILE is a file pointing to a gatekeeper device for the desired Symmetrix
set BCV_GK_FILE=C:Program FilesEMCscriptsbox3_gatekeeper
REM PAIRS is the device file for this group
set PAIRS="%SCRIPTSDIR%%group%_pairs"
goto next2

:fibshr1g
echo Using group %group%
set BCV_GK_FILE=C:Program FilesEMCscriptsbox3_gatekeeper
set PAIRS="%SCRIPTSDIR%%group%_pairs"
goto next2

:fibshr1s
echo Using group %group%
set BCV_GK_FILE=C:Program FilesEMCscriptsbox3_gatekeeper
set PAIRS="%SCRIPTSDIR%%group%_pairs"
goto next2

:next2
REM This is the actual command execution

echo Executing the following command:
echo %BCVBIN% %command% -f %PAIRS% %FLAGS%

echo Executing the following command: >> %LOGFILE%
echo %BCVBIN% %command% -f %PAIRS% %FLAGS% >> %LOGFILE%

%BCVBIN% %command% -f %PAIRS% %FLAGS%

REM Check errolevels for BCV.EXE
if %errorlevel% EQU 5 goto split
if %errorlevel% EQU 4 goto progress
if %errorlevel% EQU 1 goto established
if %errorlevel% EQU 0 goto success

REM Unknown errorlevel
echo BCV.EXE reports: Unknown errorlevel: errorlevel=%errorlevel%
echo BCV.EXE reports: Unknown errorlevel: errorlevel=%errorlevel% >> %LOGFILE%

:success
if %COMMAND%=="verify" goto established
if %COMMAND%=="split" goto split
if %COMMAND%=="est" goto progress
if %COMMAND%=="establish" goto progress
echo BCV.EXE reports: BCV command was successful
echo BCV.EXE reports: BCV command was successful (errorlevel=%errorlevel%) >> %LOGFILE%
goto end

:established
echo BCV.EXE reports: BCV devices are established
echo BCV.EXE reports: BCV devices are established (errorlevel=%errorlevel%) >> %LOGFILE%
goto end

:progress
echo BCV.EXE reports: BCV split in progress
echo BCV.EXE reports: BCV split in progress (errorlevel=%errorlevel%) >> %LOGFILE%
goto end

:split
echo BCV.EXE reports: BCV devices not established
echo BCV.EXE reports: BCV devices not established (errorlevel=%errorlevel%) >> %LOGFILE%
goto end

:end
REM Date and time stamp the log file
echo. | date | find "current" >> %LOGFILE%
echo. | time | find "current" >> %LOGFILE%
echo Finished EMCBCV.BAT with COMMAND=%COMMAND% and GROUP=%GROUP% >> %LOGFILE%

REM Restore old BCV_GK_FILE value
set BCV_GK_FILE=%OLD_GK_FILE%

REM Clean up environment variables
set FLAGS=
set COMMAND=
set GROUP=
set BCVBIN=
set SCRIPTSDIR=
set LOGFILE=
set OLD_GK_FILE=

REM BCV Restore Procedure:
REM 
REM WARNING: This completely overwrites the Standard volumes with the contents
REM of the BCV volumes.  If you are not completely sure, DO NOT DO THIS!
REM 
REM This batch file does not allow the restore command to be specified.  It
REM must be run manually.
REM 
REM To restore the contents of the BCV volumes to the Standard volumes,
REM follow this procedure:
REM 
REM 1) Note which Symmetrix contains the Standard and BCV volumes.  Set the
REM    value of BCV_GK_FILE to point to a file containing a gatekeeper for
REM    that Symmetrix.  (this may not be necessary)
REM 2) Locate a device file containing the desired Standard and BCV volume 
REM    serial numbers.
REM 3) Locate the TF-CLI executables and CD to that directory.
REM 4) run "BCV.EXE restore -f " where  is the file
REM    identified in step 2 above.