@echo off REM ============================================================================ REM Scoreboard one-click backup (Windows) REM REM Calls scoreboard.exe's backup subcommand (VACUUM INTO), so it is safe to REM run while the service is up and does not need an external sqlite3.exe. REM Output goes to \backups\; the server keeps the newest 20 per DB REM (system / each event). REM The data dir is the one the Console uses, i.e. %LOCALAPPDATA%\ScoreboardConsole\data REM (falling back to \data when that does not exist yet). It lives outside REM the install dir on purpose: reinstalling over an existing install wipes the REM install dir, so data must not be kept there. REM NOTE: only .db snapshots are taken. Background images / emblems under REM \event_projs\\uploads\ are NOT included; copy that REM directory separately if you need them on the archive. REM REM Usage: deploy\backup.bat manual backup (reason=manual) REM deploy\backup.bat publish pre-publish backup (reason=publish) REM REM Keep this file ASCII-only. cmd.exe mis-parses UTF-8 non-ASCII text inside REM batch files (especially inside if(...) blocks). See deploy\build.bat. REM ============================================================================ setlocal enabledelayedexpansion chcp 65001 >nul 2>&1 cd /d "%~dp0.." set "ROOT=%CD%" REM Same data dir the Console hands to the server via -data. set "DATA=%ROOT%\data" if defined LOCALAPPDATA if exist "%LOCALAPPDATA%\ScoreboardConsole\data" set "DATA=%LOCALAPPDATA%\ScoreboardConsole\data" REM Same config.yaml the Console hands to the server via -config: it lives in the REM per-user dir now, and the copy next to this script is only the shipped template REM (the uninstaller deletes the install dir, so edits there are lost). set "CONFIG=%ROOT%\config.yaml" if defined LOCALAPPDATA if exist "%LOCALAPPDATA%\ScoreboardConsole\config.yaml" set "CONFIG=%LOCALAPPDATA%\ScoreboardConsole\config.yaml" set "REASON=manual" if not "%~1"=="" set "REASON=%~1" set "REASON=%REASON: =_%" set "REASON=%REASON:/=-%" set "REASON=%REASON:\=-%" set "REASON=%REASON:"=%" if not exist "%DATA%" ( echo [ERROR] data directory not found: %DATA% echo Start Scoreboard_Console.exe once so the service creates it, echo or point this script at the data dir via -data manually. exit /b 1 ) REM ---- locate scoreboard.exe ------------------------------------------------- set "EXE=" if exist "%~dp0..\dist\scoreboard.exe" set "EXE=%~dp0..\dist\scoreboard.exe" if not defined EXE if exist "%ROOT%\scoreboard.exe" set "EXE=%ROOT%\scoreboard.exe" if not defined EXE if exist "%~dp0scoreboard.exe" set "EXE=%~dp0scoreboard.exe" if not defined EXE for %%I in (scoreboard.exe) do if exist "%%~$PATH:I" set "EXE=%%~$PATH:I" if not defined EXE ( echo [ERROR] scoreboard.exe not found. echo Run deploy\build.bat first, or put it in the project root / PATH. exit /b 1 ) REM config.yaml is still needed for port / backup settings; -data below picks the REM data dir explicitly, so the current directory no longer decides it. if not exist "%CONFIG%" ( echo [ERROR] config.yaml not found: %CONFIG% exit /b 1 ) echo === Scoreboard backup === echo Data dir : %DATA% echo Config : %CONFIG% echo Server : %EXE% echo Reason : %REASON% echo. set /a OK=0 set /a FAIL=0 REM The server backs up one event DB at a time (system.db is always included), REM so loop over the project directories. A typical deployment has one project. set "FOUND=" for /d %%D in ("%DATA%\event_projs\*") do ( set "FOUND=1" echo backup event %%~nxD "%EXE%" backup -config "%CONFIG%" -project "%%~nxD" -data "%DATA%" -reason "%REASON%" if errorlevel 1 (set /a FAIL+=1) else (set /a OK+=1) ) if not defined FOUND ( echo backup default event "%EXE%" backup -config "%CONFIG%" -data "%DATA%" -reason "%REASON%" if errorlevel 1 (set /a FAIL+=1) else (set /a OK+=1) ) echo. echo === backup done: ok=!OK! fail=!FAIL! === dir /b "%DATA%\backups\*.db" 2>nul if !FAIL! GTR 0 ( endlocal exit /b 1 ) endlocal exit /b 0