61 lines
2.9 KiB
Batchfile
61 lines
2.9 KiB
Batchfile
@echo off
|
|||
|
|
rem ============================================================================
|
||
|
|
rem blog full-repo backup - entry point for Windows Task Scheduler
|
||
|
|
rem
|
||
|
|
rem scripts/backup-bundle.mjs does the real work:
|
||
|
|
rem git bundle --all -> AES-256-GCM encrypt -> WebDAV upload to OpenList
|
||
|
|
rem on the ZTE F50, then downloads it back and compares sha256.
|
||
|
|
rem
|
||
|
|
rem Notes:
|
||
|
|
rem * This file is intentionally pure ASCII. cmd.exe parses a .bat/.cmd using
|
||
|
|
rem the *current* code page (GBK on zh-CN) while node emits UTF-8. A UTF-8
|
||
|
|
rem Chinese comment can swallow the CR/LF and break the following line
|
||
|
|
rem (seen in practice: a rem line got executed as a command). ASCII is a
|
||
|
|
rem subset of UTF-8, so plain-English text mixes safely with node output.
|
||
|
|
rem * node resolution order: PATH -> WorkBuddy managed -> D:\nodejs
|
||
|
|
rem * Log appends to .workbuddy-backup\logs\backup.log, rotated at 5 MB
|
||
|
|
rem * .workbuddy-backup is git-ignored; logs and passphrase never enter git
|
||
|
|
rem * Exit code is passed through (0 = success), visible in Task Scheduler
|
||
|
|
rem ============================================================================
|
||
|
|
setlocal
|
||
|
|
|
||
|
|
set "REPO=%~dp0.."
|
||
|
|
if "%REPO:~-1%"=="\" set "REPO=%REPO:~0,-1%"
|
||
|
|
set "LOG=%REPO%\.workbuddy-backup\logs"
|
||
|
|
set "SCRIPT=%REPO%\scripts\backup-bundle.mjs"
|
||
|
|
|
||
|
|
if not exist "%LOG%" mkdir "%LOG%"
|
||
|
|
|
||
|
|
rem --- rotate log at 5 MB. Guarded by if exist: on the very first run the file
|
||
|
|
rem does not exist yet and for/f would fail with a "path not found" error ---
|
||
|
|
if exist "%LOG%\backup.log" for %%F in ("%LOG%\backup.log") do if %%~zF GTR 5242880 move /y "%LOG%\backup.log" "%LOG%\backup.prev.log" >nul 2>&1
|
||
|
|
|
||
|
|
rem --- locate node ---
|
||
|
|
set "NODE="
|
||
|
|
for %%P in (node.exe) do if not defined NODE set "NODE=%%~$PATH:P"
|
||
|
|
if not defined NODE if exist "%USERPROFILE%\.workbuddy\binaries\node\versions\22.22.2-6\node.exe" set "NODE=%USERPROFILE%\.workbuddy\binaries\node\versions\22.22.2-6\node.exe"
|
||
|
|
if not defined NODE if exist "D:\nodejs\node.exe" set "NODE=D:\nodejs\node.exe"
|
||
|
|
|
||
|
|
if not defined NODE call :fail "node not found in PATH, WorkBuddy managed dir, or D:\nodejs"
|
||
|
|
if not exist "%SCRIPT%" call :fail "script not found: %SCRIPT%"
|
||
|
|
|
||
|
|
rem --- ASCII timestamp. Do NOT use %date%: on zh-CN it carries localized
|
||
|
|
rem weekday text (e.g. Chinese "Tuesday") which would mix encodings ---
|
||
|
|
set "STAMP=%TIME%"
|
||
|
|
for /f "delims=" %%I in ('powershell -NoProfile -Command "[DateTime]::Now.ToString('yyyy-MM-dd HH:mm:ss')" 2^>nul') do set "STAMP=%%I"
|
||
|
|
|
||
|
|
rem --- arguments: use %* when given (handy for manual runs, e.g. --dry / --list) ---
|
||
|
|
set "ARGS=%*"
|
||
|
|
if "%ARGS%"=="" set "ARGS=--verify --keep 3"
|
||
|
|
|
||
|
|
echo. >> "%LOG%\backup.log"
|
||
|
|
echo [%STAMP%] ===== backup start ===== >> "%LOG%\backup.log"
|
||
|
|
"%NODE%" "%SCRIPT%" %ARGS% >> "%LOG%\backup.log" 2>&1
|
||
|
|
set "RC=%ERRORLEVEL%"
|
||
|
|
echo [%STAMP%] ===== backup end, exit=%RC% ===== >> "%LOG%\backup.log"
|
||
|
|
|
||
|
|
endlocal & exit /b %RC%
|
||
|
|
|
||
|
|
:fail
|
||
|
|
echo [%TIME%] ERROR: %~1 >> "%LOG%\backup.log"
|
||
|
|
endlocal & exit /b 1
|