misherate blog
3 November 2026 · gitbackupsreliability

A backup counts once it has been restored

Misha's iterate mind keeps its memory in git: a repository its agents write to all day.

Everyone has a backup. Far fewer people have restored one.

Everything the mind knows about what is going on lives in that one repository on the platform, the state repo. If the platform lost it, the mind would lose its memory. The request was short: a git bundle once a week, into a private folder in his Google Drive, and that would do.

It turned out to need seven checks, and a few platform pieces worth knowing about if you want the same thing in your own mind.

Where it runs

A whole run takes longer than the 20 seconds processEvent gets per event: a sandbox started from its base image alone takes half a minute. So the backup is a stream processor of its own, a Durable Object on its own context (/backups/state), enabled by the init hook that runs after every publication. Three events make up its whole interface:

A context below the root has none of the root's repos, sandboxes or Artifacts access, so the init hook also gives it three rewrite rules pointing itx.repos, itx.sandboxes and itx.cfArtifacts at the root's, and creates the sandbox (/backups/state/box) from the root, since only a context above a sandbox may create it. The same publication enables the processor by naming its class and the root file that exports it, and that file has to keep exporting it in every later publication.

A backup on demand is the same event, appended by hand with a reason.

History, not a snapshot

The repo facet speaks git to the storage underneath (Cloudflare Artifacts) and doesn't lend a remote. But Artifacts is a standard smart-HTTP git server, and the mind's own Artifacts proxy answers two questions about any repo path: itx.cfArtifacts.get(path).remote(), its git URL, and .createToken("read", 3600), a read-only token good for an hour. The run reads the tip the repo facet sees, asks for both, and hands all three to the job in its environment.

The job mirrors the real history instead of rebuilding files. The token goes in as an HTTP header through git's environment config, so it never appears in a URL, a config file or the mirror:

GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.extraHeader \
GIT_CONFIG_VALUE_0="Authorization: Bearer $TOKEN" \
  git clone --quiet --mirror "$REMOTE" mirror.git
unset TOKEN
git -C mirror.git merge-base --is-ancestor "$EXPECTED" refs/heads/main
git -C mirror.git fsck --full --strict --no-dangling
git -C mirror.git bundle create "$NAME" HEAD --all

A bundle made with --all and no prerequisites restores on its own with nothing but git: git clone state.bundle state. The file is named for the UTC date and the first twelve characters of the tip.

Running longer than a call

A sandbox exec gets about a minute, and the clone, checks, upload and download can take longer. So the run makes two small scripts out of one. A start script writes the job to the sandbox's disk, launches it with setsid nohup in a process group of its own, records its pid and answers at once. A look script, run every ten seconds, answers running, the job's one-line result (ok and a JSON summary, or failed: and why), or absent if the sandbox restarted and lost the job. A job with no result after fifteen minutes fails the attempt. A failed attempt is tried twice more, two minutes apart. The whole job runs with HOME pointing at an empty directory and GIT_CONFIG_NOSYSTEM=1, so git behaves as it would on a stranger's machine.

Google Drive, without a token on the sandbox

The mind's Google account was already connected through iterate Cloud's OAuth client, with the drive scope among others. The sandbox calls Drive's REST API with plain curl, and the Authorization header is a placeholder, Bearer getSecret("/secrets/google", { field: "accessToken" }), which the sandbox's egress replaces on the way out. The sandbox never holds the token.

Drive has no paths, so the job finds things by private properties instead of names:

The checks

A run fails, and nothing counts as backed up, unless every one passes:

  1. The mirror's main contains the tip the repo facet reported just before. (A mirror of a stale replica would pass every later check.)
  2. fsck --full --strict on the mirror.
  3. The bundle verifies, and its heads equal the mirror's refs.
  4. A stranger's restore: git clone the bundle with an empty git config, fsck it, check HEAD is the tip, the commit count matches, HEAD's tree matches the mirror's, and a checkout is clean.
  5. The upload is found by its property, as above, never duplicated.
  6. Drive's sha256Checksum and size equal the bundle's, and the file's permissions list nobody but its owner.
  7. The file is downloaded back (alt=media), hashed again, and check 4 runs again on that copy.

Number 7 is the one that makes it a backup. Everything before it proves we made a good file. Only restoring the copy that is actually stored proves we have one.

const local = await sha256(bundle);
const remote = await download(fileId);
if (await sha256(remote) !== local) throw new Error("stored copy differs from the bundle");
await restoreAndCompare(remote, { tip, commitCount, tree });

Quiet unless broken

A backup job that messages every week trains you to ignore it. This one says nothing when it works. Every run, good or bad, appends settled with the Drive file, tip, commit count, root commits, refs, size, hash and git's version, and the processor's state keeps the last good one, so "when did it last work" is a read, not a guess. When a settled says it failed after three attempts, the worker's ordinary event handler sends one message to Misha's own chat. It first appends a claim with an idempotency key built from the failed event's offset, so a redelivered event cannot send the message twice. The next attempt is the next week's, or one asked for by hand.

Nothing is ever deleted. A week's bundle is about ten megabytes; keeping all of them is cheaper than reasoning about retention.

How we checked it

Before shipping, the same script ran once from a coding sandbox, and then the published job ran for real. Both uploaded, downloaded and restored. A separate clone straight from storage and a clone of the downloaded bundle had identical commit, tree and parent lists. That comparison is the test we would want to have run on the day we need it.

The job is a hundred-odd lines of bash and a processor. The checks are most of it, which feels like the right ratio.

Want this in your own iterate mind? The button copies a note for it: it reads this page, tells you what it would change, and changes nothing until you say yes.

Linking here

← A proxy that holds the body owns its size
Delivery order is not send order: read back the stream →

One email per new post, at most two a day. Unsubscribe any time. Your address is kept privately and never shown.