Skip to content

Instantly share code, notes, and snippets.

@MaZderMind
Created June 4, 2018 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MaZderMind/03172a88881e9fe14b40d66cc3310f5e to your computer and use it in GitHub Desktop.
Save MaZderMind/03172a88881e9fe14b40d66cc3310f5e to your computer and use it in GitHub Desktop.
backup-github-locally.sh
#!/bin/bash
set -xe
source /bulk/data/Drittsysteme/_env.sh
DIR="$BASEDIR/github"
NAMES_TMP=/tmp/github-repo-names.tmp
NAMES=/tmp/github-repo-names
PAGE=1
rm -f $NAMES
while true;
do
curl -s "https://api.github.com/users/MaZderMind/repos?type=all&per_page=100&page=$PAGE" | jq -r '.[] | .name' > $NAMES_TMP
COUNT=$(wc -l <$NAMES_TMP)
cat $NAMES_TMP >> $NAMES
if [ $COUNT -lt 100 ]; then
break
fi
PAGE=$((PAGE + 1))
done
rm $NAMES_TMP
COUNT=$(wc -l <$NAMES)
echo "syncing $COUNT repos"
cd $DIR
for name in $(cat $NAMES); do
if [ -d "$name.git" ]; then
cd "$name.git"
git fetch --progress -p
cd ..
else
git clone --mirror https://github.com/MaZderMind/$name.git
fi
done
echo 'notifying monitoring'
check backup-github-to-disks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment