pull-backups.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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} == "auto" ]] ;
  50. then
  51. if [[ -d "annex" ]] ;
  52. then
  53. echo Detected Git Annex
  54. git annex sync
  55. echo Annex Sync Complete
  56. else
  57. echo No Annex Sync
  58. fi
  59. elif [[ ${ANNEXFLAG} == "true" ]] ;
  60. then
  61. echo Forcing Git Annex
  62. git annex sync
  63. echo Annex Sync Complete
  64. else
  65. echo No Annex Sync
  66. fi
  67. if [[ ${GCFLAG} == "true" ]] ;
  68. then
  69. echo Performing GC/FSCK
  70. git gc --aggressive
  71. git fsck
  72. echo GC/FSCK Complete
  73. else
  74. echo No GC/FSCK
  75. fi
  76. cd "${ORIGDIR}"
  77. echo
  78. done
  79. if [[ ${IDENTFLAG} == "true" ]] ;
  80. then
  81. ssh-add -d id_backup_drive
  82. fi