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:
@@ -230,6 +230,9 @@ func (s *Server) Handler() (http.Handler, error) {
|
||||
mux.HandleFunc("POST /crm/{action}", s.crmAction)
|
||||
mux.HandleFunc("POST /crm/{id}/{action}", s.crmAction)
|
||||
|
||||
mux.HandleFunc("GET /settings/backups", s.backupsPage)
|
||||
mux.HandleFunc("POST /settings/backups/{action}", s.backupsAction)
|
||||
mux.HandleFunc("GET /settings/backups/file/{name}", s.backupDownload)
|
||||
mux.HandleFunc("GET /settings/core", s.corePage)
|
||||
mux.HandleFunc("GET /settings/core/checks", s.coreChecks)
|
||||
|
||||
@@ -300,6 +303,19 @@ func sameOrigin(r *http.Request) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// humanBytes is a file size for people: "840 KB", "12.3 MB".
|
||||
func humanBytes(n int64) string {
|
||||
switch {
|
||||
case n >= 1<<30:
|
||||
return fmt.Sprintf("%.1f GB", float64(n)/(1<<30))
|
||||
case n >= 1<<20:
|
||||
return fmt.Sprintf("%.1f MB", float64(n)/(1<<20))
|
||||
case n >= 1<<10:
|
||||
return fmt.Sprintf("%d KB", n>>10)
|
||||
}
|
||||
return fmt.Sprintf("%d bytes", n)
|
||||
}
|
||||
|
||||
var backticks = regexp.MustCompile("`([^`]+)`")
|
||||
|
||||
// ticks shows Markdown's `code` spans as code, the rest as plain text.
|
||||
@@ -313,6 +329,7 @@ func (s *Server) loadTemplates() error {
|
||||
"join": strings.Join,
|
||||
"ago": ago,
|
||||
"ticks": ticks,
|
||||
"bytes": humanBytes,
|
||||
"kindLabel": sites.KindLabel,
|
||||
"add": func(a, b int) int { return a + b },
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
|
||||
Reference in New Issue
Block a user