Skip to content

Instantly share code, notes, and snippets.

@SharkyRawr
Created April 29, 2018 19:01
Show Gist options
  • Save SharkyRawr/9c9e24bbe960b50fe8005a7d5bd4c5c8 to your computer and use it in GitHub Desktop.
Save SharkyRawr/9c9e24bbe960b50fe8005a7d5bd4c5c8 to your computer and use it in GitHub Desktop.
B2 full-system backup using duplicity with gnupg
#! /bin/bash -e
# pro-tip: This script is designed to be called from cron.daily and will only output a short report,
# which can be mailed to you if you add an email for root in /etc/aliases -
# or it can be called directly: './duplicity_backup.sh -vi' - which will show the changes for each file
DUPLICITY="/usr/local/bin/duplicity"
KEY="your-gnupg-keyid-here"
DEST="b2://your-b2-account-id:your-b2-application-key@your-b2-bucket/"
# Test if duplicity is installed or fail
test -x "$DUPLICITY" || exit -1
# Pull the PASSPHRASE variable from /root/.duplicity in to our environment, it contains the GnuPG secret key password.
# The file should simply contain: "PASSPHRASE=yourpassword" -- don't forget to trust this key "ultimatively"
. /root/.duplicity
export PASSPHRASE
# This will create a full backup once a month, up to 6 will be kept, everything else is incremental.
# You should read the duplicity man page http://duplicity.nongnu.org/duplicity.1.html and modify this script to your needs.
"$DUPLICITY" --exclude-device-files --exclude-other-filesystems -vn $1 --asynchronous-upload --full-if-older-than 1M --exclude /dev/ --exclude /sys/ --exclude /proc/ --exclude /run/ --exclude /tmp/ --exclude /mnt/ --encrypt-sign-key $KEY / "$DEST"
"$DUPLICITY" -vn $1 remove-all-but-n-full 6 --force "$DEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment