23. Last night's backup works
Everything is backed up nightly, a copy leaves the server, and the backup is opened to prove it.
Add `backup_check = <db> <table>` to ratcloud.conf: after each nightly backup root counts that table in the copy and writes it to the fact backup.json.
This is the code serving the zoo right now: the bytes this very program was built from (each file is embedded when the zoo is compiled), at commit
55c71513c5 (staging). The zoo's own self-check fetches this page and compares it byte for byte with the file it runs.
e23_backup.odin sha256 dffed338c934 · raw
1package main 2 3// Exhibit 23. Root backs up every app nightly, verifies the copy, sends one off the server, and opens 4// the zoo's guestbook *in the backup copy* to count its rows (`backup_check = zoo.db guestbook` in 5// ratcloud.conf). All of it arrives in the fact backup.json. 6 7import "core:fmt" 8import "ratcloud:rc" 9 10e23 :: proc() -> Exhibit { 11 return { 12 n = 23, wing = "Operations", 13 title = "Last night's backup works", 14 promise = "Everything is backed up nightly, a copy leaves the server, and the backup is opened to prove it.", 15 block = "Add `backup_check = <db> <table>` to ratcloud.conf: after each nightly backup root counts that table in the copy and writes it to the fact backup.json.", 16 src = {"e23_backup.odin", #load("e23_backup.odin", string)}, 17 files = srcs({"ratcloud.conf", #load("ratcloud.conf", string)}), 18 show = proc(me: ^rc.User) -> string { 19 b := fact("backup.json") 20 l := jget(b, "latest") 21 if !jhas(b, "latest") do return `<p class="muted">No verified backup yet.</p>` 22 o := jget(b, "offsite") 23 rb := jget(l, "readback", env().env) // root reads back each environment's own copy 24 rows, has_rows := jint(rb, "rows") 25 read := fmt.tprintf("%d guestbook signature(s), counted in the backup copy", rows) if jhas(rb, "rows") else cat("no guestbook count read from it", cat(": ", h(jstr(rb, "error"))) if jhas(rb, "error") else " yet") 26 _ = has_rows 27 off := fmt.tprintf("%s, %.1f MB encrypted", ago(parse_time(jstr(o, "at"))), f64(jint(o, "bytes")) / 1048576) if o != nil else "none yet" 28 return fmt.tprintf(`<ul class="list"><li><span class="tag ok">backup</span><span>%s, %.1f MB, verified</span></li><li><span class="tag %s">read back</span><span>%s</span></li><li><span class="tag %s">offsite</span><span>%s</span></li></ul>`, 29 ago(parse_time(jstr(l, "at"))), f64(jint(l, "bytes")) / 1048576, "ok" if jhas(rb, "rows") else "bad", read, "ok" if jbool(o, "ok") else "bad", off) 30 }, 31 check = proc() -> Check { 32 b := fact("backup.json") 33 l := jget(b, "latest") 34 if !jhas(b, "latest") do return fail("the fact backup.json has no verified backup") 35 age := f64(now() - parse_time(jstr(l, "at"))) / 3600 36 if age > 26 do return fail(fmt.tprintf("the newest verified backup is %.0f hours old", age)) 37 rb := jget(l, "readback", env().env) 38 if !jhas(rb, "rows") do return fail(cat("the backup has no guestbook count read back from it", cat(": ", jstr(rb, "error")) if jhas(rb, "error") else "")) 39 o := jget(b, "offsite") 40 if !jbool(o, "ok") || now() - parse_time(jstr(o, "at")) > 26 * 3600 do return fail("no copy left the server in the last day") 41 return pass(fmt.tprintf("backup %.0f hours old, %d guestbook rows read back from it, offsite copy %s", age, jint(rb, "rows"), jstr(o, "stamp"))) 42 }, 43 } 44}
ratcloud.conf sha256 da8f09e08292 · raw
1# The zoo's settings. rc builds the app and renders nginx and the jobs from this; a mistake refuses the push. 2name = Zoo 3description = See every building block working 4# Odin compiled to wasm (main.odin and the exhibits, e*.odin), built on the box at every push. 5runtime = wasm 6# 10: anyone may listen to the counter. 11: `auth` makes nginx ask the zoo first (channel_ok). 7channels = counter, mine auth 8# 21: the clock. 22: the self-check that turns every self-running exhibit into a light. 8: the nightly 9# job puts zoo-broken's deliberate typo back if a valid push cleared it. 25: once a day the robot asks 10# its workbench for a change (the job looks every half hour). Each is a name main.odin's job answers. 11cron = tick every 5m, selfcheck every 5m, nightly every 1d, workbench every 30m 12# The robot's tools (8, 18, 30): git and ssh as zoo-robot, granted by root (rc cap zoo git ssh --as zoo-robot). 13capabilities = git, ssh 14max_body = 1M 15# 23: after each nightly backup, root counts the guestbook in the backup copy. 16backup_check = zoo.db guestbook 17smoke = tests/smoke.odin