Date created: Tuesday, April 3, 2018 5:17:38 PM. Last modified: Thursday, August 2, 2018 9:03:12 AM

Backup Github

#!/bin/bash


function repo() {

    curl --silent -L https://github.com/jwbensley/$1/archive/master.zip -o $bdir/$1-$(date '+%Y-%m-%d').zip

}


function wiki() {

    git clone https://github.com/jwbensley/$1.wiki.git $bdir/wiki

    zip -r $bdir/$1-$(date '+%Y-%m-%d')-wiki.zip $bdir/wiki/

    rm -rf $bdir/wiki

}


function issues() {

    curl --silent -L https://api.github.com/repos/jwbensley/$1/issues?state=all -o $bdir/issues.json

    curl --silent -L https://api.github.com/repos/jwbensley/$1/issues/comments -o $bdir/comments.json

    curl --silent -L https://api.github.com/repos/jwbensley/$1/labels -o $bdir/labels.json

    zip $bdir/$1-$(date '+%Y-%m-%d')-issues.zip $bdir/issues.json $bdir/comments.json $bdir/labels.json

    rm -f $bdir/issues.json $bdir/comments.json $bdir/labels.json

}


declare -a repos
repos[0]="Etherate"
repos[1]="EtherateMT"

bdir="/media/bensley/9TB-Array/Backup/github/$(date '+%Y-%m-%d')"
mkdir -p $bdir

if [[ $? -ne 0 ]]
then
    echo "Couldn't create backup directory: $bdir" 
    echo "Quitting."
    exit 1
fi


for (( i=0; i < ${#repos[@]}; i++ ))
do

  echo "Backing up: ${repos[$i]}..."
  repo ${repos[$i]}
  wiki ${repos[$i]}
  issues ${repos[$i]}

done

Previous page: Bash Notes
Next page: Backups: Grandfather-father-son