#!/bin/bash # B1 備援三件套之二:每日 git bundle 備份(de-Gitea brief B1) # 對本機所有 repo:git fsck 驗完整 → git bundle 打包全部 refs → 存 ~/Backups/git-bundles/ # R2 上傳段:等 youlin 帳號 R2 開通後補(TODO 標記處)。保留最近 7 份。 set -uo pipefail ROOT="/Users/youlinhsieh/Documents/tech_projects/InkStoneCo" DEST="$HOME/Backups/git-bundles" STAMP=$(date +%Y%m%d) KEEP=7 mkdir -p "$DEST" REPOS=(. matrix/arcrun matrix/arcrun-components matrix/arcrun-gui matrix/arcrun-mcp matrix/inkstone-admin matrix/kbdb-graph-plugin matrix/kbdb-ingest-plugin products/arcrun-rag products/dev-finally-click products/finally-click products/u6u-studio polaris/AI-Meka polaris/OpenHarness polaris/mira arcrun_harness) fail=0 for r in "${REPOS[@]}"; do dir="$ROOT/$r" [ -d "$dir/.git" ] || { echo "SKIP $r (no .git)"; continue; } name=$(basename "$(cd "$dir" && pwd)") [ "$r" = "." ] && name="InkStoneCo" if ! git -C "$dir" fsck --no-progress --no-dangling >/dev/null 2>&1; then echo "❌ FSCK FAIL $r"; fail=1; continue fi out="$DEST/${name}-${STAMP}.bundle" if git -C "$dir" bundle create "$out" --all >/dev/null 2>&1; then echo "✅ $name $(du -h "$out" | cut -f1)" else echo "❌ BUNDLE FAIL $r"; fail=1 fi # 保留最近 KEEP 份 ls -t "$DEST/${name}-"*.bundle 2>/dev/null | tail -n +$((KEEP+1)) | xargs rm -f 2>/dev/null done # TODO(R2):youlin 帳號 R2 開通後,在此加 rclone/wrangler 上傳 $DEST 至獨立 bucket(與 git server 不同桶) echo "---" echo "bundles at $DEST" exit $fail