feat: use Restic for encrypted incremental backups
Keep legacy restores readable while using Restic for new captures, scoped Wormhole repositories, and chunk garbage collection.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
use crate::db::OrbitRow;
|
||||
use crate::state::HubState;
|
||||
use anyhow::{Context, Result};
|
||||
use tessera_core::config::ProviderKind;
|
||||
use tessera_core::manifest::SnapshotManifest;
|
||||
use tessera_providers::provider_from_config;
|
||||
use tessera_providers::{FilesystemConfig, PostgresProvider};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn run_orbit_internal(state: HubState, orbit_id: Uuid) -> Result<Option<Uuid>> {
|
||||
@@ -34,40 +33,57 @@ pub async fn run_orbit_internal(state: HubState, orbit_id: Uuid) -> Result<Optio
|
||||
async fn run_orbit_row(state: &HubState, orbit: OrbitRow) -> Result<Option<Uuid>> {
|
||||
state.db.set_orbit_status(orbit.id, "running").await?;
|
||||
|
||||
let provider_kind = match orbit.provider.as_str() {
|
||||
"filesystem" => ProviderKind::Filesystem,
|
||||
"postgres" => ProviderKind::Postgres,
|
||||
"command" => ProviderKind::Command,
|
||||
other => anyhow::bail!("unknown provider '{other}'"),
|
||||
};
|
||||
let config: serde_json::Value = serde_json::from_str(&orbit.provider_config)?;
|
||||
let provider = provider_from_config(&provider_kind, &config)?;
|
||||
let capture = provider.capture().await.context("capture")?;
|
||||
|
||||
let manifest = SnapshotManifest {
|
||||
let mut manifest = SnapshotManifest {
|
||||
snapshot_id: Uuid::new_v4(),
|
||||
orbit_id: orbit.id,
|
||||
orbit_name: orbit.name.clone(),
|
||||
labels: capture.labels,
|
||||
labels: vec![orbit.provider.clone()],
|
||||
provider: orbit.provider.clone(),
|
||||
paths: vec![],
|
||||
restore_hints: capture.restore_hints,
|
||||
restore_hints: serde_json::Value::Null,
|
||||
};
|
||||
|
||||
let mut vault = state.vault.write().await;
|
||||
let snap = vault
|
||||
.snapshot(manifest, &capture.payload, orbit.dry_run)
|
||||
.context("vault snapshot")?;
|
||||
|
||||
let (payload, max_file_bytes) = match orbit.provider.as_str() {
|
||||
"filesystem" => {
|
||||
let config: FilesystemConfig = serde_json::from_value(config)?;
|
||||
manifest.paths = config.paths;
|
||||
(None, config.max_file_bytes)
|
||||
}
|
||||
"postgres" => {
|
||||
let provider = PostgresProvider::from_config(&config)?;
|
||||
let file = tempfile::tempfile()?;
|
||||
manifest.restore_hints = provider.dump_to(file.try_clone()?).await?;
|
||||
(Some(file), None)
|
||||
}
|
||||
"wormhole" => anyhow::bail!("Wormhole backups are started by the outpost agent"),
|
||||
"command" => {
|
||||
anyhow::bail!("command provider is outside this release; use filesystem or postgres")
|
||||
}
|
||||
other => anyhow::bail!("unknown provider '{other}'"),
|
||||
};
|
||||
let vault = state.vault.clone().read_owned().await;
|
||||
let snap = tokio::task::spawn_blocking(move || {
|
||||
match payload {
|
||||
Some(file) => vault.snapshot_payload(manifest, file, orbit.dry_run),
|
||||
None => vault.snapshot_files(manifest, max_file_bytes, orbit.dry_run),
|
||||
}
|
||||
.context("vault snapshot")
|
||||
})
|
||||
.await??;
|
||||
let snap_id = snap.id;
|
||||
let retained_snapshot = if orbit.dry_run {
|
||||
None
|
||||
} else {
|
||||
let pruned = vault.prune_orbit_with_decay(orbit.id, &orbit.decay_preset)?;
|
||||
let pruned = state
|
||||
.vault
|
||||
.write()
|
||||
.await
|
||||
.prune_orbit_with_decay(orbit.id, &orbit.decay_preset)?;
|
||||
state
|
||||
.db
|
||||
.audit("decay.pruned", &format!("orbit={}", orbit.name))
|
||||
.await?;
|
||||
(!pruned.contains(&snap.id)).then_some(snap.id)
|
||||
(!pruned.contains(&snap_id)).then_some(snap_id)
|
||||
};
|
||||
|
||||
let status = if orbit.dry_run {
|
||||
@@ -84,7 +100,7 @@ async fn run_orbit_row(state: &HubState, orbit: OrbitRow) -> Result<Option<Uuid>
|
||||
} else {
|
||||
"orbit.completed"
|
||||
},
|
||||
&format!("snapshot={}", snap.id),
|
||||
&format!("snapshot={snap_id}"),
|
||||
)
|
||||
.await?;
|
||||
Ok(retained_snapshot)
|
||||
|
||||
Reference in New Issue
Block a user