Skip to content

Instantly share code, notes, and snippets.

@j16r
Created January 27, 2017 23:26
Show Gist options
  • Save j16r/025ffb1eb0203ce362fbd737504ae787 to your computer and use it in GitHub Desktop.
Save j16r/025ffb1eb0203ce362fbd737504ae787 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.
#!/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 --mirror "$ssh_url" "$clone"
tar -cvf "$archive" "$clone"
openssl aes-256-cbc -pass file:$BACKUP_PASSWORD_FILE -salt -in "$archive" -out "$bundle"
fi
done
page=$((page+1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment