-
-
Save cicorias/0af1babc49be58fead0dc1144d3d0df2 to your computer and use it in GitHub Desktop.
Shell script to back up all of an organization's GitHub repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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:[email protected]/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:[email protected]/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 [email protected]:$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