package main // Exhibit 23. Root backs up every app nightly, verifies the copy, sends one off the server, and opens // the zoo's guestbook *in the backup copy* to count its rows (`backup_check = zoo.db guestbook` in // ratcloud.conf). All of it arrives in the fact backup.json. import "core:fmt" import "ratcloud:rc" e23 :: proc() -> Exhibit { return { n = 23, wing = "Operations", title = "Last night's backup works", promise = "Everything is backed up nightly, a copy leaves the server, and the backup is opened to prove it.", block = "Add `backup_check = ` to ratcloud.conf: after each nightly backup root counts that table in the copy and writes it to the fact backup.json.", src = {"e23_backup.odin", #load("e23_backup.odin", string)}, files = srcs({"ratcloud.conf", #load("ratcloud.conf", string)}), show = proc(me: ^rc.User) -> string { b := fact("backup.json") l := jget(b, "latest") if !jhas(b, "latest") do return `

No verified backup yet.

` o := jget(b, "offsite") rb := jget(l, "readback", env().env) // root reads back each environment's own copy rows, has_rows := jint(rb, "rows") 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") _ = has_rows off := fmt.tprintf("%s, %.1f MB encrypted", ago(parse_time(jstr(o, "at"))), f64(jint(o, "bytes")) / 1048576) if o != nil else "none yet" return fmt.tprintf(``, 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) }, check = proc() -> Check { b := fact("backup.json") l := jget(b, "latest") if !jhas(b, "latest") do return fail("the fact backup.json has no verified backup") age := f64(now() - parse_time(jstr(l, "at"))) / 3600 if age > 26 do return fail(fmt.tprintf("the newest verified backup is %.0f hours old", age)) rb := jget(l, "readback", env().env) 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 "")) o := jget(b, "offsite") if !jbool(o, "ok") || now() - parse_time(jstr(o, "at")) > 26 * 3600 do return fail("no copy left the server in the last day") 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"))) }, } }