Skip to content

Latest commit

 

History

History

github-backup

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

github-backup

Mirrors of the user's GitHub estate, kept on the laptop, updatable forever, with a dedicated GitHub App for rate limits and webhook freshness.

This directory is the canonical home of the whole system — scripts, systemd units, the webhook Worker source, the config schema, and the docs. Nothing load-bearing lives only on a machine: a fresh laptop plus this repo plus Bitwarden rebuilds everything (see docs/RUNBOOK.md).

Layout of the backup tree (~/backups/github on the laptop)

<owner>/<repo>.git     bare mirrors (git clone --mirror: all branches+tags)
plan.json              generated by reconcile.py from config.json + GitHub
MANIFEST.json          generated: what exists, sizes, HEADs, last fetch
FAMILIES.md            generated: fork-family anchors (alternates pool)
state.json             generated: fetch/drain bookkeeping
clone-status.jsonl     clone pass log (append-only)
fetch.log              fetch failures (append-only)
reconcile-YYYY-MM-DD.md  weekly sweep reports

Design

  • Proposed hosted recovery home and failure/recovery analysis (#14964): Backup plane hosted recovery design. This is a design record, not a claim that hosted schedules are live.

  • Scope (config.json): all non-fork repos + forks under 500 MB across 18 owners, plus force-includes; 7 passive giants are excluded by the user's ruling 2026-10-31 (upstream is their backup). Edsebooks (HTTP 451) and vertexinc (SAML) are recorded gaps, not silent misses.

  • Pool/dedupe: forks sharing an upstream are cloned with git alternates against a family anchor, so e.g. the three nixpkgs copies store one shared history plus deltas. Members are NOT self-contained — the tree is the unit. Cold copies use git bundle (materializes objects), never a bare tar of a member .git.

  • Freshness: a dedicated GitHub App (developing-today-backup, metadata:read + contents:read, push+repository events) sends webhooks to the Cloudflare Worker in worker/; the Worker verifies the HMAC and queues events in KV; the laptop drains the queue every 5 min (per-repo coalescing 15 min) and fetches just those mirrors.

  • Correctness floor: a weekly reconciliation sweep re-inventories GitHub, diffs against the tree, clones new repos matching the tier rules, and flags new giant forks as pending-drew-review instead of cloning them. Webhooks may be missed; the sweep may not.

  • Daily fetch: every mirror is fetched daily regardless (12 h coalescing), so even total webhook loss degrades to daily freshness.

  • Rate limits: the App's installation tokens have their own pool (5,000/hr base, scaling with installed repos toward 12,500/hr), separate from the user's personal token that the fleet uses.

  • Secrets: by name only, in Bitwarden Secrets Manager — see config.json → app.bitwarden_secret_names. Values never enter this repo, the backup tree, or chat.

  • Cold-bundle drill: bin/bundle_cold.py --repo OWNER/REPO creates a self-contained Git bundle from one planned, valid mirror and publishes it under cold-bundles/ only after an empty-repository verify and clone-HEAD comparison. bin/bundle_r2.py --repo OWNER/REPO --bucket NAME repeats that drill, uploads the bundle through the existing r2bak rclone remote, then downloads and compares the remote bytes. It requires the caller to configure r2bak from runtime credentials (the laptop backup scripts use Bitwarden by secret name). bin/bundle_r2_all.py attempts each of the four fleet repos in the plan, and the user systemd github-backup-r2.timer runs it daily. This does not provision a bucket or provide freshness/lag reporting.

  • Plain Git mirror: bin/plain_mirror.py --repo OWNER/REPO pushes every branch and tag from a planned local mirror to the corresponding pre-created developing-today/<repo>-mirror GitHub repository. It prunes deleted branches/tags and verifies destination refs against the source. The command does not create repositories or provision credentials; targets must exist before the first run.

  • Hosted publisher inputs: bin/hosted_seed_fleet.py --root PATH rebuilds the four fleet source mirrors directly from GitHub under a fresh runner-local root and writes plan.json only after all four bare mirrors validate. It does not read the laptop backup tree or reuse local alternates; a hosted publisher workflow can consume the resulting root with the existing plain_mirror_all.py, bundle_r2_all.py, and rehost_publish_all.py drivers.

System contract — a mirror is what it can prove (design #3282)

No surface of this system may report coverage, success, or health that the underlying mirrors, records, or inventory do not support. The seven rules, in operator language:

  1. Validity is resolvability. A mirror counts as present only when it is bare AND its HEAD resolves to a commit (ghb_common.valid_mirror). A bare directory with no refs is a skeleton, not a backup. Planned repos are never legitimately empty (zero-commit repos are excluded from the plan), so there is no emptiness exception.
  2. Destinations have four states, each with a disposition. Absent → clone. Valid → skip (never deleted or re-cloned). Skeleton (bare, unresolvable HEAD, zero refs) → remove and clone; removal provably loses nothing. Debris (exists, not a bare skeleton, not valid) → preserved and reported, never silently deleted — it may hold the only copy of transferred objects; clone_all fails loudly for that repo instead.
  3. Every attempt ends in a recorded outcome. A per-repo fetch never raises out of the run: a timeout, a failure, and a missing mirror are all recorded (ok / fail / missing) in state, fetch.log, and the run summary, by the one recorder path the daily loop and the webhook drainer share.
  4. An event is acked only when its fetch landed. The drainer acks a planned repo's webhook event only on a recorded ok; on fail / missing the event stays queued for the next drain and the coalescing stamp advances only on ok.
  5. The alarm is a streak of unavailable days. Failures, timeouts, and missing mirrors all record the day against the repo; a success clears the record. Three consecutive unavailable days make the daily run exit non-zero — that exit code is the alarm systemd watches.
  6. State is written atomically, loaded tolerantly, only through ghb_common. Generated state (plan.json, state.json, MANIFEST.json, FAMILIES.md, reconcile reports) is written via temp-file + fsync + os.replace with a last-good copy kept; a torn file loads its last-good copy with a loud warning instead of crashing every reader. The two state.json writers (daily fetch, 5-minute drainer) hold the shared state.lock flock across their whole read-modify-write cycle.
  7. A failed owner keeps its plan. An owner whose inventory fails (null repositoryOwner, SAML block, API error) is an error, never an empty owner: reconcile retains that owner's previously planned entries, marks them retained in the report, and still exits non-zero.

Components

Path What
config.json owners, tier rules, exclusions, gaps, App/Worker names
bin/ghb_common.py shared inventory + plan builder
bin/clone_all.py resumable parallel initial clone (from plan.json)
bin/fetch_mirrors.py daily fetch / targeted fetch of named repos
bin/reconcile.py weekly sweep: inventory → plan → clone new → report
bin/manifest.py regenerate MANIFEST.json + FAMILIES.md
bin/drain_queue.py drain Worker queue, fetch pushed repos
bin/app_setup.py App manifest flow, credential storage, install report
worker/ Cloudflare Worker webhook receiver (wrangler)
systemd/ laptop user units + timers + installer
docs/RUNBOOK.md copy-paste operations: install, add org, upgrade, DR
tests/ regression tests (plain python3, no deps; run by the github-backup tests workflow, #5937)