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:
@@ -81,6 +81,14 @@ async fn beam_once(cli: &Cli) -> Result<()> {
|
||||
let token = cli.upload_token.clone().context("TESSERA_UPLOAD_TOKEN")?;
|
||||
let orbit_id = cli.orbit_id.clone().context("TESSERA_ORBIT_ID")?;
|
||||
|
||||
if let Some(repository) = std::env::var_os("TESSERA_RESTIC_REPOSITORY") {
|
||||
let repository = repository
|
||||
.to_str()
|
||||
.context("TESSERA_RESTIC_REPOSITORY must be UTF-8")?;
|
||||
let id = uuid::Uuid::parse_str(&orbit_id).context("invalid TESSERA_ORBIT_ID")?;
|
||||
return beam_restic(repository, &hub, &token, id).await;
|
||||
}
|
||||
|
||||
let config = serde_json::json!({ "paths": ["./"] });
|
||||
let provider = provider_from_config(&ProviderKind::Filesystem, &config)?;
|
||||
let capture = provider.capture().await?;
|
||||
@@ -112,3 +120,55 @@ async fn beam_once(cli: &Cli) -> Result<()> {
|
||||
info!("beamed {} bytes via wormhole session {session_id}", capture.payload.len());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn beam_restic(repository: &str, hub: &str, token: &str, orbit_id: uuid::Uuid) -> Result<()> {
|
||||
let authority = repository
|
||||
.strip_prefix("rest:https://")
|
||||
.and_then(|url| url.split('/').next());
|
||||
anyhow::ensure!(
|
||||
authority.is_some_and(|host| !host.is_empty() && !host.contains('@')),
|
||||
"TESSERA_RESTIC_REPOSITORY must be a rest:https:// URL without embedded credentials"
|
||||
);
|
||||
let output = tokio::process::Command::new("restic")
|
||||
.env("RESTIC_REPOSITORY", repository)
|
||||
.env_remove("RESTIC_REPOSITORY_FILE")
|
||||
.args(["backup", "--json", "--quiet", "--force", "--", "."])
|
||||
.stdin(std::process::Stdio::null())
|
||||
.kill_on_drop(true)
|
||||
.output()
|
||||
.await
|
||||
.context("starting restic (install restic on PATH)")?;
|
||||
anyhow::ensure!(
|
||||
output.status.success(),
|
||||
"restic backup failed ({}): {}",
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stderr).trim()
|
||||
);
|
||||
let summary: serde_json::Value = serde_json::from_str(
|
||||
std::str::from_utf8(&output.stdout)?
|
||||
.lines()
|
||||
.last()
|
||||
.context("missing restic summary")?,
|
||||
)?;
|
||||
let snapshot = summary["snapshot_id"]
|
||||
.as_str()
|
||||
.context("missing restic snapshot ID")?;
|
||||
let body = serde_json::json!({ "orbit_id": orbit_id, "snapshot_id": snapshot });
|
||||
let reply = http::post_json(
|
||||
&format!("{hub}/api/v1/wormhole/restic/commit"),
|
||||
&body,
|
||||
&[("x-tessera-upload-token", token)],
|
||||
)
|
||||
.with_context(|| format!("register Restic snapshot {snapshot}"))?;
|
||||
let reply: serde_json::Value = serde_json::from_str(&reply)?;
|
||||
let registered = reply["snapshot_id"]
|
||||
.as_str()
|
||||
.context("hub did not register the Restic snapshot")?;
|
||||
info!(
|
||||
snapshot,
|
||||
registered,
|
||||
stored_bytes = summary["data_added_packed"].as_u64(),
|
||||
"committed Restic backup"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user