Files
supermarket/internal/web/templates/backups-server.html
T
davidandClaude Opus 5.5 da16736fb4 Phase 10, part 9: the server package
compose.server.yaml runs Supermarket behind Caddy (HTTPS from Let's
Encrypt, Caddy's own CA or the team's), with Postgres on an internal
network and a nightly pg_dump kept two weeks. install-server.sh asks for
the domain, certificate and mail server, makes the secret key and database
password, starts it all and prints the setup link. Settings → Backups lists
the dumps on a server, and how the operator restores one. Checked end to
end in Docker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 09:37:34 -07:00

30 lines
2.3 KiB
HTML

{{define "content"}}{{template "settings-start" .}}{{with .Data}}
<h2>Backups</h2>
<p class="lede">Supermarket's database is Postgres, on the server. It's dumped every night at 03:00, and two weeks of dumps are kept. Keys and tokens are in it too, encrypted with the server's secret key: a dump restored elsewhere needs that key as well.</p>
{{if not .Dir}}
<section class="card warn"><p>Supermarket doesn't know where the dumps are (<code>SUPERMARKET_PG_BACKUPS</code>). With <code>compose.server.yaml</code>, they're in the <code>pgbackups</code> volume; whoever runs Postgres otherwise backs it up their own way.</p></section>
{{else}}
{{with .Err}}<p class="error">The dumps can't be read: {{.}}</p>{{end}}
{{with .Stale}}<p class="error">The last dump is from {{.Local.Format "2 Jan 2006"}}: the nightly backup isn't working. Check the backup service's log on the server.</p>{{end}}
{{if .Dumps}}
<p class="small">{{len .Dumps}} dump{{if ne (len .Dumps) 1}}s{{end}}, {{bytes .Total}} in all.</p>
<div class="table-wrap"><table>
<thead><tr><th>Made</th><th>File</th><th class="num">Size</th></tr></thead>
<tbody>{{range .Dumps}}<tr><td>{{.At.Local.Format "2 Jan 2006, 15:04"}}<br><span class="small muted">{{ago .At}}</span></td><td><code>{{.Name}}</code></td><td class="num">{{bytes .Size}}</td></tr>{{end}}</tbody>
</table></div>
{{else if not .Err}}<section class="card empty"><p>No dumps yet: the first is made when the backup service starts.</p></section>{{end}}
{{end}}
<section class="card">
<h2>Restoring</h2>
<p>Restoring is done on the server, by whoever runs it, so that no one can undo the team's work from a browser. Stop Supermarket, restore the dump over the database, and start it again:</p>
<pre id="restore">docker compose -f compose.server.yaml --env-file server.env stop supermarket
docker compose -f compose.server.yaml --env-file server.env exec backup \
pg_restore --clean --if-exists --no-owner -d supermarket /backups/supermarket-YYYY-MM-DD.dump
docker compose -f compose.server.yaml --env-file server.env start supermarket</pre>
<button type="button" class="secondary small" data-copy="restore">Copy</button>
<p class="help">To move to another server, <code>supermarket export</code> and <code>supermarket import</code> work too, from either database to either.</p>
</section>
{{end}}{{template "settings-end"}}{{end}}