pull-backups.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/usr/bin/bash
  2. ORIGDIR=$(pwd)
  3. ANNEXFLAG=auto
  4. GCFLAG=false
  5. IDENTFLAG=false
  6. while getopts "haAlgi" opt ;
  7. do
  8. case "$opt" in
  9. h)
  10. cat <<EOF >&2
  11. $0 [ -h | -a | -A | -l | -g | -i ]*
  12. -h Show Help
  13. -a Always sync annex
  14. -A Do not sync annex
  15. -l List Repositories
  16. -g Run GC
  17. -i Use an identity
  18. EOF
  19. exit 1
  20. ;;
  21. a)
  22. ANNEXFLAG=true
  23. ;;
  24. A)
  25. ANNEXFLAG=false
  26. ;;
  27. l)
  28. find . -type d -name '*.git'
  29. exit
  30. ;;
  31. g)
  32. GCFLAG=true
  33. ;;
  34. i)
  35. IDENTFLAG=true
  36. ;;
  37. esac
  38. done
  39. if [[ ${IDENTFLAG} == "true" ]] ;
  40. then
  41. ssh-add id_backup_drive
  42. fi
  43. find . -type d -name '*.git' | \
  44. while read -r repository
  45. do
  46. cd "${repository}"
  47. echo "In $(echo "${repository}" | sed -e 's/^\.\///g' -e 's/\.git$//g'):"
  48. git fetch
  49. if [[ ${ANNEXFLAG} == "detect" ]] ;
  50. then
  51. if [[ -d "annex" ]] ;
  52. then
  53. echo Detected Git Annex
  54. git annex sync
  55. echo Annex Sync Complete
  56. fi
  57. elif [[ ${ANNEXFLAG} == "true" ]] ;
  58. then
  59. echo Forcing Git Annex
  60. git annex sync
  61. echo Annex Sync Complete
  62. else
  63. echo No Annex Sync
  64. fi
  65. if [[ ${GCFLAG} == "true" ]] ;
  66. then
  67. echo Performing GC/FSCK
  68. git gc --aggressive
  69. git fsck
  70. echo GC/FSCK Complete
  71. else
  72. echo No GC/FSCK
  73. fi
  74. cd "${ORIGDIR}"
  75. echo
  76. done
  77. if [[ ${IDENTFLAG} == "true" ]] ;
  78. then
  79. ssh-add -d id_backup_drive
  80. fi