@echo off setlocal EnableExtensions if "%~1"=="" goto usage if "%~2"=="" goto usage set "JACTION=%~1" set "JSTATUS=%~2" set "JNOTE=%~3" if "%BACKUP_JOURNAL%"=="" ( set "JLOG=%USERPROFILE%\backup-journal.log" ) else ( set "JLOG=%BACKUP_JOURNAL%" ) for %%I in ("%JLOG%") do ( if not "%%~dpI"=="" ( if not exist "%%~dpI" mkdir "%%~dpI" ) ) powershell -NoProfile -ExecutionPolicy Bypass -Command "$ErrorActionPreference='Stop'; if ((Test-Path -LiteralPath $env:JLOG) -and ((Get-Item -LiteralPath $env:JLOG).Length -gt 5MB)) { $old = $env:JLOG + '.' + (Get-Date -Format 'yyyyMMdd-HHmmss'); Move-Item -LiteralPath $env:JLOG -Destination $old }; Add-Content -LiteralPath $env:JLOG -Value ((Get-Date -Format 'yyyy-MM-dd HH:mm:ss') + ' | ' + $env:JACTION + ' | ' + $env:JSTATUS + ' | ' + $env:JNOTE) -Encoding UTF8" if errorlevel 1 goto failed echo Journal entry added: %JLOG% exit /b 0 :failed echo Failed to write journal: %JLOG% exit /b 1 :usage echo Usage: backup_journal.bat ^ ^ [note] exit /b 2