Incremental backups using Duplicity, Rsync and GPG

89 || 0  || 2018-04-14 06:03:33 || root || || Bash

The script below allows you to create system backups on Linux systems using Duplicity, Rsync and GPG. Check comments in the code and don't forget to replace some placeholders with real values.

There are several snippets related to this topic:

  1. Incremental backups (duplicity + rsync + gpg)
  2. Full backups (duplicity + rsync + gpg)
  3. Backup to Amazon S3
  4. Configuring GPG keys

Please check the code to find links for other code snippets.


# Incremental backups:
# Full backups:
# Backups to S3:
# Configuring GPG: soon

# You need to create your own GPG key before using this script
# This directory will be used for making backups
# Backups will be copied to server ( using rsync. Install rsync on both server and client and configure in
# This file contains list of excluded files/directories (one path per line)
# Choose backup name if you are going to backup several devices

# Modify several lines below. They are related to email notifications. Use real email addresses, host and port
mailFrom="Backups <>"
mailTo="Firstname Lastname <>"
mailSubject="Failed backup on HP laptop"
mailBody="Latest incremental backup process on HP laptop has been finished with errors. Please check script manually and try again later. You can find error details below:"

# This file contains GPG and email credentials, one per line (PASSPHRASE="", mailLogin="", mailPass="")
test -x $(which duplicity) || exit 0
. /root/.duplicity_file

# Command for making incremental backups
duplicity_output=$(/usr/bin/duplicity --verbosity 9 --encrypt-key "$keyID" --sign-key "$keyID" --exclude-filelist "$excList" --name "$backupName" --num-retries 5 --timeout 30 --volsize 50 --asynchronous-upload "$srcPath" "$dstPath" 2>&1)

# If backup is finished with errors for some reason, script will send email about that
if [ $exit_code != 0 ]
    /usr/bin/sendEmail -f "$mailFrom" -t "$mailTo" -u "$mailSubject" -m "$mailBody" -s "${mailServer}:${mailPort}" -o message-charset=utf-8 -o tls=yes -xu "$mailLogin" -xp "$mailPass"
    exit 1

exit 0