Skip to content

Instantly share code, notes, and snippets.

@vibragiel
Forked from tsileo/duptools.sh
Last active August 25, 2017 21:46
Show Gist options
  • Save vibragiel/4484803 to your computer and use it in GitHub Desktop.
Save vibragiel/4484803 to your computer and use it in GitHub Desktop.
An example on how to use duplicity to perform encrypted incremental backups on Google Drive. Changes over tileo's original script: Google Drive instead of S3 as backend storage. Zenity dialogs to ask for credentials. IGNORE variable to exclude a list of directories from the backup. Verbosity raised to level 8. Activated asynchronous uploads.
#!/bin/bash
# directories to be included, space separated
SOURCE="/home/chewie /etc"
# directories to be excluded, space separated
IGNORE="/home/chewie/Downloads /home/chewie/Steam"
DRIVE_FOLDER="duplicity-backup"
LOGFILE=/home/chewie/duplicity.log
# set email to receive a backup report
EMAIL=""
get_credentials() {
gpg_pass="$(zenity --password --title 'duplicity - GnuPG passphrase')"
google_credentials="$(zenity --password --username --title 'duplicity - Google Drive password')"
case $? in
0)
google_username=$(echo $google_credentials | cut -d'|' -f1)
google_password=$(echo $google_credentials | cut -d'|' -f2)
;;
1)
echo "Stop login.";;
-1)
echo "An unexpected error has occurred.";;
esac
DRIVE_URL=gdocs://[email protected]/$DRIVE_FOLDER
export PASSPHRASE="$gpg_pass"
export FTP_PASSWORD="$google_password"
}
backup() {
INCLUDE=""
for CDIR in $SOURCE
do
TMP=" --include ${CDIR}"
INCLUDE=${INCLUDE}${TMP}
done
EXCLUDE=""
for CDIR in $IGNORE
do
TMP=" --exclude ${CDIR}"
EXCLUDE=${EXCLUDE}${TMP}
done
# perform an incremental backup to root, exclude directories, include directories, exclude everything else, / as reference.
duplicity -v8 --asynchronous-upload --full-if-older-than 30D $EXCLUDE $INCLUDE --exclude '**' / $DRIVE_URL | tee $LOGFILE
if [ -n "$EMAIL" ]; then
mail -s "backup report" $EMAIL < $LOGFILE
fi
}
list() {
duplicity list-current-files $DRIVE_URL
}
restore() {
if [ $# = 2 ]; then
duplicity restore --file-to-restore $1 $DRIVE_URL $2
else
duplicity restore --file-to-restore $1 --time $2 $DRIVE_URL $3
fi
}
status() {
duplicity collection-status $DRIVE_URL
}
if [ "$1" = "backup" ]; then
get_credentials
backup
elif [ "$1" = "list" ]; then
get_credentials
list
elif [ "$1" = "restore" ]; then
get_credentials
if [ $# = 3 ]; then
restore $2 $3
else
restore $2 $3 $4
fi
elif [ "$1" = "status" ]; then
get_credentials
status
else
echo "
duptools - manage duplicity backup
USAGE:
./duptools.sh backup
./duptools.sh list
./duptools.sh status
./duptools.sh restore file [time] dest
"
fi
unset PASSPHRASE
unset FTP_PASSWORD
@mihalu
Copy link

mihalu commented Jan 8, 2016

What version of duplicity are you using? Does it work after ClientLogin deprecation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment