From 5c5ca2fcecf2285af792c263c59a153b9d854ad4 Mon Sep 17 00:00:00 2001 From: Micha Date: Tue, 26 May 2026 20:16:19 +0200 Subject: [PATCH] Fix Gitea bundle mirror host run --- ops/borg-ui/scripts/README.md | 2 +- ops/borg-ui/scripts/gitea-bundle-mirror.sh | 26 +++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ops/borg-ui/scripts/README.md b/ops/borg-ui/scripts/README.md index e604a6e..99e798e 100644 --- a/ops/borg-ui/scripts/README.md +++ b/ops/borg-ui/scripts/README.md @@ -29,7 +29,7 @@ secret backup material. - The script is written for host execution where `docker` is available. - `gitea-bundle-mirror.sh` additionally expects host access to the Gitea bare - repositories under `/mnt/user/services/gitea/git/repositories`. + repositories under `/mnt/user/services/gitea/data/git/repositories`. - It does not assume Backrest. - It keeps only the latest dump set because Borg itself provides history. diff --git a/ops/borg-ui/scripts/gitea-bundle-mirror.sh b/ops/borg-ui/scripts/gitea-bundle-mirror.sh index 0ece5aa..44e86df 100644 --- a/ops/borg-ui/scripts/gitea-bundle-mirror.sh +++ b/ops/borg-ui/scripts/gitea-bundle-mirror.sh @@ -5,9 +5,9 @@ set -eu # Gitea repository so a Gitea outage does not make repo bootstrap depend on the # Gitea application database. -SOURCE_ROOT="${SOURCE_ROOT:-/mnt/user/services/gitea/git/repositories}" +SOURCE_ROOT="${SOURCE_ROOT:-/mnt/user/services/gitea/data/git/repositories}" BUNDLE_ROOT="${BUNDLE_ROOT:-/mnt/user/backups/git-bundles/gitea}" -TMP_ROOT="${TMP_ROOT:-$BUNDLE_ROOT/.tmp}" +TMP_ROOT="${TMP_ROOT:-/mnt/cache/tmp/gitea-bundle-mirror}" REPORT_PATH="${REPORT_PATH:-$BUNDLE_ROOT/latest-report.md}" MANIFEST_PATH="${MANIFEST_PATH:-$BUNDLE_ROOT/manifest.tsv}" RUN_ID="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" @@ -63,27 +63,37 @@ main() { details="$run_tmp/details.txt" : > "$details" - find "$SOURCE_ROOT" -type d -name '*.git' | sort | while IFS= read -r repo; do + repo_list="$run_tmp/repos.txt" + find "$SOURCE_ROOT" -type d -name '*.git' | sort > "$repo_list" + + while IFS= read -r repo; do total=$((total + 1)) - if [ "$(git -C "$repo" rev-parse --is-bare-repository 2>/dev/null || true)" != "true" ]; then + if [ "$(git --git-dir="$repo" rev-parse --is-bare-repository 2>/dev/null || true)" != "true" ]; then skipped=$((skipped + 1)) printf 'SKIP\t%s\tnot a bare repository\n' "$repo" >> "$details" + printf '%s\t%s\t%s\t%s\n' "$total" "$bundled" "$skipped" "$failed" > "$run_tmp/counts" continue fi target="$(bundle_target_for_repo "$repo")" target_dir="$(dirname "$target")" tmp="$run_tmp/$(basename "$target").tmp" + target_tmp="$target_dir/.$(basename "$target").tmp" mkdir -p "$target_dir" rel="${repo#$SOURCE_ROOT/}" log "Bundling $rel" - if git -C "$repo" bundle create "$tmp" --all >/dev/null 2>&1 && - git -C "$repo" bundle verify "$tmp" >/dev/null 2>&1; then + if git --git-dir="$repo" bundle create "$tmp" --all >/dev/null 2>&1 && + git --git-dir="$repo" bundle verify "$tmp" >/dev/null 2>&1; then chmod 600 "$tmp" - mv "$tmp" "$target" + rm -f "$target_tmp" + cp "$tmp" "$target_tmp" + chmod 600 "$target_tmp" + mv "$target_tmp" "$target" + rm -f "$tmp" + git --git-dir="$repo" bundle verify "$target" >/dev/null 2>&1 ( cd "$target_dir" sha256sum "$(basename "$target")" > "$(basename "$target").sha256.tmp" @@ -101,7 +111,7 @@ main() { fi printf '%s\t%s\t%s\t%s\n' "$total" "$bundled" "$skipped" "$failed" > "$run_tmp/counts" - done + done < "$repo_list" if [ -f "$run_tmp/counts" ]; then IFS="$(printf '\t')" read -r total bundled skipped failed < "$run_tmp/counts"