Created
March 2, 2022 10:55
-
-
Save g4s8/23d22cf5c865c06f747f805cfd9170db to your computer and use it in GitHub Desktop.
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
#!/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