diff --git a/crates/ledger-cli/Cargo.toml b/crates/ledger-cli/Cargo.toml index a992303d..ff19b180 100644 --- a/crates/ledger-cli/Cargo.toml +++ b/crates/ledger-cli/Cargo.toml @@ -75,8 +75,6 @@ workspace = true # program: `just package-linux`. Paths are relative to the workspace root. [package.metadata.generate-rpm] name = "wanderbooks" -# Backups run the system's git (WB-pkg-4): dnf fetches it. -requires = { git = "*" } summary = "Double-entry bookkeeping your agent keeps and you can read" license = "MIT OR Apache-2.0" url = "https://wanderbooks.ai" diff --git a/crates/ledger-cli/tests/backups.rs b/crates/ledger-cli/tests/backups.rs index b94215e4..5394e907 100644 --- a/crates/ledger-cli/tests/backups.rs +++ b/crates/ledger-cli/tests/backups.rs @@ -1236,3 +1236,118 @@ async fn old_settings_and_an_old_backup_history_are_left_alone_and_said() { drop(c); assert!(server.close().success()); } + +/// docs/backups.md, "A backup made with an older version": a person who +/// still has a backup made with git clones it themselves (git is their own +/// tool now) and adopts the plain folder. This makes such a backup the way +/// an older version did (a repository whose one commit is the books' +/// files), clones it as the docs say, and adopts the clone with its vault +/// and key as the docs say. +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn a_clone_of_an_old_git_backup_is_adopted_as_a_plain_folder() { + let git = |dir: &Path, args: &[&str]| { + let out = Command::new("git") + .arg("-C") + .arg(dir) + .args(["-c", "user.name=t", "-c", "user.email=t@t.invalid"]) + .args(args) + .output(); + match out { + Ok(o) => { + assert!(o.status.success(), "{args:?}: {o:?}"); + true + } + // No git on this machine: the path is the person's own tool's. + Err(_) => false, + } + }; + let home = Home::new("old-backup"); + let server = Server::start(&home, Duration::from_secs(3600)); + home.create("acme"); + let c = connect(&home, "acme", home.token("acme", &ALL)).await; + call( + &c, + "books.add_party", + json!({"name": "Mo", "roles": ["member"]}), + ) + .await + .unwrap(); + call( + &c, + "books.set_tin", + json!({"party": "Mo", "tin": "12-3456789", "tin_type": "ein"}), + ) + .await + .unwrap(); + let (folder, want) = backed_up_acme(&home).await; + drop(c); + assert!(server.close().success()); + // The old backup: the books' files, committed, in a bare repository. + let book = home.book_dir("acme"); + let work = home.outside("old-work"); + std::fs::create_dir_all(&work).unwrap(); + for part in ["journal.jsonl", "blobs", "vault", "keys", "access.jsonl"] { + let from = book.join(part); + if from.is_dir() { + copy_dir(&from, &work.join(part)); + } else if from.is_file() { + std::fs::copy(&from, work.join(part)).unwrap(); + } + } + if !git(&work, &["init", "-q", "-b", "main"]) { + return; + } + git(&work, &["add", "-A", "-f"]); + git(&work, &["commit", "-q", "-m", "seq 1 head x\n\nbook acme"]); + let bare = home.outside("acme.git"); + let out = Command::new("git") + .args(["clone", "-q", "--bare"]) + .arg(&work) + .arg(&bare) + .output() + .unwrap(); + assert!(out.status.success(), "{out:?}"); + // The person's steps: clone it, then adopt the folder with its vault + // and key. + let clone = home.outside("acme-old"); + let out = Command::new("git") + .args(["clone", "-q"]) + .arg(&bare) + .arg(&clone) + .output() + .unwrap(); + assert!(out.status.success(), "{out:?}"); + let other = Home::new("old-backup-new"); + let server = Server::start(&other, Duration::from_secs(3600)); + let request = |confirmed: bool, expect_head: Option<(u64, String)>| Request::Adopt { + id: "acme".into(), + source: clone.clone(), + settings_toml: None, + config_json: None, + vault_dir: Some(clone.join("vault")), + vault_key: Some(clone.join("keys").join("legacy.key")), + confirmed, + expect_head, + skip_unknown: false, + }; + let preview = match other.admin(request(false, None)) { + Response::Preview(p) => p, + r => panic!("{r:?}"), + }; + match other.admin(request(true, Some(preview.source_head))) { + Response::Adopted(a) => { + assert!(a.problem.is_none(), "{a:?}"); + assert_eq!(a.head, live_head(&home, "acme")); + } + r => panic!("{r:?}"), + } + let c = connect(&other, "acme", other.token("acme", &["read"])).await; + assert_eq!(figures(&c).await, want); + let party = call(&c, "books.party", json!({"party": "Mo"})) + .await + .unwrap(); + assert_eq!(party["party"]["tin"]["in_vault"], true, "{party}"); + drop(c); + assert!(server.close().success()); + let _ = folder; +} diff --git a/crates/ledger-cli/tests/packaging.rs b/crates/ledger-cli/tests/packaging.rs index b54eaca4..d100d452 100644 --- a/crates/ledger-cli/tests/packaging.rs +++ b/crates/ledger-cli/tests/packaging.rs @@ -684,26 +684,30 @@ fn only_a_person_runs_the_workflow_that_publishes_the_repositories() { ); } -/// WB-pkg-4: on Linux git is a dependency of every package, so the package -/// manager fetches it; nothing carries a git of its own. +/// WB-pkg-4: a backup is plain files the program writes itself, so no +/// package depends on another program for it and none carries one. #[test] -fn the_linux_packages_depend_on_git_and_none_carries_one() { - let packager = read("deploy/packaging/packager.toml"); - assert_eq!( - packager.matches("\"git\"").count(), - 2, - "the deb and the pacman package depend on git" - ); - assert!(read("crates/ledger-cli/Cargo.toml").contains("requires = { git = \"*\" }")); - assert!(read("deploy/packaging/aur/PKGBUILD").contains("'git'")); +fn no_package_depends_on_another_program_for_backups() { + let word = |text: &str| { + text.to_lowercase() + .split(|c: char| !c.is_ascii_alphanumeric()) + .any(|w| w == "git") + }; for file in [ + "deploy/packaging/packager.toml", + "deploy/packaging/aur/PKGBUILD", + "crates/ledger-cli/Cargo.toml", "deploy/packaging/windows/wanderbooks.nsi", "deploy/packaging/macos/build-macos.sh", ] { - let text = read(file).to_lowercase(); - assert!( - !text.contains("mingit") && !text.contains("git.exe"), - "{file} bundles a git" - ); + let text = read(file); + // (Cargo.toml may name a git *dependency* of the build, never a + // package requirement.) + let checked: String = text + .lines() + .filter(|l| !l.contains("git =")) + .collect::>() + .join("\n"); + assert!(!word(&checked), "{file} depends on, or bundles, a git"); } } diff --git a/crates/ledger-host/src/commands.rs b/crates/ledger-host/src/commands.rs index dc8cb62f..fe687429 100644 --- a/crates/ledger-host/src/commands.rs +++ b/crates/ledger-host/src/commands.rs @@ -770,7 +770,7 @@ fn books_usage(prog: &str) { " back-up back the books up now to every backup their settings name (--new-disk: the backup folder's disk is new)" ); eprintln!( - " restore bring back a backup (a git repository's address, or BOOK.git in the backup folder), proven whole first: as new books, or replacing books (kept in legacy/)" + " restore bring back a backup (your backup folder, the folder of one set of books in it, or a backup file), proven whole first: as new books, or replacing books (kept in legacy/)" ); eprintln!( " upgrade give the go-ahead, with the owner passphrase, for books an older wanderbooks wrote to move to this version's journal format (a verified backup with the vault and keys first)" @@ -779,7 +779,7 @@ fn books_usage(prog: &str) { " extract read one attachment's text (a PDF, XLSX or text file) and journal it, one at a time; books an older version filed are read this way after an upgrade" ); eprintln!( - " put-aside move the old copies of adopted books (their data folder, their vault and its key, and other paths given: settings file, git history) whole into the legacy folder, once the books hold everything they do, byte for byte; nothing is deleted" + " put-aside move the old copies of adopted books (their data folder, their vault and its key, and other paths given: settings file, old history) whole into the legacy folder, once the books hold everything they do, byte for byte; nothing is deleted" ); } diff --git a/crates/ledger-host/src/start.rs b/crates/ledger-host/src/start.rs index 47690f43..8e10f8b9 100644 --- a/crates/ledger-host/src/start.rs +++ b/crates/ledger-host/src/start.rs @@ -12,7 +12,7 @@ //! and DBUS_SESSION_BUS_ADDRESS only when they point at this //! account's own private runtime folder, and SSH_AUTH_SOCK only when //! it names a socket this account owns (the owner's ssh agent, so the -//! server's backups reach a private git repository, D-30). Nothing +//! server's backups reach a folder on the network, D-91). Nothing //! else passes (a scope's own identifiers, such as INVOCATION_ID, are //! systemd's). Two more: APPIMAGE and APPDIR, only when they are //! this program's own (INVARIANT 6), so the host knows its own @@ -441,9 +441,9 @@ fn scope_made(child: &mut std::process::Child, log: &std::fs::File, from: u64) - /// The host's environment on Windows (INVARIANT 1's counterpart): the /// system's own variables, the account's profile, and a PATH fixed to the -/// system folders and Git for Windows (the backups run `git`). Nothing -/// else of the opener's passes. (CHOICE, P11c: no authority states a -/// Windows list; this is the least a Windows program and `git` need.) +/// system folders. Nothing else of the opener's passes. (CHOICE, P11c: no +/// authority states a Windows list; this is the least a Windows program +/// needs.) #[cfg(windows)] fn host_env(home: &Path) -> Vec<(String, std::ffi::OsString)> { let var = |name: &str| std::env::var_os(name); @@ -452,12 +452,8 @@ fn host_env(home: &Path) -> Vec<(String, std::ffi::OsString)> { .map_or_else(|| PathBuf::from(r"C:\Windows"), PathBuf::from); let program_files: PathBuf = var("ProgramFiles").map_or_else(|| PathBuf::from(r"C:\Program Files"), PathBuf::from); - let path = std::env::join_paths([ - system_root.join("System32"), - system_root.clone(), - program_files.join("Git").join("cmd"), - ]) - .unwrap_or_default(); + let path = std::env::join_paths([system_root.join("System32"), system_root.clone()]) + .unwrap_or_default(); let mut env: Vec<(String, std::ffi::OsString)> = vec![ ("PATH".into(), path), ("SystemRoot".into(), system_root.clone().into_os_string()), diff --git a/crates/ledger-mcp/handbook/backups.md b/crates/ledger-mcp/handbook/backups.md index b51c09c4..17b90a8f 100644 --- a/crates/ledger-mcp/handbook/backups.md +++ b/crates/ledger-mcp/handbook/backups.md @@ -1,9 +1,10 @@ # Backups -- The books back themselves up: a little after each change, when they open, before they close. Each backup goes to the targets the settings name: backup.git_remote, a private repository the human owns, and backup.folder, a folder on another disk. Both is best. The backups aren't encrypted: the human's repository host and disk keep them private. -- No targets set: books.start says so. Ask the human for the repository's address and the folder, then set them with books.set_setting (who decided, and when); choosing where backups go needs books:admin, as backing up does. -- books.backup says how each target stands: when it last took the books, through which journal seq, why the last try failed, and whether its weekly restore check passed. A target that is stale, failing, or failed its check: tell the human what it says, in plain words (a disk not connected, a repository that refused). -- books.back_up_now backs up at once, for instance before the human changes computers. A backup never changes the books. -- A backup folder that took these books' backups but holds none now is a disk not connected: ask the human to connect it. Only if they say the disk is new, back up now with new_disk: true to begin the books' backup there again. -- Books restored as a copy of other books (under another name) don't back up to those books' repository (that would stop theirs): books.backup says so; ask the human for one of their own. -- Restoring is the human's to do, outside these tools: a backup comes back as new books, or replacing these (the old books are kept, never deleted), and each is proven whole before it is restored. +- The books back themselves up: a little after each change, when they open, before they close. The backup goes to the backup folder the settings name (backup.folder): a folder on another disk, or one that Dropbox, iCloud, OneDrive or Google Drive keeps in sync. It holds one folder for these books, made only of files that are added and never changed or deleted, so a sync service never sees one change under it. +- No backup folder set: books.start says so. Ask the human which folder, then set it with books.set_setting (who decided, and when); choosing where backups go needs books:admin, as backing up does. The window has a folder chooser for the same. +- The human may protect the backups with a passphrase, set up in the window and off by default. Then every file in the folder is sealed and says no more than how many there are and how big. The passphrase is never in the books or in these tools, and a forgotten one can't be recovered: say so plainly if the human asks. books.backup says whether the backups are sealed. +- books.backup says how the folder stands: when it last took the books, through which journal seq, why the last try failed, and whether its weekly restore check passed. A folder that is stale, failing, or failed its check: tell the human what it says, in plain words (a disk not connected, another set of books in the folder). +- books.back_up_now backs up at once, for instance before the human changes computers. A backup never changes the books. The window's Save a backup... makes the same backup as one file to keep or carry. +- A backup folder that took these books' backups but holds none now is a disk not connected (disconnected: true): ask the human to connect it. Only if they say the disk is new, back up now with new_disk: true to begin the books' backup there again. +- Books that still name a private repository in their settings (an older kind of backup) are told it is no longer used: ask the human for a backup folder instead. Nothing older is deleted. +- Restoring is the human's to do, outside these tools: a backup comes back as new books, or replacing these (the old books are kept, never deleted), from the backup folder or a backup file, and each is proven whole before it is restored. diff --git a/crates/ledger-mcp/src/tools/kept.rs b/crates/ledger-mcp/src/tools/kept.rs index 99b59bc1..81c37088 100644 --- a/crates/ledger-mcp/src/tools/kept.rs +++ b/crates/ledger-mcp/src/tools/kept.rs @@ -1038,11 +1038,11 @@ impl BooksServer { // failing. { let st = self.backups.standing(store); - if st.note.is_some() { + if st.targets.is_empty() { next_steps.push(step( "books.backup", None, - "No backups are set up: ask the human for a private repository and a folder on another disk, then set backup.git_remote and backup.folder (books.set_setting).", + "No backups are set up: ask the human which folder to back up to (a folder on another disk, or one a sync service keeps), then set backup.folder (books.set_setting).", )); } else if st.needs_attention() { next_steps.push(step( diff --git a/crates/ledger-mcp/src/tools/reports.rs b/crates/ledger-mcp/src/tools/reports.rs index 2a3bb2f0..84b681b3 100644 --- a/crates/ledger-mcp/src/tools/reports.rs +++ b/crates/ledger-mcp/src/tools/reports.rs @@ -1124,7 +1124,7 @@ impl BooksServer { /// ```text /// GOAL: everything the CPA needs for the return in one zip, the K-1s' /// and 1099s' TINs included, without a full TIN ever landing in - /// the books (a git repository) or the conversation. + /// the books or the conversation. /// SOURCE: docs/mcp-interface.md; BS-partner-2; DECISION (owner, /// 2026-10-15): "it needs to be in the damn CPA package." /// INVARIANTS: diff --git a/crates/ledger-package/src/attention.rs b/crates/ledger-package/src/attention.rs index 97c1b72e..262cc0b7 100644 --- a/crates/ledger-package/src/attention.rs +++ b/crates/ledger-package/src/attention.rs @@ -1294,7 +1294,7 @@ pub fn find_with( count(ids.len(), "stored file is", "stored files are") ), detail: format!( - "Attachment {}: the bytes on disk don't match their recorded hash. Restore them from a backup (the books dir's git history).", + "Attachment {}: the bytes on disk don't match their recorded hash. Restore them from a backup.", ids.join(", ") ), target: Target::Documents, diff --git a/deploy/README.md b/deploy/README.md index 6d0630c8..af6f2642 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -104,17 +104,11 @@ and `IPAddressDeny=any` with `IPAddressAllow=localhost`, and no seccomp or Landlock lines (D-32, D-51). The loopback-only rule is deliberate: the server reaches nothing out. A -book whose backup target is a **remote** git repository needs that host -allowed, or its backups fail: - -```ini -# /etc/systemd/system/wanderbooks-server.service.d/backup.conf -[Service] -IPAddressAllow=203.0.113.10 -``` - -A backup to a folder on this machine needs nothing. The tunnel and Caddy -run as their own services and reach 127.0.0.1:7411, which the rule allows. +backup is a folder of plain files (docs/backups.md): a folder on this +machine's disks needs nothing, and nothing else is installed for it. (A +folder on a network share the machine mounts is a disk to the server, and +the mount, not the server, reaches the network.) The tunnel and Caddy run as +their own services and reach 127.0.0.1:7411, which the rule allows. ## 5. A token for each client @@ -221,7 +215,7 @@ a last backup and closes (3.9), so `TimeoutStopSec=600` is generous rather than needed. Backups still run on their own, from the books' settings, as on the -desktop (3.7, D-30, D-31); this machine runs git itself. +desktop (3.7, D-91): plain files in a folder, written by the server. ## 9. Prove the boundary (what CI runs) diff --git a/deploy/packaging/aur/PKGBUILD b/deploy/packaging/aur/PKGBUILD index 77d469f9..020b382c 100644 --- a/deploy/packaging/aur/PKGBUILD +++ b/deploy/packaging/aur/PKGBUILD @@ -9,7 +9,7 @@ pkgdesc="Double-entry bookkeeping your agent keeps and you can read" arch=('x86_64') url="https://wanderbooks.ai" license=('MIT' 'Apache-2.0') -depends=('gcc-libs' 'glibc' 'git') +depends=('gcc-libs' 'glibc') provides=('wanderbooks') conflicts=('wanderbooks') options=('!lto' '!strip') diff --git a/deploy/packaging/macos/entitlements.plist b/deploy/packaging/macos/entitlements.plist index 30dd36ee..5e3d36e5 100644 --- a/deploy/packaging/macos/entitlements.plist +++ b/deploy/packaging/macos/entitlements.plist @@ -5,13 +5,13 @@ The app is signed with the hardened runtime (codesign --options runtime), which Apple's notarization requires. It is NOT sandboxed (the App Sandbox would forbid what the product is: it starts a copy of - itself as the books server, runs the system's git for backups, and + itself as the books server, and reads and writes the person's data folder and the folders they pick for backups). Outside the sandbox, none of that needs an entitlement: - * starting itself as a child process and git as another: none; - * outgoing network connections (the relay, the update look, a git - remote): none (com.apple.security.network.client is a SANDBOX + * starting itself as a child process: none; + * outgoing network connections (the relay, the update look): none + (com.apple.security.network.client is a SANDBOX entitlement); * reading and writing its data folder, Application Support/wanderbooks: none (the Documents folder is a privacy prompt, answered by diff --git a/deploy/packaging/packager.toml b/deploy/packaging/packager.toml index 7a0b9791..8dbb5bf1 100644 --- a/deploy/packaging/packager.toml +++ b/deploy/packaging/packager.toml @@ -24,9 +24,8 @@ section = "utils" # A deb marks itself package-managed: `wanderbooks update` refuses on it # and says to use apt (plan 3.9). desktop-template = "deploy/packaging/wanderbooks.desktop" -# git: the backups run the system's git (WB-pkg-4); the package manager -# fetches it, so a Linux person never sees the missing-git words. -depends = ["libc6", "libgcc-s1", "git"] +# Backups need nothing installed (WB-pkg-4): they are plain files. +depends = ["libc6", "libgcc-s1"] [deb.files] "deploy/packaging/install-method-deb" = "usr/share/wanderbooks/install-method" @@ -42,7 +41,7 @@ depends = ["libc6", "libgcc-s1", "git"] "LICENSE-APACHE" = "usr/share/doc/wanderbooks/LICENSE-APACHE" [pacman] -depends = ["gcc-libs", "glibc", "git"] +depends = ["gcc-libs", "glibc"] [pacman.files] "deploy/packaging/install-method-aur" = "usr/share/wanderbooks/install-method" diff --git a/deploy/wanderbooks-server.service b/deploy/wanderbooks-server.service index 75ae263e..fbf376b7 100644 --- a/deploy/wanderbooks-server.service +++ b/deploy/wanderbooks-server.service @@ -50,9 +50,8 @@ ProtectHome=yes PrivateTmp=yes PrivateDevices=yes # No network but loopback: the tunnel reaches 127.0.0.1:7411, and the -# server reaches nothing out. A book whose backup target is a remote git -# repository needs that host allowed here (`IPAddressAllow=` its address) -# or its backups fail; see README.md. +# server reaches nothing out. Backups go to a folder on this machine's +# disks (see README.md), so they need no network. IPAddressDeny=any IPAddressAllow=localhost diff --git a/docs/architecture.md b/docs/architecture.md index c9cd1871..fca75099 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -487,9 +487,8 @@ already running with other flags keeps them; on a self-host machine `serve` is the unit's only holder. The unit sets `IPAddressDeny=any` and `IPAddressAllow=localhost`: the -server reaches nothing out. A book whose backup target is a remote git -repository therefore needs that host allowed in a drop-in (D-31 backups -still run on the server). The recipe, the head check for the move and the +server reaches nothing out. Backups go to a folder on the machine's own +disks and need no network (D-91). The recipe, the head check for the move and the two-account CI job are in `deploy/README.md`, `deploy/wanderbooks-server.service` and `.github/workflows/two-user.yml`; the checks are `crates/ledger-cli/tests/two_user.rs`. diff --git a/docs/install.md b/docs/install.md index 3fbf7944..c401de70 100644 --- a/docs/install.md +++ b/docs/install.md @@ -23,8 +23,8 @@ close the window: that quits Wanderbooks fully and closes your books. Where things are: the program is in `%LOCALAPPDATA%\Programs\Wanderbooks`; your books, keys and backups are in `%LOCALAPPDATA%\wanderbooks`. -Backups need Git for Windows (https://git-scm.com/download/win, or `winget -install --id Git.Git -e`); without it Wanderbooks works and says so. +Backups need nothing installed: choose a backup folder in Wanderbooks +(another disk, or a folder your cloud drive keeps in sync). ## macOS @@ -38,8 +38,9 @@ install --id Git.Git -e`); without it Wanderbooks works and says so. remove it, drag it to the Trash. Neither touches your books. Your books, keys and backups are in `~/Library/Application Support/wanderbooks`. -Backups need git: run `xcode-select --install` in Terminal (or `brew install -git`). +Backups need nothing installed: choose a backup folder in Wanderbooks +(another disk, or a folder iCloud, Dropbox, OneDrive or Google Drive keeps in +sync). ## Linux @@ -48,8 +49,8 @@ Ubuntu), the `.rpm` (Fedora), the Arch package, or the AppImage (one file: mark it executable, keep it where you put it, and run it). Open **Wanderbooks** from the menu. To update, install the newer package, or replace the AppImage. Your books are in `~/.local/share/wanderbooks` and are never touched by a package. -Backups need git (`sudo apt install git`, `sudo dnf install git`, -`sudo pacman -S git`). +Backups need nothing installed: choose a backup folder in Wanderbooks +(another disk, or a folder your sync program keeps). ## After it is installed diff --git a/docs/mcp-interface.md b/docs/mcp-interface.md index 41736caf..79c80df5 100644 --- a/docs/mcp-interface.md +++ b/docs/mcp-interface.md @@ -378,27 +378,21 @@ didn't open, with why). Protocol version 1: the requests are new, the (a drill, or a format upgrade not yet journaled, is stopped when the close begins, at its next look, so it never takes the last backup's turn; its scratch clone is removed and the books are unchanged): - a backup still running after that is stopped (git is sent SIGTERM, which - makes it remove its own lock files, and killed with all it started only - if it hasn't ended after 5 seconds) and waited for to end. The program - never writes to or deletes from a backup folder (it is the owner's, and - may be shared with other computers or a sync program): a lock git left - there when it had to be killed is left in place, recorded in - `ops/backup.jsonl` as `lock_left` with its whole path, and the target's - backup is marked failed with words naming the file and saying to remove - it only when nothing else is using the backup folder (`books.backup` - and the close's answer say the same; the next backup that finds the - lock gone goes on). In the book's own archive (`archive.git`, private to - the program; running git by hand inside it is unsupported) it removes - only the locks its own stopped git made, and, at open and when a backup - begins, locks older than ten minutes, each recorded `lock_removed`; + a backup still running after that is stopped (its copy of files + stops at the next piece, or the next 64 KiB of one) and waited for to + end. The program never rewrites or deletes anything in a backup folder + (it is the owner's, and may be shared with other computers or a sync + program): a backup stopped part way leaves pieces no manifest names and + the folder proves whole at its previous manifest, so there is nothing to + clean up and nothing to remove by hand. **What a close stops, and what it waits for.** At its start a close stops the calls and jobs that can do long I/O or loop over a book's whole journal or files, each at its next look: `books.back_up_now` and - a backup a timer asked for (git is stopped; the call answers that it was - stopped because the books are closing, its access record says + a backup a timer asked for (its copy is stopped; the call answers that it + was stopped because the books are closing, its access record says `refused: stopped_by_close`, and nothing it was doing is recorded as done; - a commit it had made stands), `books.verify` (once per journal line and + what it had written stands, and the folder still proves whole at its + previous manifest), `books.verify` (once per journal line and per stored file; a heal of a drifted database is begun only if no stop was asked before it, then finishes), `books.export_cpa_package` (once per stored file, unless it has journaled a decision, below), a drill, and a @@ -1329,75 +1323,74 @@ through the policy. ## Tools — backups -Books back themselves up (plan 3.7, D-30, -D-31): each keeps `archive.git`, a bare repository whose commits are its -journal, stored files, vault, keys and access log as they were (one -commit per backup, made under the store's lock, its message -`seq N head H` and, below, `book `), pushed fast-forward only to the targets the settings -name: `backup.git_remote` (the owner's private repository) and -`backup.folder` (a repository `.git` in a folder on another disk). -Not encrypted: the destinations keep it private. Backups run a little -after the books are last written (`--backup-quiet`, 30 s), when they -open, before they close, and on request; a failed one is retried after -15 minutes. Each target is drilled weekly: cloned, its chain replayed, -every stored file re-hashed, every TIN record the books name there with -its key, its head the one its commit records, its journal a byte prefix -of the live one (a failed drill is tried again at the server's next -hourly look, once 15 minutes have passed). A backup's tree is checked -before any of it is written out: plain files under the backed-up paths -only, never a link or a submodule. git runs with no hooks (in a -repository on this computer it pushes to as well), no ignore or -attributes rules of anyone's (a `.gitattributes` in a book's folder -refuses the backup) and no command-running transports; a repository on -this computer is used only if plain (a bare repository at that very -path, no settings of its own but where a copy came from, nothing sending -git elsewhere, no link where it or its parts are), and a backup folder that took backups and is gone is -reported as a disk not connected, never made again (restored books count -the backups of the books they were). Books restored beside the books they -were (under another id) don't push to those books' repository, which -would stop theirs: `books.backup` says it is paused for them until -another is named. A damaged backup record is set aside and begun again; -it never keeps the books shut. One book's drill holds the others' -backups until it ends (a backup at close waits at most a minute for -it). A target -whose push failed is left out of the backups after writes for 15 -minutes, then tried again, written to or not; the other targets don't -wait for it. Every -commit, push and drill is a record in the book's `ops/backup.jsonl` (a -chain log; a backup never moves the books' head), each target's records -keyed by the target itself. Setting `backup.*` (books.set_setting) needs -books:admin, as -backing up does: a backup is the whole book, its vault and key included. +Books back themselves up (plan 3.7, D-91, D-92): to the folder the settings +name, `backup.folder` (a folder on another disk, or one a sync service +keeps), as plain files written once (docs/backups.md): a folder for the +books holding a read-me, a `manifests/` folder, and the pieces the manifests +name, the journal and the access log as numbered segments, an index of the +stored files and the files themselves under their hash, the vault and keys +by content hash. The manifest is written last and makes a backup complete; +nothing in the folder is ever rewritten or deleted. Taking a backup holds +the store's lock only to cut the books (the journal's length and head, the +vault, the keys); the files are written after it. With a passphrase (D-92, +set up in the window; off by default) every file is sealed with +XChaCha20-Poly1305, the key derived with Argon2id (64 MiB, 3 passes, 1 +lane), names say no more than counts and sizes, and the key is kept on this +computer only. Backups run a little after the books are last written +(`--backup-quiet`, 30 s), when they open, before they close, and on request; +a failed one is retried after 15 minutes. The folder's backup is drilled +weekly: its books built and proven whole, every stored file re-hashed, every +TIN record the books name there with its key, its head the one its manifest +records, its journal a byte prefix of the live one (a failed drill is tried +again at the server's next hourly look, once 15 minutes have passed). A +backup is written only onto a folder whose newest whole manifest is a point +on the live journal; one holding other books, another history, or more than +these books have is said, and nothing is written. A backup folder that took +backups and is gone is reported as a disk not connected, never made again +(restored books count the backups of the books they were). Books restored +under another id back up to a folder of their own in the same place. A +damaged backup record is set aside and begun again; it never keeps the books +shut. A folder whose write failed is left out of the backups after writes +for 15 minutes, then tried again. Every cut, write and drill is a record in +the book's `ops/backup.jsonl` (a chain log; a backup never moves the books' +head), the folder's records keyed by the folder and the passphrase. Setting +`backup.*` (books.set_setting) needs books:admin, as backing up does: a +backup is the whole book, its vault and key included. Books that still name +a private repository (`backup.git_remote`, an older kind of backup) work as +ever; `books.backup`'s `note` says it is no longer used, and an older backup +history in the book's folder is left alone and said once. - `books.backup {}` (books:read) → `{ head_seq, targets: [{ target: - "repository" | "folder", at, last_ok_at, through_seq, stale, - last_error, last_drill_at, drill_error, paused }], note }`. `paused`: - not backed up there, these books being restored as a copy of others - (its `last_error` says so). `stale`: the target + "folder", at, last_ok_at, through_seq, stale, last_error, + last_drill_at, drill_error, sealed, disconnected }], note }`. + `sealed`: protected by a passphrase. `disconnected`: its disk isn't + there. `stale`: the target lacks the head, and the first try to back up what it lacks (since its last good backup, or ever) is more than a day old. `last_error`: its - last push's, or a later failed commit's. `note` - says what to set when no target is. `books.start` adds a next step when - none is set up, or one is stale, failing, paused or failed its drill. + last write's, or a later failed cut's. `note` + says what to set when no folder is, and what older settings or history are + no longer used. `books.start` adds a next step when none is set up, or the + folder is stale, failing or failed its drill. - `books.back_up_now { new_disk? }` (books:admin) → the same, after - backing up to every target now. `new_disk`: the backup folder's disk is + backing up to the folder now. `new_disk`: the backup folder's disk is new, so a folder that took these books' backups and holds none now is begun again (otherwise it is a disk not connected). The one tool whose - `openWorldHint` is true. A target paused for books restored as a copy - of others shows `paused` (and is no failure to retry). + `openWorldHint` is true. -Restoring is the owner's, from a terminal: `wanderbooks books restore -BACKUP [--id ID] [--replace] [--yes]` (the admin socket's `restore`, -previewed then confirmed against the previewed head; without `--id`, the -books keep the id of the books the backup holds, which the preview names, -else the repository's name; under another id they are a copy, and don't -push to those books' repository). The backup is -cloned into the root, proven whole as a drill proves it (but for the -live-journal check: there may be no live books), and built as an -adoption builds; it arrives as new books, or replaces books (`--replace`, -which are let go and moved whole into `legacy/-