phoebus_os/scripts/backup-git.sh
Phoebus 83368f774c
Some checks are pending
ci / test (push) Waiting to run
feat(git): add session context, host doctor, ADRs and git hygiene
Adds scripts/context.sh + 'make context' (one-screen session briefing),
scripts/doctor.sh + 'make doctor' (host prerequisites), docs/HANDOFF.md
(rolling cross-session note), docs/adr/ (BLS, desktop profile, keyring, Rust),
.githooks/commit-msg (Conventional Commits), .gitattributes, scripts/backup-git.sh
+ 'make backup', and a Forgejo Actions CI workflow. Updates AGENTS.md reading
order/work loop and DEVELOPMENT.md.
2026-09-20 02:36:32 -07:00

31 lines
864 B
Bash
Executable file

#!/usr/bin/env bash
# Make a self-contained bundle of the whole repository (all branches and tags).
#
# Useful because the only remote is a single VPS. Store bundles off-box.
#
# scripts/backup-git.sh [DEST_DIR] (default ~/backups/phoebus)
#
# Keeps the 10 newest bundles. Restore with:
# git clone /path/to/phoebus-<stamp>.bundle phoebus_os
set -euo pipefail
root="$(git rev-parse --show-toplevel)"
cd "$root"
dest="${1:-$HOME/backups/phoebus}"
mkdir -p "$dest"
stamp="$(date -u +%Y%m%dT%H%M%SZ)"
bundle="$dest/phoebus-${stamp}.bundle"
git bundle create "$bundle" --all >/dev/null
git bundle verify "$bundle" >/dev/null
printf 'bundle: %s (%s)\n' "$bundle" "$(du -h "$bundle" | cut -f1)"
# Retain the 10 most recent bundles.
mapfile -t old < <(ls -1t "$dest"/phoebus-*.bundle 2>/dev/null | tail -n +11)
((${#old[@]})) && rm -f "${old[@]}"
exit 0