Browse Source

Added the backup puller script

Samuel W. Flint 7 years ago
parent
commit
766bb5decc
1 changed files with 90 additions and 0 deletions
  1. 90 0
      pull-backups.sh

+ 90 - 0
pull-backups.sh

@@ -0,0 +1,90 @@
+#!/usr/bin/bash
+
+ORIGDIR=$(pwd)
+ANNEXFLAG=auto
+GCFLAG=false
+IDENTFLAG=false
+
+while getopts "haAlgi" opt ;
+do
+    case "$opt" in
+        h)
+            cat <<EOF >&2
+$0 [ -h | -a | -A | -l | -g | -i ]*
+
+-h	Show Help
+-a	Always sync annex
+-A	Do not sync annex
+-l	List Repositories
+-g	Run GC
+-i	Use an identity
+EOF
+            exit 1
+            ;;
+        a)
+            ANNEXFLAG=true
+            ;;
+        A)
+            ANNEXFLAG=false
+            ;;
+        l)
+            find . -type d -name '*.git'
+            exit
+            ;;
+        g)
+            GCFLAG=true
+            ;;
+        i)
+            IDENTFLAG=true
+            ;;
+    esac
+done
+
+if [[ ${IDENTFLAG} == "true" ]] ;
+then
+ ssh-add id_backup_drive
+fi
+
+find . -type d -name '*.git' | \
+while read -r repository
+do
+    cd "${repository}"
+    echo "In $(echo "${repository}" | sed -e 's/^\.\///g' -e 's/\.git$//g'):"
+
+    git fetch
+    
+    if [[ ${ANNEXFLAG} == "detect" ]] ;
+    then
+        if [[ -d "annex" ]] ;
+        then
+            echo Detected Git Annex
+            git annex sync
+            echo Annex Sync Complete
+        fi
+    elif [[ ${ANNEXFLAG} == "true" ]] ;
+    then
+        echo Forcing Git Annex
+        git annex sync
+        echo Annex Sync Complete
+    else
+        echo No Annex Sync
+    fi
+
+    if [[ ${GCFLAG} == "true" ]] ;
+    then
+        echo Performing GC/FSCK
+        git gc --aggressive
+        git fsck
+        echo GC/FSCK Complete
+    else
+        echo No GC/FSCK
+    fi
+
+    cd "${ORIGDIR}"
+    echo
+done
+
+if [[ ${IDENTFLAG} == "true" ]] ;
+then
+    ssh-add -d id_backup_drive
+fi