hi… i just made a simpel batch script for our client-systems.
i wanted to give an error-output to the user, but it never changes errorlevel despite of real error.
for example if the REST server is not reachable, the backup prozess should exit with errorcode not 0.
but it seems i always get a 0
any idea on that?
@echo off
REM #########################################################
REM # how to use this batch file: #
REM # - restback.cmd init | to initialize repo #
REM # - restback.cmd | to start backup #
REM # - restback.cmd help | to show more commands #
REM # --------------------------------------------------- #
REM # each file/folder on a seperate line in: #
REM # - restinclude.txt | to backup #
REM # - restexclude.txt | to exclude from backup #
REM #########################################################
REM ############################################
REM # config #
REM ############################################
SET RESTIC_USER=user
SET RESTIC_PASSWORD=password
REM ############################################
REM # config - not necessary #
REM ############################################
SET RESTIC_REPO=repo
SET RESTIC_SERVER=sub.domain.tld
SET RESTIC_PORT=443
SET RESTIC_INCLUDE="%~dp0restinclude.txt"
SET RESTIC_EXCLUDE="%~dp0restexclude.txt"
SET RESTIC_DO=backup --files-from %RESTIC_INCLUDE% --exclude-file=%RESTIC_EXCLUDE%
SET RESTIC_COMMAND="%~dp0restic_0.9.6_windows_386.exe" -r rest:https://%RESTIC_USER%:%RESTIC_PASSWORD%@%RESTIC_SERVER%:%RESTIC_PORT%/%RESTIC_USER%%%2F%RESTIC_REPO%
REM ############################################
REM # check for parameter: #
REM # - no parameter = default backup #
REM # - repo is always given by config above #
REM ############################################
IF [%1] == [] (
@cmd /c
echo:
echo #########################################################################
echo # #
echo # Backup wird gestartet #
echo # Warte bis das Backup fertig ist! #
echo # Dieses Fenster schließt sich automatisch, wenn kein Fehler passiert #
echo # #
echo #########################################################################
echo:
echo:
echo:-------------------------------------------------------------------------
echo:
%RESTIC_COMMAND% %RESTIC_DO%
IF %ERRORLEVEL% NEQ 0 (
echo:
echo:-------------------------------------------------------------------------
echo:
echo #########################################################################
echo # #
echo # Problem beim anfertigen des Backups. #
echo # Kontaktiere einen Administrator! #
echo # #
echo # Fehlercode: %ERRORLEVEL% #
echo # #
echo #########################################################################
) ELSE (
echo:
echo:-------------------------------------------------------------------------
echo:
echo #########################################################################
echo # #
echo # Backup fertig #
echo # #
echo #########################################################################
timeout /T 10
)
) ELSE (
%RESTIC_COMMAND% %1 %2 %3 %4 %5 %6 %7
)