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

Better - count kind of this.

I want to create log / e-mail list of changed, deleted or added files only if there have been changes.

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

Thank you. You’re a genius!

BTW, better if will be a flag Duplicati__CreatedBackup: True / False.

Is the DUPLICATI__PARSED_RESULT environment variable not good enough?

No, it’s Success whatever created new version or not.
And may better to call new variable: Duplicati__CreatedNewVersionBackup

I suggested to add result code instead: Suggestion: ExitCode of backup as exit codes of application (ex. Duplicati.CommandLine.exe)