Last active
November 24, 2024 05:19
-
-
Save tedivm/9a26d4343784e426d1d276d9be547004 to your computer and use it in GitHub Desktop.
Github Backups
This file contains hidden or 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 | |
ORGANIZATIONS="tedivm tedious multi-py TerraformInDepth GitConsensus" | |
BACKUP_DIR="/storage-pool/github" | |
FLAGS="--source --no-archived" | |
GITHUB_PREFIX="https://github.com/" | |
# GITHUB_PREFIX="[email protected]:" | |
function repo_list() { | |
gh repo list $1 $FLAGS --json name --jq '.[] | .name' | sort -f -u | |
} | |
for org in $ORGANIZATIONS; do | |
repos=$(repo_list $org) | |
if [ ! -d "$BACKUP_DIR/$org" ]; then | |
mkdir -p "$BACKUP_DIR/$org" | |
fi | |
for repo in $repos; do | |
echo "Backing up $org/$repo" | |
if [ ! -d "$BACKUP_DIR/$org/$repo" ]; then | |
git clone --mirror "$GITHUB_PREFIX/$org/$repo" "$BACKUP_DIR/$org/$repo" | |
else | |
git -C "$BACKUP_DIR/$org/$repo" remote update | |
fi | |
done | |
done | |
if [ ! -d "$BACKUP_DIR/gists" ]; then | |
mkdir -p "$BACKUP_DIR/gists" | |
fi | |
for gist in $(gh gist list | tail -n +1 | cut -f1); do | |
echo "Backing up gist $gist" | |
if [ ! -d "$BACKUP_DIR/gists/$gist" ]; then | |
gh gist clone $gist "$BACKUP_DIR/gists/$gist" | |
else | |
git -C "$BACKUP_DIR/gists/$gist" pull | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment