Backups#
An encrypted daily archive of everything a lost machine would take with it, and a restore that never loses a file.
What a backup holds#
cabinet backup create (bin/backup.sh create, which the schedule runs) writes one archive with, for the workspaceWorkspace The folder that holds the team's files (CABINET.md, AGENTS.md, HANDOFFS.md, roles, specs, notes) and usually the product repos. It is its own private git repo. and every repo in repos.tsv:
- the full git history: every branch and unpushed commit;
- uncommitted changes, untracked files and stashes;
- every .env file (
.env,.env.localand the like), at any depth (git ignores them, so nothing else keeps them), except those innode_modules, in a nested repo, and*.examplefiles; - the branch it was on, or that HEAD was detached;
- each session of a repo: its uncommitted changes and untracked files (its commits are in the repo's history, on its
session/<name>branch). A sessionSession A folder of its own for one agent session in a repo (a git worktree on a branchsession/<name>), so several sessions work at once without touching each other's changes:cabinet session start. You merge its work.cabinet session endlists what deleting its folder would lose and refuses work that exists nowhere else, changing nothing;--forcedeletes it after asking at a terminal. See sessions. whose folder was deleted by hand is named in the output and left out.
It also includes Claude Code's memory for the workspace and ~/.claude/settings.json. A repo with no commits yet (for example a workspace made without an owner identity) is kept as its files.
Archives are named <slug>-<YYYYMMDD>-<HHMMSS>.tar.gz.enc and readable only by you (mode 600). Each is sealed with authenticated encryption, AES-256-GCM with a key from PBKDF2-SHA-256 (600000 iterations), so an archive that was changed, cut short or opened with the wrong passphrase never opens. It starts with the bytes CBNTBAK1, and inside it records the workspace's slugSlug The workspace's short name (acme). It names its schedules, logs, backups and backup key, so projects on one machine never collide. and the time it was made, so a restore can tell where it belongs without trusting the file name. The newest CABINET_BACKUP_KEEP (default 14) of this workspace's archives are kept, newest by the time in their names, never by when the file was last modified (which a synced drive or a copy changes); the archive a backup has just written is never deleted, and another workspace's archives in the same folder are never touched.
Setting it up#
- Choose a folder outside the workspace and every repo it lists: a synced drive or an external disk. Setup,
cabinet configand the backup itself refuse a folder inside them, because a backup there is lost with what it protects, copies itself into every later archive, and can be committed. - Set it with
cabinet config --backup-dir <folder>(and--backup-time "<time>", default 1:00 PM), thenbin/bootstrap.shto schedule it. - Put the passphrase in the keychain (macOS), the secret store (Linux) or, where cron runs the schedules, a file only you can read, and keep the same one in your password manager: without it no archive opens.
bin/bootstrap.shprints the command for your system; on Linux without a desktop session see macOS and Linux.
security add-generic-password -a "$USER" -s cabinet.<slug>.backup -wOr set CABINET_BACKUP_PASSPHRASE in the environment. Never put it in cabinet.env, which git tracks.
Restoring#
bin/backup.sh restore <archive> [folder] [--force] # folder: where the workspace goes (default: this workspace)
bin/bootstrap.sh # then guardrails, links and schedules
bin/doctor.shOn a new machine, put the passphrase in the keychain or secret store first, then run backup.sh restore from a copy of the kit (or a clone of the workspace's repo). Restore never loses a file, and it acts only on an archive it can prove is this workspace's. Before it writes anything, it refuses, writing nothing, an archive that is changed or damaged, or the passphrase is wrong (checked whole, before anything is unpacked); a file not named <slug>-YYYYMMDD-HHMMSS.tar.gz.enc (give it back its name); an archive that does not hold exactly one folder; one whose slug or stamp differs from its file name's; and a folder that holds another workspace (its cabinet.env names another CABINET_SLUG, read as text, never run): restore into an empty folder instead. An archive made before 0.8.5 has no seal: it still restores as before, saying once that it is not authenticated. Back up again once it is restored. It reads the whole archive before it writes anything: each repo's folder comes from the repos.tsv in the archive, never the one in the folder being restored over (a path there can be absolute or under ~), and an archive member with an absolute path or a .. part, or a .env file whose name starts with -, stops it, naming the member, with nothing written. Then:
- A repo that already exists gets the archive's branches under
refs/remotes/backup/*, to compare and merge by hand. Its patches are copied torecovered/. - A missing repo, or an empty folder, is restored with its uncommitted work, on the branch it was on (or detached, as it was).
- The workspace folder itself, or a project folder holding nothing but the workspace being restored (the inside layoutLayout Where the workspace sits: a new folder, around an existing folder of repos, inside a project as
cabinet/, or beside a project. See layouts.), is checked out in place. Every path in the way is first moved torecovered/<archive>/<repo>/, at the same path, and the restore goes on: a file with other content than the archive's, tracked or untracked; a file where the archive has a folder (a filespecswhere it hasspecs/x.md, or a filenotes/draftswhere its untracked files havenotes/drafts/idea.md); a folder where it has a file (a folderREADME.md/); a file the archive added without committing it (added.mdstaged), or deleted without committing (gone.md), when the folder holds one of that name. A repo with no commits is archived as its files and restored into its folder whatever it holds, so what is in its way is moved aside the same way, even in a folder outside the workspace. - Any other folder that already holds files of its own is left alone, and the repo is restored into
recovered/<archive>/<name>/repoinstead. A folder such as your home folder is never turned into a repo. - Sessions come back as worktrees at
sessions/<repo>/<name>/, on their branch, with their uncommitted changes and untracked files, when their repo is restored fresh and that folder is missing. Where the repo already exists, or the session's folder does, its patch and untracked files go torecovered/<archive>/<repo>/sessions/<name>/, and nothing that exists changes. .envfiles are restored only where missing: a file, or a link (even to nothing), already at that path or in a folder above it is left as is, and nothing is written through a link. Stashes are kept as patches inrecovered/.- Claude Code memory and settings are restored only where missing.
- Run again, it never writes over what it kept: each run keeps aside into a folder that does not exist yet (
recovered/<archive>/<repo>-2,-3, ...), and names it. - Stopped half way (a full disk, a failed command), it finishes when run again: a folder it was checking out in place holds
.git/cabinet-restoreuntil the checkout and the untracked files are done, and the next run checks it out in place again instead of only fetching. --forcedeletes what is in the way instead of keeping it, after listing it all at once, before anything is written, including in a repo's folder outside the workspace: it asks at the terminal and deletes only when you typeyes. Anything else, no terminal (an agent's command), or a scheduled run, changes nothing.
Inside a project with the private layout, the pointer files (CLAUDE.local.md and the others) are ignored by the project's git and so not in the archive: bin/role.sh build, run by bootstrap, rebuilds them.
Checking it#
bin/doctor.sh reports the newest scheduled backup's age (from backup.log in the log folder, never by listing the backup folder, which can trigger a macOS access prompt), whether the passphrase is in the keychain or secret store (or in CABINET_BACKUP_PASSPHRASE), and a backup folder in the wrong place. Once a quarter, check that the newest archive really restores:
cabinet backup verify # or bin/backup.sh verify [folder]It restores the newest archive of this workspace (by the time in its name) into a temporary folder, as backup.sh restore would, and deletes that copy when it is done (it holds your secrets). For the workspace, each repo and each session it holds it prints one line (a session as <repo> session <name>, with its worktree rebuilt on its branch and its changes applied): restores exactly as it is now, restores with so many files or commits changed since the backup (work done after it), or a problem. A problem is an archive that is changed or damaged, or opened with the wrong passphrase; one made for another workspace, or whose stamp differs from its file name; one made before 0.8.5, which is not authenticated (its repos are still checked: back up again); a history that does not rebuild, uncommitted changes that do not apply, files that do not unpack, or a repo that is not in the archive. Any problem makes it exit 1: back up again, then verify that archive. It never touches the workspace, its repos or your settings, and does not check Claude Code's memory or settings. A good result is recorded in ~/Library/Logs/cabinet/<slug>/backup-verified, and bin/doctor.sh notes when none is recorded or the last is older than 92 days.
Built from version 0.8.5