Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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://$google_username@gmail.com/$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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement