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
+33
View File
@@ -0,0 +1,33 @@
{{define "content"}}{{template "settings-start" .}}{{with .Data}}{{$d := .}}
<h2>Backups</h2>
<p class="lede">Copies of Supermarket's database: your profile, inventory, signals, prospects, drafts, SEO and metrics. Each one is a single SQLite file. Your keys and tokens aren't in them; they stay in <code>secrets.json</code>.</p>
<section class="card">
<p>Supermarket backs up by itself once a day, and before every update that changes the database. The last 7 daily backups are kept, plus one a week for 4 weeks. The ones made before an update, before a restore, and the ones you make are kept until you delete them.</p>
<form method="post" action="/settings/backups/now" class="inline-form">
<label>Note <span class="muted">(optional)</span> <input name="note" placeholder="before the big import" maxlength="60"></label>
<button type="submit" data-busy="Backing up…">Back up now</button>
</form>
<p class="small muted">They're kept in <code>{{.Dir}}</code>, on this computer. From a terminal: <code>supermarket backup [note]</code> and <code>supermarket backups</code>.</p>
</section>
{{if .Backups}}
<p class="small">{{len .Backups}} backup{{if ne (len .Backups) 1}}s{{end}}, {{bytes .Total}} in all. This version of Supermarket is at schema {{.Schema}}.</p>
<div class="table-wrap"><table>
<thead><tr><th>Made</th><th>Why</th><th class="num">Size</th><th class="num">Schema</th><th></th></tr></thead>
<tbody>{{range .Backups}}<tr>
<td>{{.At.Format "2 Jan 2006, 15:04"}}<br><span class="small muted">{{ago .At}}</span></td>
<td>{{if eq .Kind "manual"}}By you{{else if eq .Kind "migration"}}Before an update{{else if eq .Kind "daily"}}Daily{{if not (index $d.Keep .Name)}} <span class="muted">(next to go)</span>{{end}}{{else if eq .Kind "restore"}}Before a restore{{else}}An older copy{{end}}{{with .Note}}<br><span class="small muted">{{.}}</span>{{end}}</td>
<td class="num">{{bytes .Size}}</td>
<td class="num">{{if ge .Schema 0}}{{.Schema}}{{else}}<span class="error-text" title="{{.Err}}">unreadable</span>{{end}}</td>
<td><div class="row-actions">
<a class="button secondary small" href="/settings/backups/file/{{.Name}}" download>Download</a>
<form method="post" action="/settings/backups/delete" data-confirm="Delete the backup from {{.At.Format "2 Jan 2006, 15:04"}}?">
<input type="hidden" name="name" value="{{.Name}}"><button type="submit" class="secondary small">Delete</button></form>
</div></td>
</tr>{{end}}</tbody>
</table></div>
{{else}}
<section class="card empty"><p>No backups yet. The first daily one is made when Supermarket starts.</p></section>
{{end}}
{{end}}{{template "settings-end"}}{{end}}