Skip to content

Instantly share code, notes, and snippets.

@mallond
Last active February 24, 2017 22:54
Show Gist options
  • Save mallond/a7be813115cce81ca092fde1b29187b3 to your computer and use it in GitHub Desktop.
Save mallond/a7be813115cce81ca092fde1b29187b3 to your computer and use it in GitHub Desktop.
GIT Download All
#!/bin/bash
#
# Crude script to backup an organisations repositories and its members forks.
#
# Name of organisation
ORG="change"
# Needed to talk to API
USER="change"
PASS="change"
API="https://api.github.com"
BACKUP_DIR="/data/github_backups"
TSTAMP=`date "+%Y%m%d-%H%M"`
GITCMD="git clone git@github.com:"
mkdir -p $BACKUP_DIR
# crudely get list of repositories in the organisation
echo "# getting list of repos..."
#curl -i https://api.github.com/users/KiCad/repos?per_page=100&page=2
REPOLIST=`curl -u $USER:$PASS ${API}/orgs/${ORG}/repos?per_page=2000 -q | grep name | awk -F': "' '{print $2}' | sed -e 's/",//g'`
# for each repository, backit and forks up
for REPO in $REPOLIST; do
# backup org repo
echo "Backing up ${ORG}/${REPO}"
TSTAMP=`date "+%Y%m%d-%H%M"`;
${GITCMD}${ORG}/${REPO}.git ${BACKUP_DIR}/${ORG}-${REPO}-${TSTAMP}.git
done
echo "Backup process completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment