#!/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-.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