feat: add managed database capture and operator restore
PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
109
crates/tessera-core/src/restore.rs
Normal file
109
crates/tessera-core/src/restore.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
use crate::job::CaptureFormat;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Engine {
|
||||
Postgres,
|
||||
Mysql,
|
||||
}
|
||||
|
||||
impl CaptureFormat {
|
||||
pub fn engine(self) -> Option<Engine> {
|
||||
match self {
|
||||
Self::PostgresCustom | Self::PostgresSql => Some(Engine::Postgres),
|
||||
Self::MysqlSql => Some(Engine::Mysql),
|
||||
Self::Filesystem => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct DatabaseIdentity {
|
||||
pub instance: String,
|
||||
pub database: String,
|
||||
}
|
||||
|
||||
impl DatabaseIdentity {
|
||||
pub fn valid(&self, engine: Engine) -> bool {
|
||||
let instance_valid = match engine {
|
||||
Engine::Postgres => self
|
||||
.instance
|
||||
.parse::<u64>()
|
||||
.is_ok_and(|id| id.to_string() == self.instance),
|
||||
Engine::Mysql => {
|
||||
Uuid::parse_str(&self.instance).is_ok_and(|id| id.to_string() == self.instance)
|
||||
}
|
||||
};
|
||||
instance_valid
|
||||
&& (1..=255).contains(&self.database.len())
|
||||
&& !self.database.chars().any(char::is_control)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RestoreTarget {
|
||||
pub id: Uuid,
|
||||
pub application_id: Uuid,
|
||||
pub outpost_id: Uuid,
|
||||
pub name: String,
|
||||
pub engine: Engine,
|
||||
pub identity: DatabaseIdentity,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct RestoreRequest {
|
||||
pub snapshot_id: Uuid,
|
||||
pub target_id: Uuid,
|
||||
pub confirmation: String,
|
||||
}
|
||||
|
||||
impl RestoreRequest {
|
||||
pub fn confirmation(snapshot: Uuid, target: Uuid) -> String {
|
||||
format!("RESTORE {snapshot} TO {target}")
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct RestoreJob {
|
||||
pub id: Uuid,
|
||||
pub snapshot_id: Uuid,
|
||||
pub target: RestoreTarget,
|
||||
pub actor: String,
|
||||
pub status: String,
|
||||
pub phase: String,
|
||||
pub safety_snapshot_id: Option<Uuid>,
|
||||
pub created_at: i64,
|
||||
pub updated_at: i64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct RestoreArtifact {
|
||||
pub format: CaptureFormat,
|
||||
pub identity: DatabaseIdentity,
|
||||
pub sha256: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct RestoreLease {
|
||||
pub job: RestoreJob,
|
||||
pub token: Uuid,
|
||||
pub artifact: RestoreArtifact,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum RestoreProgress {
|
||||
Heartbeat,
|
||||
Checking,
|
||||
Safety,
|
||||
InvalidPayload,
|
||||
WrongTarget,
|
||||
SafetyFailed,
|
||||
Applied,
|
||||
ApplyFailed,
|
||||
}
|
||||
Reference in New Issue
Block a user