Skip to content

Instantly share code, notes, and snippets.

@g4s8
Created March 2, 2022 10:55
Show Gist options
  • Save g4s8/23d22cf5c865c06f747f805cfd9170db to your computer and use it in GitHub Desktop.
Save g4s8/23d22cf5c865c06f747f805cfd9170db to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
cd ${0%/*}
if [[ -z "$1" ]]; then
echo "usage: $0 <orgname>"
exit 1
fi
ORG="$1"
echo "backup github.com/$ORG"
W=$(mktemp -d -p $PWD)
function cleanup {
echo "cleaning up"
rm -fr $W
}
trap cleanup EXIT
echo "created workdir $W"
function repo_names {
local org="$1"
curl -s "https://api.github.com/orgs/$org/repos?per_page=200" | \
jq -r '.[].name'
}
for repo in $(repo_names $ORG); do
echo "back up github.com/$ORG/$repo"
git clone https://github.com/$ORG/${repo}.git $W/backup/$repo
done
BACKUP="backup-$(date +%Y%m%d%H%M%S).tar.gz"
tar -czf ${BACKUP} -C $W ./backup
echo "created backup: $BACKUP"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment