runtime_cli/commands/backup.rs
1//! `runtime backup` — operator-facing snapshot operations.
2//!
3//! `runtime backup create` — calls the admin-only
4//! `createBackupSnapshot` mutation, returning the on-disk path where
5//! the server wrote the tarball.
6//!
7//! The restore path is intentionally not exposed via this CLI: a
8//! restore needs the API stopped, the data directory wiped, and the
9//! pg_restore run by an operator with shell access to the host.
10//! Putting a one-button "restore" in a CLI talking to a live API
11//! makes the foot-gun too easy. The restore runbook in
12//! `docs/operator/disaster-recovery.md` is the sanctioned path.
13
14use anyhow::Result;
15use clap::Subcommand;
16use serde_json::json;
17
18use crate::client;
19
20#[derive(Debug, Subcommand)]
21pub enum BackupCmd {
22 /// Trigger an on-demand snapshot of the live DB + storage root.
23 /// Useful before a risky operation. Admin-only.
24 Create,
25}
26
27pub fn run(cmd: BackupCmd) -> Result<()> {
28 match cmd {
29 BackupCmd::Create => create(),
30 }
31}
32
33fn create() -> Result<()> {
34 let (cli, _cfg) = client::authenticated()?;
35 let data = cli.execute("mutation { createBackupSnapshot }", json!({}))?;
36 let path = data["createBackupSnapshot"]
37 .as_str()
38 .unwrap_or("(no path returned)");
39 println!("Snapshot written to {path}");
40 Ok(())
41}