Advertisement
Guest User

Untitled

a guest
Jan 1st, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # directories to be included, space separated
  4. SOURCE="/home/chewie /etc"
  5. # directories to be excluded, space separated
  6. IGNORE="/home/chewie/Downloads /home/chewie/Steam"
  7. DRIVE_FOLDER="duplicity-backup"
  8. LOGFILE=/home/chewie/duplicity.log
  9. # set email to receive a backup report
  10. EMAIL=""
  11.  
  12. get_credentials() {
  13.  
  14. gpg_pass="$(zenity --password --title 'duplicity - GnuPG passphrase')"
  15. google_credentials="$(zenity --password --username --title 'duplicity - Google Drive password')"
  16.  
  17. case $? in
  18. 0)
  19. google_username=$(echo $google_credentials | cut -d'|' -f1)
  20. google_password=$(echo $google_credentials | cut -d'|' -f2)
  21. ;;
  22. 1)
  23. echo "Stop login.";;
  24. -1)
  25. echo "An unexpected error has occurred.";;
  26. esac
  27.  
  28. DRIVE_URL=gdocs://$google_username@gmail.com/$DRIVE_FOLDER
  29.  
  30. export PASSPHRASE="$gpg_pass"
  31. export FTP_PASSWORD="$google_password"
  32. }
  33.  
  34. backup() {
  35. INCLUDE=""
  36. for CDIR in $SOURCE
  37. do
  38. TMP=" --include ${CDIR}"
  39. INCLUDE=${INCLUDE}${TMP}
  40. done
  41. EXCLUDE=""
  42. for CDIR in $IGNORE
  43. do
  44. TMP=" --exclude ${CDIR}"
  45. EXCLUDE=${EXCLUDE}${TMP}
  46. done
  47. # perform an incremental backup to root, exclude directories, include directories, exclude everything else, / as reference.
  48. duplicity -v8 --asynchronous-upload --full-if-older-than 30D $EXCLUDE $INCLUDE --exclude '**' / $DRIVE_URL | tee $LOGFILE
  49. if [ -n "$EMAIL" ]; then
  50. mail -s "backup report" $EMAIL < $LOGFILE
  51. fi
  52. }
  53.  
  54. list() {
  55. duplicity list-current-files $DRIVE_URL
  56. }
  57.  
  58. restore() {
  59. if [ $# = 2 ]; then
  60. duplicity restore --file-to-restore $1 $DRIVE_URL $2
  61. else
  62. duplicity restore --file-to-restore $1 --time $2 $DRIVE_URL $3
  63. fi
  64. }
  65.  
  66. status() {
  67. duplicity collection-status $DRIVE_URL
  68. }
  69.  
  70. if [ "$1" = "backup" ]; then
  71. get_credentials
  72. backup
  73. elif [ "$1" = "list" ]; then
  74. get_credentials
  75. list
  76. elif [ "$1" = "restore" ]; then
  77. get_credentials
  78. if [ $# = 3 ]; then
  79. restore $2 $3
  80. else
  81. restore $2 $3 $4
  82. fi
  83. elif [ "$1" = "status" ]; then
  84. get_credentials
  85. status
  86. else
  87. echo "
  88. duptools - manage duplicity backup
  89.  
  90. USAGE:
  91.  
  92. ./duptools.sh backup
  93. ./duptools.sh list
  94. ./duptools.sh status
  95. ./duptools.sh restore file [time] dest
  96. "
  97. fi
  98.  
  99. unset PASSPHRASE
  100. unset FTP_PASSWORD
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement