feat(sv): Backups card — offsite DR status (Core-4 -> Farm) + /api/backups (2.6.0)
migration 026 backup_runs; POST ingest (owner) from offsite-backup.sh, GET for the Sacred Valley card showing last run, per-guest sizes, Farm free, schedule. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
21
lib/db/repos/backups.js
Normal file
21
lib/db/repos/backups.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { pool } from '../pool.js';
|
||||
|
||||
export async function record({ ok = true, total_bytes = null, won_free_bytes = null,
|
||||
guests = null, duration_sec = null }) {
|
||||
const { rows: [r] } = await pool.query(
|
||||
`INSERT INTO backup_runs (ok, total_bytes, won_free_bytes, guests, duration_sec)
|
||||
VALUES ($1,$2,$3,$4,$5) RETURNING *`,
|
||||
[ok, total_bytes, won_free_bytes, guests ? JSON.stringify(guests) : null, duration_sec]);
|
||||
return r;
|
||||
}
|
||||
|
||||
export async function latest() {
|
||||
const { rows: [r] } = await pool.query(
|
||||
`SELECT * FROM backup_runs ORDER BY id DESC LIMIT 1`);
|
||||
return r || null;
|
||||
}
|
||||
|
||||
export async function count() {
|
||||
const { rows: [r] } = await pool.query(`SELECT count(*)::int AS n FROM backup_runs`);
|
||||
return r.n;
|
||||
}
|
||||
Reference in New Issue
Block a user