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
This commit is contained in:
44
backups/scripts/gitea-mirror-export.sh
Normal file
44
backups/scripts/gitea-mirror-export.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user