Phase 6 part 1: database backups

Backups with SQLite's VACUUM INTO into <data>/backups: on request
(Settings → Backups, supermarket backup [note]), before every schema
migration, and daily, keeping 7 dailies and 4 weeklies. Listed with size
and schema; downloadable and deletable. The old app.db.pre-* copies are
moved in, with their -wal files folded in first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 14:38:23 -07:00
co-authored by Claude Opus 5.5
parent c425f49c93
commit 5313369328
14 changed files with 1039 additions and 4 deletions
+60 -3
View File
@@ -1348,11 +1348,66 @@ under Sections and pages.
**Phase 5 is complete** (parts 1–5). Not yet tried for real: building a
page (a paid AI call) and pushing it to the real repository.
### Phase 6: Backups, lead forms, the LinkedIn page, new sites
**Started 2026-11-22** on branch `phase6`, after Phase 5 was merged into
`main`. Phases 0–5 had covered the plan; the user chose to make Phase 6
of four further pieces: the first three future enhancements below, and a
shared theme for new sites (deferred in Phase 5).
**Parts, in order, a commit after each:**
1. **Backups.** As designed under Future enhancements, item 2: SQLite's own
backup (`VACUUM INTO`), into `backups/`; made on request (Settings →
Backups, `supermarket backup [note]`), before every schema migration,
and daily; kept 7 daily and 4 weekly, the rest until deleted; listed
with size and schema, downloadable and deletable; the old
`app.db.pre-*` copies moved in.
2. **Restore.** From a backup in the list, an uploaded one, or `supermarket
restore <file>`: checked (integrity, schema not newer), the current
database backed up first, then swapped in and the app restarted.
`supermarket backup --with-secrets` for moving machines.
3. **Inbound lead forms.** The sites' `form` sections post to EspoCRM's own
lead capture (Supermarket is local-only, so it can't take the posts
itself), with the buying signal from the page's campaign tag. Supermarket
sets the capture up, puts its address in the site's settings by pull
request, and counts the leads in the funnel.
4. **The LinkedIn company page.** As designed under Future enhancements,
item 1: the second app's keys, choosing the page, and posting as the
page or the profile per draft. Built against LinkedIn's documented API;
used for real once LinkedIn approves the app.
5. **New sites from a shared theme.** A Hugo theme of sections common to
federated-website and webcoredesktop, and creating a new site from it:
a new Gitea repository, a first set of pages built by Part 3 of Phase 5,
and a preview. Planned in detail when it starts.
**Part 1 built (2026-11-22; no schema change).** `internal/backup` makes
backups with `VACUUM INTO` (to a `.part` file, then renamed; mode 0600)
into `<data>/backups`, named `app-<yyyymmdd>-<hhmmss>-<kind>[-<note>].db`
(kinds: manual, migration, daily, restore, legacy). `db.BeforeMigrate`
backs up an existing database before any pending migration
(`before-schema-<n>`; a failed backup stops the migration); a new database
isn't backed up. The app makes the daily backup at start and then hourly
checks whether one is due, pruning dailies to the newest 7 plus the newest
of each of the 4 weeks before. Settings → Backups lists them (when, why,
size, schema; unreadable files are flagged), makes one with a note,
downloads and deletes; only names from the list are served. `supermarket
backup [note]` and `supermarket backups` run the binary in the container
with `docker exec`; it opens the database beside the app without
migrating it. On start, the old `app.db.pre-*` copies are moved in as
*legacy* backups dated by their file time, with any `-wal` folded in
first; one that fails the integrity check is left in place. Live: all 23
moved. Some show an older schema than the database had when they were
taken (pre-phase5-part5 is at 22, not 23): plain `cp` missed writes still
in the WAL, as feared. The live database is 60 MB (mostly Stripe objects),
so the backups folder holds about 620 MB; old legacy copies can be deleted
from the page.
### Future enhancements
Not in any phase yet; picked up when the user asks.
1. **Post to the LinkedIn company page** (deferred 2026-11-21). Today posts
1. **Post to the LinkedIn company page** (deferred 2026-11-21; Phase 6,
part 4). Today posts
go to the signed-in member's profile (`w_member_social`). Posting as the
Federated Computer page needs LinkedIn's **Community Management API**,
which LinkedIn approves by hand.
@@ -1374,7 +1429,7 @@ Not in any phase yet; picked up when the user asks.
and .../community-management/community-management-overview.
2. **Back up the database and restore from a backup** (asked for
2026-11-21). Today backups are copies made by hand before risky changes
2026-11-21; Phase 6, parts 1 and 2). Today backups are copies made by hand before risky changes
(`app.db.pre-phase1`, `app.db.pre-dedupe`, …) in the data folder. A plain
`cp` of a running database in WAL mode can miss recent writes, so
backups must use SQLite's own backup (`VACUUM INTO` or the online backup
@@ -1452,7 +1507,9 @@ Phase 0 (incl. Hermes bridge test) ──► Phase 1 (content)
│ mail on the Core, Plausible, Stripe key
├──► Phase 3 (SEO) ──────── needs: Google OAuth (Search Console), Gitea token
├──► Phase 4 (metrics) ──── needs: Stripe key; CRM reads for pipeline
└──► Phase 5 (sites) ────── needs: Gitea token
├──► Phase 5 (sites) ────── needs: Gitea token
└──► Phase 6 (backups; lead forms ─ needs: EspoCRM lead capture;
LinkedIn page ─ needs: LinkedIn's approval; new sites)
```
Phases 1, 3, 5 and the Stripe half of 4 depend only on Phase 0.