Can I know in --run-script-after script: was any changed, added or deleted files?

You can read %DUPLICATI__RESULTFILE% and check if there are any added, modified or deleted files.
This script will check the values for AddedFiles, ModifiedFiles and DeletedFiles. If at least one of them has a value greater than 0, the number of added/modified/deleted files is listed in a text file. If all 3 values are 0, the text “Nothing changed since last backup” is written to the text file.

The script checks only the values for these 3 options. You can extend it by checking additional options, like AddedFolders, ModifiedFolders, DeletedFolders, TooLargeFiles, FilesWithError etc.

@echo off

set OutputFile=C:\ProgramData\Duplicati.txt

rem Run script only after Backup operation.
if /i "%DUPLICATI__OPERATIONNAME%" neq "Backup" (goto :eof)

if exist "%OutputFile%" (del "%OutputFile%")
for /f "tokens=1,2 usebackq delims=: " %%a in ("%DUPLICATI__RESULTFILE%") do (
  call :ParseUploadStats %%a %%b
)
set /a TotalFiles = %AddedFiles% + %ModifiedFiles% + %DeletedFiles%
if %TotalFiles% gtr 0 (
  echo Added files:    %AddedFiles% >> "%OutputFile%"
  echo Modified files: %AddedFiles% >> "%OutputFile%"
  echo Deleted files:  %AddedFiles% >> "%OutputFile%"
) else (
  echo Nothing changed since last backup >> "%OutputFile%"
)
if exist "%Tempfile%" (del "%Tempfile%")
goto :eof

:ParseUploadStats
if /i "%1" equ "AddedFiles"    (set /a AddedFiles=%2)
if /i "%1" equ "ModifiedFiles" (set /a ModifiedFiles=%2)
if /i "%1" equ "DeletedFiles"  (set /a DeletedFiles=%2)
exit /b

2 Likes