Email list of backed up files

Hi,

due to lack of this feature I developed little run-script-after script, it might be useful for someone else. Its windows only and at least 2.0.2.10_canary_2017-10-11 is required. Feel free to post bugfixes and improvements.

Have fun, Jan

@echo off

if not "%DUPLICATI__OPERATIONNAME%" == "Backup" goto :EOF

set "DUPLICATI=C:\Program Files\Utils\Duplicati 2\Duplicati.CommandLine.exe"
set "DBPATH=C:\YourDBLocation.sqlite"
set "ENCRYPTION=--no-encryption"
set "RESULT_FILE=%TEMP%\DuplicatiAfterBackup.txt"
set "RESULT_FILE_TOO_LONG=%TEMP%\DuplicatiAfterBackup.TooLong.txt"
set "SUBJECT=Duplicati %DUPLICATI__backup_name% backup result: %DUPLICATI__PARSED_RESULT%"
set "MAIL_OPTIONS=--send-mail-to=you@your.email"
set "MAIL_OPTIONS=%MAIL_OPTIONS% --send-mail-url=smtp://your.smtp.server:25"
set "EXCLUDE_FOLDERS=--exclude=*\\"
set "MAX_BYTE_SIZE=10000"

echo Result: %DUPLICATI__PARSED_RESULT% > "%RESULT_FILE%"
echo. >> "%RESULT_FILE%"

"%DUPLICATI%" compare file://dummy 1 0 "--dbpath=%DBPATH%" "%EXCLUDE_FOLDERS%" --full-result %ENCRYPTION% >> "%RESULT_FILE%"

for /f "usebackq" %%A in ('%RESULT_FILE%') do set SIZE=%%~zA
if %SIZE% GTR %MAX_BYTE_SIZE% (
  echo Comparison file size of %SIZE% is over max %MAX_BYTE_SIZE% bytes, it was stored in %RESULT_FILE% > "%RESULT_FILE_TOO_LONG%"
  set "RESULT_FILE=%RESULT_FILE_TOO_LONG%"
)

"%DUPLICATI%" send-mail --send-mail-subject="%SUBJECT%" --send-mail-body=%RESULT_FILE% %MAIL_OPTIONS%
3 Likes

This script for macOS

#!/bin/sh

# credits to
# https://forum.duplicati.com/t/email-list-of-backed-up-files/978
# https://github.com/duplicati/duplicati/blob/master/Duplicati/Library/Modules/Builtin/run-script-example.sh

# otherwise every operation starts the script
if [ 'Backup' != "$DUPLICATI__OPERATIONNAME" ]; then
   exit 0;
fi

# ugly hack to set execution context locale
export LANG=$(defaults read -g AppleLocale).UTF-8

DUPLICATI="/Volumes/System/Applications/Duplicati.app/Contents/MacOS/duplicati-cli"
ENCRYPTION=--no-encryption
REPORT_FILE="$HOME/Library/Application Support/Duplicati/${DUPLICATI__backup_name}.log"
MAIL_SUBJECT="Duplicati $DUPLICATI__backup_name $DUPLICATI__EVENTNAME $DUPLICATI__OPERATIONNAME report"
STATUS="$DUPLICATI__PARSED_RESULT"
MAIL_OPTIONS="--send-mail-url=smtp://smtp.mail.ru:587/?starttls=when-available --send-mail-username=<user> --send-mail-password=<pass> --send-mail-from=<user> --send-mail-to=<user>"
EXCLUDE_FOLDERS=--exclude=*/

if [ 'Success' = "$DUPLICATI__PARSED_RESULT" ]; then

  # are there any changes?
  COUNT_NO_CHANGES=$(grep -cE '^(DeletedFiles: 0|DeletedFolders: 0|ModifiedFiles: 0|AddedFiles: 0|AddedFolders: 0)$' "$DUPLICATI__RESULTFILE")

  if [ 5 -eq $COUNT_NO_CHANGES ]; then

    # no changes, save result file for reference
    STATUS="Nothing"
    cp "$DUPLICATI__RESULTFILE" "$REPORT_FILE"

  else

    # log changes
    $DUPLICATI compare file:/dummy 1 0 "--dbpath=$DUPLICATI__dbpath" "$EXCLUDE_FOLDERS" --full-result $ENCRYPTION > $REPORT_FILE

  fi

else

  # operation failed, save result file for reference
  cp "$DUPLICATI__RESULTFILE" "$REPORT_FILE"

fi

# send report to email
$DUPLICATI send-mail --send-mail-subject="${MAIL_SUBJECT}: $STATUS" --send-mail-body="$REPORT_FILE" $MAIL_OPTIONS

exit 0
1 Like