2012. 7. 5. 09:40ㆍ99. 정리전 - IT/29. IT 잡동지식
좋은예제
@ECHO OFF
REM ------------------------------------------------------------------
REM 변경 설정값 세팅 -> 추후 이전 버젼 체크 주석 풀기
REM ------------------------------------------------------------------
SET PRE_VERSION=P_090624_V1
SET CRT_VERSION=P_090624_V1
SET PATCH_FILE=OS_ERP_PATCH_P_090624_V1.zip
REM ------------------------------------------------------------------
REM 고정 설정값 세팅
REM ------------------------------------------------------------------
SET TARGET_DIR=C:
SET SQL_PATH=DB
SET APP_PATH=tomcat_5
SET WORK=%TARGET_DIR%\%APP_PATH%\work\Catalina\localhost\_\org\apache\jsp
SET JOB_DIR=D:\OS_ERP_PATCH_JOB
SET KRUSER=webapp/ppabew@ssyprodk
SET LCUSER=webapp/ppabew@ssyprodl
REM SET JOB_DIR=C:\OS_ERP_PATCH_JOB
REM SET KRUSER=webapp/ppabew@ssydevkr
REM SET LCUSER=webapp/ppabew@ssydevlc
SET LOG_PATH=%JOB_DIR%\LOG
SET PRE_LOG=%LOG_PATH%\%PRE_VERSION%.log
SET CRT_LOG=%LOG_PATH%\%CRT_VERSION%.log
SET RESULT_MSG=SUCCESS COMPLETED.
IF NOT DEFINED CATALINA_HOME (
@SET CATALINA_HOME=%TAG%
)
REM ------------------------------------------------------------------
REM 작업공간 생성
REM ------------------------------------------------------------------
IF NOT EXIST %JOB_DIR% (
MKDIR %JOB_DIR%
)
IF NOT EXIST %LOG_PATH% (
MKDIR %LOG_PATH%
)
REM ------------------------------------------------------------------
REM 배치파일 시작 알림
REM ------------------------------------------------------------------
ECHO ================================================================== > %CRT_LOG%
ECHO * SSY OS ERP BATCH JOB START : %date% %time% >> %CRT_LOG%
ECHO ================================================================== >> %CRT_LOG%
REM ------------------------------------------------------------------
REM 이전버전 설치 여부 확인 -> 처음한번은 로그가 없을테니 넘어감
REM ------------------------------------------------------------------
REM IF NOT EXIST %PRE_LOG% GOTO ERR01
REM ------------------------------------------------------------------
REM 패치파일 압축풀기
REM ------------------------------------------------------------------
IF NOT EXIST %PATCH_FILE% (
GOTO ERR02
) ELSE (
IF EXIST %JOB_DIR%\%CRT_VERSION% (
RMDIR /S /Q %JOB_DIR%\%CRT_VERSION% >> %CRT_LOG%
)
ECHO * >> %CRT_LOG%
ECHO * >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
ECHO - UNZIP >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
UNZIP %PATCH_FILE% -d%JOB_DIR%\%CRT_VERSION% >> %CRT_LOG%
)
REM ------------------------------------------------------------------
REM APP파일 패치
REM ------------------------------------------------------------------
IF NOT EXIST %TARGET_DIR%/%APP_PATH% (
GOTO ERRO3
) ELSE (
RMDIR /S /Q %WORK%
ECHO * >> %CRT_LOG%
ECHO * >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
ECHO - COPY >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
XCOPY %JOB_DIR%\%CRT_VERSION%\%APP_PATH% %TARGET_DIR%\%APP_PATH%\ /E /R /Y >> %CRT_LOG%
)
REM ------------------------------------------------------------------
REM 실행할 DB 쿼리 가져오기
REM ------------------------------------------------------------------
ECHO * >> %CRT_LOG%
ECHO * >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
ECHO - SQL COPY >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
XCOPY %JOB_DIR%\%CRT_VERSION%\%SQL_PATH% /E /R /Y >> %CRT_LOG%
REM ------------------------------------------------------------------
REM DB 패치
REM ------------------------------------------------------------------
ECHO * >> %CRT_LOG%
ECHO * >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
ECHO - DB Log >> %CRT_LOG%
ECHO ================================ >> %CRT_LOG%
ECHO * Target DB : SSYPRODK >> %CRT_LOG%
sqlplus %KRUSER% @patch_kr.sql >> %CRT_LOG%
ECHO * Target DB : SSYPRODL >> %CRT_LOG%
sqlplus %LCUSER% @patch_lc.sql >> %CRT_LOG%
ECHO * >> %CRT_LOG%
ECHO * >> %CRT_LOG%
REM ------------------------------------------------------------------
REM 배치파일 마감 알림
REM ------------------------------------------------------------------
GOTO END
REM ------------------------------------------------------------------
REM 각종 메세지 설정
REM ------------------------------------------------------------------
:ERR01
SET RESULT_MSG=Not found Previous Version Log File [%PRE_LOG%]
GOTO END
:ERR02
SET RESULT_MSG=Not found source zip file. [%PATCH_FILE%]
GOTO END
:ERR03
SET RESULT_MSG=Not found target directory. [%TARGET_DIR%/%APP_PATH%]
GOTO END
:END
ECHO - Result Message : %RESULT_MSG% >> %CRT_LOG%
ECHO ================================================================== >> %CRT_LOG%
ECHO * SSY OS ERP BATCH JOB END : %date% %time% >> %CRT_LOG%
ECHO ================================================================== >> %CRT_LOG%
REM ------------------------------------------------------------------
REM 저장로그 가져오기
REM ------------------------------------------------------------------
XCOPY %CRT_LOG% /E /R /Y