Email list of backed up files

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