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:
@@ -2,15 +2,50 @@ use crate::db::OrbitRow;
|
||||
use crate::state::HubState;
|
||||
use anyhow::{Context, Result};
|
||||
use tessera_core::manifest::SnapshotManifest;
|
||||
use tessera_providers::{FilesystemConfig, PostgresProvider};
|
||||
use tessera_providers::{FilesystemConfig, MysqlSource, PostgresProvider, PostgresSource};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn run_orbit_internal(state: HubState, orbit_id: Uuid) -> Result<Option<Uuid>> {
|
||||
let orbits = state.db.list_orbits().await?;
|
||||
let orbit = orbits
|
||||
.into_iter()
|
||||
.find(|o| o.id == orbit_id)
|
||||
.context("orbit not found")?;
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(tag = "engine", rename_all = "snake_case")]
|
||||
pub(super) enum DatabaseSource {
|
||||
Postgres(PostgresSource),
|
||||
Mysql(MysqlSource),
|
||||
}
|
||||
|
||||
impl DatabaseSource {
|
||||
pub(super) fn valid_endpoint(&self) -> bool {
|
||||
let (host, port, database, user, password_file) = match self {
|
||||
Self::Postgres(source) if source.bastion.is_none() => (
|
||||
&source.host,
|
||||
source.port,
|
||||
&source.database,
|
||||
&source.user,
|
||||
&source.password_file,
|
||||
),
|
||||
Self::Mysql(MysqlSource::Direct {
|
||||
host,
|
||||
port,
|
||||
database,
|
||||
user,
|
||||
password_file,
|
||||
..
|
||||
}) => (host, *port, database, user, password_file),
|
||||
_ => return false,
|
||||
};
|
||||
port != 0
|
||||
&& password_file.is_absolute()
|
||||
&& [host, database, user]
|
||||
.iter()
|
||||
.all(|value| !value.trim().is_empty() && !value.chars().any(char::is_control))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run_orbit_internal(state: HubState, orbit: OrbitRow) -> Result<Option<Uuid>> {
|
||||
anyhow::ensure!(
|
||||
orbit.provider != "wormhole",
|
||||
"Wormhole backups are started by the outpost agent"
|
||||
);
|
||||
let orbit_id = orbit.id;
|
||||
anyhow::ensure!(
|
||||
state.active_orbits.lock().await.insert(orbit_id),
|
||||
"orbit already running"
|
||||
@@ -49,6 +84,23 @@ async fn run_orbit_row(state: &HubState, orbit: OrbitRow) -> Result<Option<Uuid>
|
||||
manifest.paths = config.paths;
|
||||
(None, config.max_file_bytes)
|
||||
}
|
||||
"database" => {
|
||||
let source = serde_json::from_value::<DatabaseSource>(config)?;
|
||||
let file = tempfile::tempfile()?;
|
||||
let (engine, format) = match source {
|
||||
DatabaseSource::Postgres(source) => {
|
||||
source.dump_to(file.try_clone()?, "plain").await?;
|
||||
("postgres", "plain")
|
||||
}
|
||||
DatabaseSource::Mysql(source) => {
|
||||
source.dump_to(file.try_clone()?).await?;
|
||||
("mysql", "plain")
|
||||
}
|
||||
};
|
||||
manifest.provider = engine.into();
|
||||
manifest.restore_hints = serde_json::json!({"engine": engine, "format": format});
|
||||
(Some(file), None)
|
||||
}
|
||||
"postgres" => {
|
||||
let provider = PostgresProvider::from_config(&config)?;
|
||||
let file = tempfile::tempfile()?;
|
||||
|
||||
Reference in New Issue
Block a user