113 lines
4.3 KiB
Batchfile
113 lines
4.3 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions DisableDelayedExpansion
|
|
set "PUSHD_ACTIVE=0"
|
|
|
|
if "%~1"=="" goto :usage
|
|
if "%~2"=="" goto :usage
|
|
if "%~3"=="" goto :usage
|
|
if "%~4"=="" goto :usage
|
|
if "%~5"=="" goto :usage
|
|
if "%~6"=="" goto :usage
|
|
|
|
set "REPO_ROOT=%~f1"
|
|
set "SQL_SERVER=%~2"
|
|
set "DATABASE=%~3"
|
|
set "START_UTC=%~4"
|
|
set "OUTPUT_DIR=%~f5"
|
|
set "LOG_DIR=%~f6"
|
|
set "SQL_FILE=%~dp0shadow-v3-export.sql"
|
|
set "WAREHOUSE_ID=%FORTUCKY_ALGORITHM_WAREHOUSE_ID%"
|
|
if not defined WAREHOUSE_ID set "WAREHOUSE_ID=01"
|
|
if "%WAREHOUSE_ID%"=="1" set "WAREHOUSE_ID=01"
|
|
rem FORTUCKY_SHADOW_ variables are collected by the FORTUCKY_ prefix scan below.
|
|
|
|
if not "%WAREHOUSE_ID%"=="01" (call :fail "FORTUCKY_ALGORITHM_WAREHOUSE_ID must be 01" & exit /b 1)
|
|
if not exist "%REPO_ROOT%\.git" (call :fail "REPO_ROOT is not a Git repository" & exit /b 1)
|
|
if not exist "%LOG_DIR%" (call :fail "LOG_DIR does not exist" & exit /b 1)
|
|
if not exist "%SQL_FILE%" (call :fail "export SQL file is missing" & exit /b 1)
|
|
where git >nul 2>nul
|
|
if errorlevel 1 (call :fail "git is not available on PATH" & exit /b 1)
|
|
where jps >nul 2>nul
|
|
if errorlevel 1 (call :fail "jps is not available on PATH" & exit /b 1)
|
|
where sqlcmd >nul 2>nul
|
|
if errorlevel 1 (call :fail "sqlcmd is not available on PATH" & exit /b 1)
|
|
|
|
if exist "%OUTPUT_DIR%" (
|
|
dir /a /b "%OUTPUT_DIR%" >nul 2>nul
|
|
if not errorlevel 1 (call :fail "OUTPUT_DIR already exists and is not empty" & exit /b 1)
|
|
) else (
|
|
mkdir "%OUTPUT_DIR%"
|
|
if errorlevel 1 (call :fail "cannot create OUTPUT_DIR" & exit /b 1)
|
|
)
|
|
|
|
pushd "%REPO_ROOT%" >nul
|
|
if errorlevel 1 (call :fail "cannot enter REPO_ROOT" & exit /b 1)
|
|
set "PUSHD_ACTIVE=1"
|
|
(
|
|
echo export_started_local=%DATE% %TIME%
|
|
echo expected_branch=test/ft546wms-shadow-v3-20260903
|
|
) > "%OUTPUT_DIR%\deployment.txt" 2>&1
|
|
if errorlevel 1 (call :fail "cannot create deployment evidence" & exit /b 1)
|
|
git branch --show-current >> "%OUTPUT_DIR%\deployment.txt" 2>&1
|
|
if errorlevel 1 (call :fail "cannot collect Git branch evidence" & exit /b 1)
|
|
git rev-parse HEAD >> "%OUTPUT_DIR%\deployment.txt" 2>&1
|
|
if errorlevel 1 (call :fail "cannot collect Git commit evidence" & exit /b 1)
|
|
git status --porcelain >> "%OUTPUT_DIR%\deployment.txt" 2>&1
|
|
if errorlevel 1 (call :fail "cannot collect Git deployment evidence" & exit /b 1)
|
|
popd >nul
|
|
set "PUSHD_ACTIVE=0"
|
|
|
|
jps -lv > "%OUTPUT_DIR%\runtime-processes.txt" 2>&1
|
|
if errorlevel 1 (call :fail "cannot collect JVM process evidence" & exit /b 1)
|
|
|
|
(
|
|
for /f "tokens=1 delims==" %%E in ('set FORTUCKY_ 2^>nul') do echo %%E
|
|
) > "%OUTPUT_DIR%\environment-variable-names.txt"
|
|
if errorlevel 1 (call :fail "cannot collect environment variable evidence" & exit /b 1)
|
|
call :require_output "environment-variable-names.txt"
|
|
if errorlevel 1 exit /b 1
|
|
|
|
rem sqlcmd 13 does not reliably expand variables in :out paths. Use literal names under OUTPUT_DIR.
|
|
pushd "%OUTPUT_DIR%" >nul
|
|
if errorlevel 1 (call :fail "cannot enter OUTPUT_DIR" & exit /b 1)
|
|
set "PUSHD_ACTIVE=1"
|
|
sqlcmd -S "%SQL_SERVER%" -d "%DATABASE%" -E -b -r1 -w 65535 -y 0 -Y 0 -v WarehouseId="%WAREHOUSE_ID%" StartUtc="%START_UTC%" -i "%SQL_FILE%"
|
|
if errorlevel 1 (call :fail "read-only SQL export failed" & exit /b 1)
|
|
popd >nul
|
|
set "PUSHD_ACTIVE=0"
|
|
|
|
set "LOG_CANDIDATE="
|
|
for /f "delims=" %%L in ('dir /s /b "%LOG_DIR%\*.log" "%LOG_DIR%\*.txt" 2^>nul') do set "LOG_CANDIDATE=%%L"
|
|
if not defined LOG_CANDIDATE (call :fail "LOG_DIR has no readable .log or .txt candidate" & exit /b 1)
|
|
findstr /S /I /N /C:"shadow_failure" "%LOG_DIR%\*.log" "%LOG_DIR%\*.txt" > "%OUTPUT_DIR%\shadow-warnings.txt" 2>nul
|
|
if errorlevel 2 (call :fail "cannot read log sources" & exit /b 1)
|
|
|
|
call :require_output "sql-diagnostics.txt"
|
|
if errorlevel 1 exit /b 1
|
|
call :require_output "comparison-detail.txt"
|
|
if errorlevel 1 exit /b 1
|
|
call :require_output "runtime-metrics.txt"
|
|
if errorlevel 1 exit /b 1
|
|
call :require_output "inventory-parity.txt"
|
|
if errorlevel 1 exit /b 1
|
|
call :require_output "shadow-warnings.txt"
|
|
if errorlevel 1 exit /b 1
|
|
|
|
echo EXPORT_OK output=%OUTPUT_DIR%
|
|
echo EXPORT_OK means files were collected, not approval to switch algorithms.
|
|
exit /b 0
|
|
|
|
:require_output
|
|
if not exist "%OUTPUT_DIR%\%~1" (call :fail "expected export file is missing" & exit /b 1)
|
|
exit /b 0
|
|
|
|
:usage
|
|
echo Usage: %~nx0 REPO_ROOT SQL_SERVER DATABASE START_UTC OUTPUT_DIR LOG_DIR 1>&2
|
|
exit /b 2
|
|
|
|
:fail
|
|
echo EXPORT_FAILED %~1 1>&2
|
|
if "%PUSHD_ACTIVE%"=="1" popd >nul 2>nul
|
|
set "PUSHD_ACTIVE=0"
|
|
exit /b 1
|