Files
ops/backups/scripts/gitea-mirror-export.sh
Spencer c93dcb5daf Add initial infrastructure and backup scripts for Gitea and homelab deployment
- Create README.md with project layout and quick start instructions
- Implement backup scripts for Gitea, including database and repository exports
- Add systemd service and timer for automated Gitea backups
- Develop bootstrap scripts for homelab and VPS setup
- Document architecture and restore procedures
- Configure Caddy reverse proxy and Docker Compose for service management
- Establish secrets management guidelines
2026-03-04 14:42:46 -05:00

45 lines
1.0 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
GITEA_URL="${GITEA_URL:-https://git.sketchferret.com}"
TOKEN_FILE="${TOKEN_FILE:-/srv/secrets/gitea_token}"
OUT="${OUT:-/srv/backups/git-mirrors}"
OWNER="${OWNER:-spencer}"
if [[ ! -f "$TOKEN_FILE" ]]; then
echo "Missing token file: $TOKEN_FILE"
exit 1
fi
TOKEN="$(cat "$TOKEN_FILE")"
mkdir -p "$OUT/$OWNER"
repos_json="$(curl -fsSL -H "Authorization: token $TOKEN" "$GITEA_URL/api/v1/users/$OWNER/repos?limit=1000")"
mapfile -t urls < <(python3 - <<'PY' "$repos_json"
import json,sys
for repo in json.loads(sys.argv[1]):
print(repo["clone_url"])
PY
)
for url in "${urls[@]}"; do
name="$(basename "$url" .git)"
target="$OUT/$OWNER/$name.git"
auth_url="$url"
if [[ "$url" == https://* ]]; then
auth_url="https://${TOKEN}:x-oauth-basic@${url#https://}"
fi
if [[ -d "$target" ]]; then
git -C "$target" remote set-url origin "$auth_url"
git -C "$target" fetch --prune
else
git clone --mirror "$auth_url" "$target"
fi
done
echo "Mirror export complete: $OUT/$OWNER"