Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Shell script to back up all of an organization's GitHub repos
#!/bin/sh
LOGIN=YOURLOGIN
TOKEN=YOURTOKEN
ORG=YOURORG
DONE=0
PAGE=0
# sample output:
# "total_private_repos": 50,
# "public_repos": 41,
NUMREPOS=$(curl -s "https://$LOGIN:$TOKEN@api.github.com/orgs/$ORG" | awk '
/public_repos/{t+=substr($2, 0, length($2)-1)}
/total_private_repos/{t+=substr($2, 0, length($2)-1)}
END{print t}')
while [ $DONE -lt $NUMREPOS ]; do
# Sample:
# "full_name": "VividCortex/wlr",
for repo in $(curl -s "https://$LOGIN:$TOKEN@api.github.com/orgs/$ORG/repos?type=all&page=$PAGE" | awk '/full_name/{print substr($2, 2, length($2)-3)}'); do
if [ ! -e "$HOME/repos/${repo#*/}" ]; then
(cd "$HOME/repos" && git clone git@github.com:$repo.git)
else
(cd "$HOME/repos/${repo#*/}" && git pull || echo "^^ $repo")
fi
DONE=$(($DONE + 1))
done
PAGE=$(($PAGE + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.