@echo off

REM $Header: TRCLOG.BAT 1.00 02/11/2004 RM Copyright (c) 2004-2005, Hitachi, Ltd.
REM
REM NAME  : RM Shadow Copy Provider log collection script.
REM 
REM CHANGELOG
REM Revision 1.00   02/11/2004   t.nagura Initial revision
REM 

REM ------------------------------------------------------------------
REM Initialize
REM ------------------------------------------------------------------
REM SETLOCAL ENABLEEXTENSIONS
SET RMVSSPROG=%0
SET RMVSSINST=
SET RMVSSGROUP=
SET RMVSSOUTFILE=
SET RMVSSINST_LOCAL=
SET RMVSSINST_REMOTE=
SET RMVSSENVFILE=
SET RMVSSERRFLAG=

REM ------------------------------------------------------------------
REM Parameter analyze and check
REM ------------------------------------------------------------------
:ARGSANALYZE
IF "%1" == "" GOTO ANALYZEEND
  IF "%1" == "-i" ( SET RMVSSINST=%2
                    SHIFT )
  IF "%1" == "-g" ( SET RMVSSGROUP=%2
                    SHIFT )
  IF "%1" == "-o" ( SET RMVSSOUTFILE=%2
                    SHIFT )
SHIFT
GOTO ARGSANALYZE
:ANALYZEEND

REM ------------------------------------------------------------------
REM Parameter error
REM ------------------------------------------------------------------
IF "%RMVSSGROUP%" == "" GOTO GRPERR
IF "%RMVSSOUTFILE%" == "" GOTO OUTFILEERR


IF "%RMVSSINST%" == "" (
  SET RMVSSINST_LOCAL=%VSHTCHORCMINST_LOCAL%
  SET RMVSSINST_REMOTE=%VSHTCHORCMINST_REMOTE%
  echo Use default instance number %VSHTCHORCMINST_LOCAL% %VSHTCHORCMINST_REMOTE%
)

IF NOT "%RMVSSINST%" == "" (
  SET RMVSSINST_LOCAL=%RMVSSINST%
  SET RMVSSINST_REMOTE=
  echo Use specify instance number %RMVSSINST%
)

IF NOT "%VSHTCRMENVF%" == "" (
  SET RMVSSENVFILE=%VSHTCRMENVF%
)

REM ------------------------------------------------------------------
REM Output file Initialize
REM ------------------------------------------------------------------
echo > %RMVSSOUTFILE%

(echo ############################################################
 echo # Variables
 echo ############################################################) >> %RMVSSOUTFILE%
(
echo VSHTCHORCMINST_LOCAL = %VSHTCHORCMINST_LOCAL%
echo VSHTCHORCMINST_REMOTE = %VSHTCHORCMINST_REMOTE%
echo VSHTCHOMRCF_MUN = %VSHTCHOMRCF_MUN%
echo VSHTCHORC_MUN = %VSHTCHORC_MUN%
echo VSHTCRMAUTO = %VSHTCRMAUTO%
echo VSHTCRMENVF = %VSHTCRMENVF%
echo HORCMINST = %HORCMINST%
echo HORCC_MRCF = %HORCC_MRCF%
echo ----------------------------------------
echo RMVSSINST = %RMVSSINST%
echo RMVSSGROUP = %RMVSSGROUP%
echo RMVSSOUTFILE = %RMVSSOUTFILE%
echo RMVSSINST_LOCAL = %RMVSSINST_LOCAL%
echo RMVSSINST_REMOTE = %RMVSSINST_REMOTE%
echo RMVSSENVFILE = %RMVSSENVFILE%
) >> %RMVSSOUTFILE%

REM ------------------------------------------------------------------
REM Query environment variables 
REM ------------------------------------------------------------------
(echo:
 echo ############################################################
 echo # SET result
 echo ############################################################) >> %RMVSSOUTFILE%
set >>%RMVSSOUTFILE% 2>&1
echo Query environment variables			...OK

REM ------------------------------------------------------------------
REM Query environment file
REM ------------------------------------------------------------------
IF EXIST "%RMVSSENVFILE%" (
  (echo:
   echo ############################################################
   echo # type %RMVSSENVFILE% result
   echo ############################################################ ) >> %RMVSSOUTFILE%
  type %RMVSSENVFILE% >>%RMVSSOUTFILE% 2>&1
  IF ERRORLEVEL 1 (
    SET RMVSSERRFLAG=1
    SET CMD=type %RMVSSENVFILE%
    echo type %RMVSSENVFILE%				...NG
  )
  IF NOT ERRORLEVEL 1 (
    echo type %RMVSSENVFILE%				...OK
  )
  echo: >>%RMVSSOUTFILE%

)

REM ------------------------------------------------------------------
REM Query available LDEVs 
REM ------------------------------------------------------------------
(echo:
 echo ############################################################
 echo # inqraid -CLI -fg $Phys result
 echo ############################################################ ) >> %RMVSSOUTFILE%
\HORCM\etc\inqraid -CLI -fg $Phys >>%RMVSSOUTFILE% 2>&1
IF ERRORLEVEL 1 (
  SET RMVSSERRFLAG=1
  SET CMD=\HORCM\etc\inqraid -CLI -fg $Phys
  echo inqraid -CLI -fg $Phys				...NG
)
IF NOT ERRORLEVEL 1 (
  echo inqraid -CLI -fg $Phys				...OK
)


REM ------------------------------------------------------------------
REM Query LOCAL RAID Manager Config File and pair status
REM ------------------------------------------------------------------
IF NOT "%RMVSSINST_LOCAL%" == "" (
	set HORCMINST=%RMVSSINST_LOCAL%
	set HORCC_MRCF=

	IF NOT "%VSHTCHOMRCF_MUN%" == "" set HORCC_MRCF=1
	IF NOT "%VSHTCHORC_MUN%" == "" set HORCC_MRCF=

	REM Delayed environment variable expansion fix
	REM cound not refer %HORCC_MRCF%
	REM When not use this fix, use !HORCC_MRCF! with CMD /V option
)

REM Delayed environment variable expansion fix
IF NOT "%RMVSSINST_LOCAL%" == "" (
	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_LOCAL%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # raidqry -l
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\raidqry -l >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo raidqry -l					...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\raidqry -l
	)
	IF NOT ERRORLEVEL 1 (
          echo raidqry -l					...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_LOCAL%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # raidscan -pi $Phys -findg result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\raidscan -pi $Phys -findg >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo raidscan -pi $Phys -findg			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\raidscan -pi $Phys -findg
	)
	IF NOT ERRORLEVEL 1 (
          echo raidscan -pi $Phys -findg			...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_LOCAL%
	 echo # type %windir%\horcm%RMVSSINST_LOCAL%.conf result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	type %windir%\horcm%RMVSSINST_LOCAL%.conf >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo type %windir%\horcm%RMVSSINST_LOCAL%.conf			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=type %windir%\horcm%RMVSSINST_LOCAL%.conf
	)
	IF NOT ERRORLEVEL 1 (
          echo type %windir%\horcm%RMVSSINST_LOCAL%.conf			...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_LOCAL%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # pairdisplay -g %RMVSSGROUP% -CLI -fd result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\pairdisplay -g %RMVSSGROUP% -CLI -fd >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo pairdisplay -g %RMVSSGROUP% -CLI -fd			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\pairdisplay -g %RMVSSGROUP% -CLI -fd -l
	)
	IF NOT ERRORLEVEL 1 (
          echo pairdisplay -g %RMVSSGROUP% -CLI -fd			...OK
        )

)

REM ------------------------------------------------------------------
REM Query REMOTE RAID Manager Config File and pair status
REM ------------------------------------------------------------------
IF NOT "%RMVSSINST_REMOTE%" == "" (
	set HORCMINST=%RMVSSINST_REMOTE%
	set HORCC_MRCF=

	IF NOT "%VSHTCHOMRCF_MUN%" == "" set HORCC_MRCF=1
	IF NOT "%VSHTCHORC_MUN%" == "" set HORCC_MRCF=

	REM Delayed environment variable expansion fix
	REM cound not refer %HORCC_MRCF%
	REM When not use this fix, use !HORCC_MRCF! with CMD /V option
)

REM Delayed environment variable expansion fix
IF NOT "%RMVSSINST_REMOTE%" == "" (
	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_REMOTE%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # raidqry -l
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\raidqry -l >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo raidqry -l					...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\raidqry -l
	)
	IF NOT ERRORLEVEL 1 (
          echo raidqry -l					...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_REMOTE%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # raidscan -pi $Phys -findg result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\raidscan -pi $Phys -findg >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo raidscan -pi $Phys -findg			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\raidscan -pi $Phys -findg
	)
	IF NOT ERRORLEVEL 1 (
          echo raidscan -pi $Phys -findg			...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_REMOTE%
	 echo # type %windir%\horcm%RMVSSINST_REMOTE%.conf result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	type %windir%\horcm%RMVSSINST_REMOTE%.conf >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo type %windir%\horcm%RMVSSINST_REMOTE%.conf			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=type %windir%\horcm%RMVSSINST_REMOTE%.conf
	)
	IF NOT ERRORLEVEL 1 (
          echo type %windir%\horcm%RMVSSINST_REMOTE%.conf			...OK
        )

	(echo:
 	 echo ############################################################
	 echo # HORCMINST = %RMVSSINST_REMOTE%
	 echo # HORCC_MRCF = %HORCC_MRCF%
	 echo # pairdisplay -g %RMVSSGROUP% -CLI -fd result
	 echo ############################################################ ) >> %RMVSSOUTFILE%
	\HORCM\etc\pairdisplay -g %RMVSSGROUP% -CLI -fd >>%RMVSSOUTFILE% 2>&1
	IF ERRORLEVEL 1 (
          echo pairdisplay -g %RMVSSGROUP% -CLI -fd			...NG
	  SET RMVSSERRFLAG=1
	  SET CMD=\HORCM\etc\pairdisplay -g %RMVSSGROUP% -CLI -fd
	)
	IF NOT ERRORLEVEL 1 (
          echo pairdisplay -g %RMVSSGROUP% -CLI -fd			...OK
        )
)

REM ------------------------------------------------------------------
REM Query systeminfo
REM ------------------------------------------------------------------
(echo:
 echo ############################################################
 echo # systeminfo result
 echo ############################################################ ) >> %RMVSSOUTFILE%
systeminfo >>%RMVSSOUTFILE% 2>&1
IF ERRORLEVEL 1 (
  echo systeminfo					...NG
  SET RMVSSERRFLAG=1
  SET CMD=systeminfo
)
IF NOT ERRORLEVEL 1 (
  echo systeminfo					...OK
)

REM ------------------------------------------------------------------
REM Query vssadmin list providers
REM ------------------------------------------------------------------
(echo:
 echo ############################################################
 echo # vssadmin list providers
 echo ############################################################ ) >> %RMVSSOUTFILE%
vssadmin list providers >>%RMVSSOUTFILE% 2>&1
IF ERRORLEVEL 1 (
  echo vssadmin list providers				...NG
  SET RMVSSERRFLAG=1
  SET CMD=vssadmin list providers
)
IF NOT ERRORLEVEL 1 (
  echo vssadmin list providers				...OK
)

REM ------------------------------------------------------------------
REM Query Eventlog messages(Optional)
REM ------------------------------------------------------------------
(echo:
 echo ############################################################
 echo # cscript c:\windows\system32\eventquery.vbs /V
 echo ############################################################ ) >> %RMVSSOUTFILE%
cscript c:\windows\system32\eventquery.vbs /V >>%RMVSSOUTFILE% 2>&1
IF ERRORLEVEL 1 (
  echo cscript c:\windows\system32\eventquery.vbs /V	...NG
  SET RMVSSERRFLAG=1
  SET CMD=cscript c:\windows\system32\eventquery.vbs /V
)
IF NOT ERRORLEVEL 1 (
  echo cscript c:\windows\system32\eventquery.vbs /V	...OK
)


REM ------------------------------------------------------------------
REM Error occur
REM ------------------------------------------------------------------
IF NOT "%RMVSSERRFLAG%" == "" (
  echo:
  echo ERROR: log collections failed. Reconsider arguments.
)
IF "%RMVSSERRFLAG%" == "" (
  echo:
  echo Log collections succeeded.  
)
REM ------------------------------------------------------------------
REM Normal end
REM ------------------------------------------------------------------
echo Output %RMVSSOUTFILE%
GOTO END

REM ------------------------------------------------------------------
REM Group argument error
REM ------------------------------------------------------------------
:GRPERR
echo ERROR: requires -g group as argument
GOTO USAGE

REM ------------------------------------------------------------------
REM Outfile argument error
REM ------------------------------------------------------------------
:OUTFILEERR
echo ERROR: requires -o outfile as argument
GOTO USAGE

:USAGE
echo Usage: %RMVSSPROG% [-i inst#] -g group -o outputfile
echo        [-i inst#]     Specify the instance number for HORCM.
echo                       Running HORCM instance must be specified.
echo                       If not specified, VSHTCHORCMINST_LOCAL and
echo                       VSHTCHORCMINST_REMOTE system environment variables
echo                       will be used as default.
echo        -g group       Specify the dev_group for a configuration file.
echo                       If not specified, 'VG' will be used as default.
echo        -o outputfile  Specify the output filename for a collection data.

GOTO END

:END
ENDLOCAL
