Skip to content

Instantly share code, notes, and snippets.

@thomasfr
Last active January 15, 2020 17:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasfr/0fa42cc45237b2a1ead8 to your computer and use it in GitHub Desktop.
Save thomasfr/0fa42cc45237b2a1ead8 to your computer and use it in GitHub Desktop.
duplicity.backup Bash Script with Rollbar Notification
#!/bin/bash
export FTP_PASSWORD="123456"
FTP_USER="user"
FTP_HOST="user.your-backup.de"
BACKUP_TARGET="ftp://${FTP_USER}@${FTP_HOST}/$(hostname)"
DUPLICITY_LOGFILE="/var/log/duplicity.log"
DUPLICITY_TEMPDIR="/tmp/duplicity"
# Rollbar access token
ACCESS_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxx
test -x $(which duplicity) || exit 0
mkdir -p "${DUPLICITY_TEMPDIR}"
cd ${DUPLICITY_TEMPDIR}
curl -H "Content-Type: application/json" -d '{"access_token":"'"${ACCESS_TOKEN}"'","data":{"environment":"production","level":"info","title":"Backup started '"$(hostname -f)"'","body":{"message":{"body":"Backup started '"$(hostname -f)"'"}}}}' https://api.rollbar.com/api/1/item/
OUT1="$($(which duplicity) incr --allow-source-mismatch --no-encryption -v3 --ftp-passive --tempdir="${DUPLICITY_TEMPDIR}" --full-if-older-than "1W" --volsize=250 --log-file="${DUPLICITY_LOGFILE}" --include /var/www/files --include /etc --include /home --include /root --exclude '/**' / "${BACKUP_TARGET}" 2>&1)"
OUT2="$($(which duplicity) remove-all-but-n-full 8 --allow-source-mismatch -v3 --ftp-passive --force "${BACKUP_TARGET}" 2>&1)"
echo -e $OUT1;
echo -e $OUT2;
payload='{"access_token":"'"${ACCESS_TOKEN}"'","data":{"environment":"production","level":"info","title":"Backup finished '"$(hostname -f)"'","body":{"message":{"body":"'"${OUT1}"'\n\n'"${OUT2}"'"}}}}';
curl -H "Content-Type: application/json" -d "${payload}" https://api.rollbar.com/api/1/item/
unset FTP_PASSWORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment