backup 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/env bash
  2. log_dir="$HOME/var/"
  3. log_file="${log_dir}duplicity.log"
  4. gpg_key="018FAC02"
  5. dir="$HOME"
  6. backend="s3://s3.amazonaws.com/tylercipriani-backup/$(hostname -s)"
  7. backend_mail="s3://s3.amazonaws.com/tylercipriani-backup/Mail"
  8. backend_pictures="s3://s3.amazonaws.com/tylercipriani-backup/Pictures"
  9. getnetrc="$HOME"/bin/getnetrc
  10. show_help() {
  11. cat<<DOC
  12. Usage: $(basename $0) (--all|--pictures|--other|--mail)
  13. DOC
  14. }
  15. get_creds() {
  16. export AWS_ACCESS_KEY_ID=$($getnetrc duplicity login)
  17. export AWS_SECRET_ACCESS_KEY=$($getnetrc duplicity)
  18. }
  19. backup_pictures() {
  20. printf "Pictures\n---\n" >> "$log_file"
  21. duplicity \
  22. --verbosity info \
  23. --encrypt-key="$gpg_key" \
  24. --sign-key="$gpg_key" \
  25. --full-if-older-than 7D \
  26. --asynchronous-upload \
  27. --volsize=100 \
  28. --log-file "$log_file" \
  29. --include "$HOME/Pictures" \
  30. --exclude "**" \
  31. "$dir" "$backend_pictures"
  32. }
  33. backup_mail() {
  34. printf "Mail\n---\n" >> "$log_file"
  35. duplicity \
  36. --verbosity info \
  37. --encrypt-key="$gpg_key" \
  38. --sign-key="$gpg_key" \
  39. --full-if-older-than 7D \
  40. --asynchronous-upload \
  41. --volsize=100 \
  42. --log-file "$log_file" \
  43. --include "$HOME/Mail" \
  44. --exclude "**" \
  45. "$dir" "$backend_mail"
  46. }
  47. backup_other() {
  48. printf "Everything else\n---\n" >> "$log_file"
  49. # http://askubuntu.com/a/40997
  50. duplicity \
  51. --verbosity info \
  52. --encrypt-key="$gpg_key" \
  53. --sign-key="$gpg_key" \
  54. --full-if-older-than 7D \
  55. --asynchronous-upload \
  56. --volsize=100 \
  57. --log-file "$log_file" \
  58. --include "$HOME/.aws" \
  59. --include "$HOME/.backups" \
  60. --include "$HOME/.batterytrack.log" \
  61. --include "$HOME/.config" \
  62. --include "$HOME/.cups" \
  63. --include "$HOME/.dotfiles" \
  64. --include "$HOME/.emacs.d" \
  65. --include "$HOME/.marks" \
  66. --include "$HOME/.muh_history" \
  67. --include "$HOME/.netrc" \
  68. --include "$HOME/.password-store" \
  69. --include "$HOME/.zotero" \
  70. --include "$HOME/ArduinoProjects" \
  71. --include "$HOME/Backups" \
  72. --include "$HOME/Documents" \
  73. --include "$HOME/Music" \
  74. --include "$HOME/notebooks" \
  75. --include "$HOME/Projects" \
  76. --include "$HOME/public_html" \
  77. --include "$HOME/Videos" \
  78. --include "$HOME/Webcam" \
  79. --exclude "**cache/**" \
  80. --exclude "**logs/**" \
  81. --exclude "**" \
  82. "$dir" "$backend"
  83. }
  84. backup_everything() {
  85. backup_pictures
  86. backup_mail
  87. backup_other
  88. }
  89. cleanup() {
  90. duplicity \
  91. remove-older-than 1M \
  92. "$backend"
  93. duplicity \
  94. remove-older-than 1M \
  95. "$backend_pictures"
  96. duplicity \
  97. remove-older-than 1M \
  98. "$backend_mail"
  99. unset AWS_ACCESS_KEY_ID
  100. unset AWS_SECRET_ACCESS_KEY
  101. }
  102. main() {
  103. if (($# < 1)) || (($# > 1)); then
  104. show_help
  105. exit 1
  106. fi
  107. get_creds
  108. mkdir -p "$log_dir"
  109. if [ -f "$log_file" ]; then
  110. cat /dev/null > "$log_file"
  111. fi
  112. case $1 in
  113. other|--other|-o)
  114. backup_other
  115. ;;
  116. mail|--mail|-m)
  117. backup_mail
  118. ;;
  119. pic*|--pic*|-p)
  120. backup_pictures
  121. ;;
  122. all|--all|-a)
  123. backup_everything
  124. ;;
  125. *)
  126. show_help
  127. cleanup
  128. exit 1
  129. ;;
  130. esac
  131. cleanup
  132. }
  133. main "$@"