Last active
June 14, 2017 13:12
-
-
Save j16r/16d59b34d8dab964158c73dc8ea4ed6d to your computer and use it in GitHub Desktop.
This is a bash script designed for backing up every repo in a github organization and encrypted the repo archives.
This file contains 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
#!/usr/bin/env bash -e | |
organization=$1 | |
if [ -z $organization ]; then | |
echo "Usage: $0 <organization>" | |
echo | |
echo "Make sure to specify \$GITHUB_API_TOKEN as an environment variable." | |
echo "Acquire one here: https://github.com/settings/tokens" | |
echo | |
echo "Also required \$BACKUP_PASSWORD_FILE containing a password for AES encryption." | |
echo | |
exit 1 | |
fi | |
mkdir -p repos/$organization archives/$organization | |
page=1 | |
while : | |
do | |
repos=`curl -s "https://api.github.com/orgs/$organization/repos?page=$page&per_page=100&access_token=$GITHUB_API_TOKEN" | jq '.[].ssh_url' | sed -e 's/^"//' -e 's/"$//'` | |
if [ -z "$repos" ]; then | |
break | |
fi | |
for ssh_url in $repos; | |
do | |
repo=`basename $ssh_url` | |
clone="repos/$organization/${repo%.*}" | |
archive="archives/$organization/${repo%.*}.tar" | |
bundle="$archive.aes" | |
if [ ! -e "$bundle" ]; then | |
git clone "$ssh_url" "$clone" | |
fi | |
done | |
page=$((page+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment