Keep your books

Back up and restore

Export the whole book to one archive and restore it into an empty installation.

Your books live in the folder where you run Pantry. An export is one archive holding the whole book: the ledger, documents byte for byte, reconciliations, close state, approvals and the move-in journal. A hosted Pantry keeps its own books on your Cloudflare account; back those up as in Back up a hosted Pantry.

Export

Stop Pantry so nothing can change during the backup, then export:

Shell
rer dev --stop
rer export --output exports/pantry-books.rer

The archive is saved in the exports folder, with its checksums inside it: rer import checks them before restoring. Copy it somewhere safe, away from this computer. Sign-ins are not part of it: after a restore you set up the owner again. Keys Pantry keeps sealed with this installation's own secret (Stripe, the AI key, Gusto and bank feed connections) only open in this installation, so after a restore into a fresh install, connect them again in Settings and Bank.

Back up a hosted Pantry

rer export saves only the books on this computer, and refuses when you name a hosted address. To keep the hosted books, run this in the run-pantry folder you deploy from:

Shell
rer run hosted-backup --env-file .env.pantry

Add --environment NAME if you deployed with one. The command establishes the database's stable erasure-journal identity if this is its first backup, then takes Cloudflare's SQL snapshot and converts it to a private, checksum-verified .rer archive. The receipt lists table counts, exclusions, archive hash and content hash. The same Pantry policy as local export removes credentials and disables restored connections and standing consent. Original document bytes travel from the private document bucket, with their D1 custody records and hashes.

Restore the resulting archive with the ordinary rer import command below. Supply the latest post-erasure archive with --journal when restoring an older backup. This uses ERASURE-001's existing journal fence; a fresh destination without that later journal cannot discover erasures made after its backup.

The command accepts a mode-0600 deploy file or injected CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN. It never prints provider diagnostics or credentials. Each default filename contains the full timestamp, and an existing output is refused. A failed conversion retains its private SQL snapshot and names its location. To retry conversion without another provider call:

Shell
node scripts/hosted-archive.mjs --input-sql /path/to/snapshot.sql --output exports/recovered.rer --bucket pantry-production-pantry-documents

Only use a snapshot produced after the source installation established its erasure identity. A legacy SQL file without that identity is refused: retain it and take a new backup from the source rather than assigning an unrelated identity.

For an owner-controlled scheduler, run the same command from the exact deployed checkout, with its private deploy file, once per day. Keep the archive directory on encrypted storage outside the deployed database, monitor the command's exit status, and copy successful archives to a separate failure domain. The command returns nonzero on provider or conversion failure and never replaces an earlier archive. Example scheduler command:

Shell
cd ./run-pantry && node scripts/hosted-backup.mjs --env-file ./pantry-deploy.env --environment production

New own-account hosted deploys provision a private PANTRY_BACKUPS R2 binding. The half-hour Cron starts one complete archive per UTC day. Minute ticks resume an existing snapshot, advancing at most 32 archive parts per tick without starting a new large database snapshot. If erasure invalidates a snapshot, only the next half-hour tick may replace it. A durable lease prevents overlapping ticks from publishing duplicates. Multipart uploads keep memory bounded; failed uploads are aborted. Failed work retries on a later tick, and erasure invalidates an unfinished snapshot before a fresh snapshot is taken. No archive is deleted automatically.

A saved archive job can disappear when an owner erases personal data. The next scheduled tick replaces that missing job with a fresh snapshot through the same erasure fence, finishes the oldest incomplete day, then continues later days. A provider upload failure retains a valid completed snapshot for retry.

The installation's pt_hosted_backup_runs table records completion, the object key, content hash and a value-free failure code. Download a completed archive using the owner's Cloudflare R2 tools, then restore it as below. Keep the bucket private. Existing deployments without the binding continue their accounting schedule and need redeployment to enable it. A backup remains in the same Cloudflare account; copy it elsewhere for independent disaster recovery.

Uploaded originals move from transactional D1 staging into verified private R2 objects. Reads retain the existing document permissions and verify stored hashes; erasure queues an empty tombstone so a delayed upload cannot recreate erased bytes. Complete recovery archives contain the objects, custody rows and erasure fence. Retained issued invoice and estimate snapshots remain in D1. A fresh hosted deployment drill and the large-business report timing proof remain OPS-001 work.

Restore into a fresh hosted deployment

Reserve a new hosted environment at the same Pantry revision, apply its normal migrations, and keep its writers and Cron paused during recovery. The destination must contain only its unchanged migration defaults. The restore refuses existing books and never merges or replaces them.

Provision the new environment through rer deploy with configured production sign-in mail or an approved Auth SSO installation. Cloudflare resource permissions alone do not configure sign-in. A deployment refused at this prerequisite has no fresh hosted destination to restore into; local or simulated-provider recovery does not establish a hosted drill.

Run from the deployed checkout with its mode-0600 Cloudflare deploy file and a mode-0600 archive:

Shell
node scripts/hosted-restore.mjs --environment recovery --env-file .env.pantry --input exports/pantry-books.rer --journal exports/latest-pantry-books.rer --yes

The command also accepts injected CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN instead of a file. It validates the full archive and the optional later journal before remote staging, then uses the same Pantry policy, migration replay and ERASURE-001 fence as local import. A missing later journal is reported explicitly: a fresh destination cannot discover erasures made after the backup on its own. A refused archive publishes no books. Provider diagnostics and document values never enter command errors.

Compare the restored report snapshots, document inventory and original bytes with the source before resuming writers and Cron. Owner sign-ins and provider keys are configured separately. The archive restores the private document objects and their D1 custody records together. It refuses incomplete object inventories and hash mismatches.

Restore into a fresh install

A restore goes into an installation with no books yet. On the new computer (or in a new folder), get Pantry, put the archive in its exports folder, import it, then set up the owner:

Shell
git clone https://github.com/just-every/run-pantry.git
cd run-pantry
mkdir -p exports
cp /path/to/pantry-books.rer exports/
rer import --input exports/pantry-books.rer --yes
rer setup --owner-email you@example.com
rer dev

Import before setup: rer import installs what Pantry needs by itself. Pantry checks the archive before restoring it and refuses one whose posted entries do not balance. People you invited keep their roles; they sign in again by email.

Start over in this folder

rer reset --yes removes this installation's local data, owner and sessions, and keeps the exports folder. Export first, then reset and restore:

Shell
rer dev --stop
rer export --output exports/pantry-books.rer
rer reset --yes
rer import --input exports/pantry-books.rer --yes
rer setup --owner-email you@example.com
rer dev

If a restore is refused

A refused restore changes nothing, and your archive stays where it was.

  • target_not_empty: the folder already holds Pantry books, so the restore would mix two sets of books. Either restore into a fresh install (above), or replace the books here: export them first if you want to keep a copy (rer export --output exports/books-before-restore.rer), then rer reset --yes and import again.
  • content_checksum or archive_checksum: the file was damaged or changed after export. Use another copy.

Do not run rer setup in place of a restore that was refused: setup starts a new, empty book. Run it once rer import reports import: complete.