Skip to content

Instantly share code, notes, and snippets.

@Joshix-1
Created August 22, 2020 20:36
Show Gist options
  • Save Joshix-1/561223a48df1b907093eab586500dbbd to your computer and use it in GitHub Desktop.
Save Joshix-1/561223a48df1b907093eab586500dbbd to your computer and use it in GitHub Desktop.
Script which downloads all repos of a github organization.
#!/bin/sh
#usage:
#chmod +x backup-github.sh
#./backup-github.sh organization_name
orgName=$1
if [ "$#" -eq "0" ]; then
echo No argument given. Please add the name of the organization as argument.
exit 2
fi
dirname="$orgName-github-backup-$(date "+%Y-%m-%d-%H-%M-%S")"
mkdir "$dirname"
cd $dirname
curl -H "Accept: application/vnd.github.nebula-preview+json" \
"https://api.github.com/orgs/$orgName/repos?type=all&per_page=100" \
| jq -r '.[] | .name' \
| while IFS= read projectName; do
curl -H "Accept: application/vnd.github.v3.raw" -L \
"https://api.github.com/repos/$orgName/$projectName/zipball" --output $projectName.zip
done
if [ -n "$(ls -A "$(pwd)" 2>/dev/null)" ]
then
echo Done! All files downloaded here: $(pwd);
else
echo Something went wrong. Please check the spelling of the organization or your internet connection.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment