Skip to content

Instantly share code, notes, and snippets.

@tedivm
Last active November 24, 2024 05:19
Show Gist options
  • Save tedivm/9a26d4343784e426d1d276d9be547004 to your computer and use it in GitHub Desktop.
Save tedivm/9a26d4343784e426d1d276d9be547004 to your computer and use it in GitHub Desktop.
Github Backups
#!/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