Fix Gitea bundle mirror host run
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user