chore: rustfmt the workspace and make clippy -D warnings pass
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,8 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
use tessera_core::job::{
|
||||
CaptureFormat, CaptureLease, CaptureProgress, CaptureReport, ResticCaptureCommit, CAPTURE_HEARTBEAT_SECONDS,
|
||||
CaptureFormat, CaptureLease, CaptureProgress, CaptureReport, ResticCaptureCommit,
|
||||
CAPTURE_HEARTBEAT_SECONDS,
|
||||
};
|
||||
use tessera_core::restore::DatabaseIdentity;
|
||||
use tessera_providers::{MysqlSource, PostgresSource};
|
||||
@@ -83,9 +84,9 @@ pub async fn run(cli: &Cli, path: &Path) -> Result<()> {
|
||||
"capture timeout must be positive"
|
||||
);
|
||||
anyhow::ensure!(
|
||||
profiles
|
||||
.values()
|
||||
.all(|profile| profile.source.is_some() || !profile.paths.is_empty() || !profile.targets.is_empty()),
|
||||
profiles.values().all(|profile| profile.source.is_some()
|
||||
|| !profile.paths.is_empty()
|
||||
|| !profile.targets.is_empty()),
|
||||
"application requires a source or at least one restore target"
|
||||
);
|
||||
let url = cli
|
||||
@@ -195,7 +196,11 @@ async fn capture(hub: &Arc<Hub>, lease: &CaptureLease, profile: &Profile) -> Res
|
||||
}
|
||||
let identity = match before {
|
||||
Some(identity)
|
||||
if lease.profile.format.engine().is_some_and(|engine| identity.valid(engine))
|
||||
if lease
|
||||
.profile
|
||||
.format
|
||||
.engine()
|
||||
.is_some_and(|engine| identity.valid(engine))
|
||||
&& probe_identity(source).await.as_ref() == Some(&identity) =>
|
||||
{
|
||||
Some(identity)
|
||||
@@ -248,39 +253,73 @@ async fn commit_backup(
|
||||
identity: Option<DatabaseIdentity>,
|
||||
) -> Result<()> {
|
||||
let result = tokio::time::timeout(Duration::from_secs(profile.timeout_seconds), async {
|
||||
let repository = profile.restic_repository.as_deref().context("configure the profile Restic repository")?;
|
||||
let repository = profile
|
||||
.restic_repository
|
||||
.as_deref()
|
||||
.context("configure the profile Restic repository")?;
|
||||
let mut command = crate::restic_command(repository)?;
|
||||
if let Some(path) = &profile.restic_password_file {
|
||||
command.env_remove("RESTIC_PASSWORD").env_remove("RESTIC_PASSWORD_COMMAND")
|
||||
command
|
||||
.env_remove("RESTIC_PASSWORD")
|
||||
.env_remove("RESTIC_PASSWORD_COMMAND")
|
||||
.env("RESTIC_PASSWORD_FILE", path);
|
||||
}
|
||||
if let Some(path) = &profile.rest_server_password_file {
|
||||
let password = tokio::fs::read_to_string(path).await.context("read Rest Server password")?;
|
||||
command.env("RESTIC_REST_USERNAME", lease.profile.orbit_id.to_string())
|
||||
.env("RESTIC_REST_PASSWORD", password.trim_end_matches(['\r', '\n']));
|
||||
let password = tokio::fs::read_to_string(path)
|
||||
.await
|
||||
.context("read Rest Server password")?;
|
||||
command
|
||||
.env("RESTIC_REST_USERNAME", lease.profile.orbit_id.to_string())
|
||||
.env(
|
||||
"RESTIC_REST_PASSWORD",
|
||||
password.trim_end_matches(['\r', '\n']),
|
||||
);
|
||||
}
|
||||
command.args(["backup", "--json", "--quiet", "--tag", &format!("tessera-{}", lease.job_id)]);
|
||||
command.args([
|
||||
"backup",
|
||||
"--json",
|
||||
"--quiet",
|
||||
"--tag",
|
||||
&format!("tessera-{}", lease.job_id),
|
||||
]);
|
||||
let sha256 = if let Some(mut file) = stage {
|
||||
let (file, hash) = tokio::task::spawn_blocking(move || {
|
||||
let (_, hash) = digest_file(&mut file)?;
|
||||
file.seek(SeekFrom::Start(0))?;
|
||||
Ok::<_, anyhow::Error>((file, hash))
|
||||
}).await??;
|
||||
command.args(["--stdin", "--stdin-filename", "payload"]).stdin(Stdio::from(file));
|
||||
})
|
||||
.await??;
|
||||
command
|
||||
.args(["--stdin", "--stdin-filename", "payload"])
|
||||
.stdin(Stdio::from(file));
|
||||
Some(hash)
|
||||
} else {
|
||||
command.arg("--").args(&profile.paths);
|
||||
None
|
||||
};
|
||||
let snapshot_id = crate::restic_snapshot(command).await?;
|
||||
let body = serde_json::to_value(ResticCaptureCommit { lease_id: lease.lease_id, snapshot_id, identity, sha256 })?;
|
||||
let body = serde_json::to_value(ResticCaptureCommit {
|
||||
lease_id: lease.lease_id,
|
||||
snapshot_id,
|
||||
identity,
|
||||
sha256,
|
||||
})?;
|
||||
for _ in 0..3 {
|
||||
if hub.post(format!("capture/{}/restic", lease.job_id), body.clone(), None).await.is_ok() {
|
||||
if hub
|
||||
.post(
|
||||
format!("capture/{}/restic", lease.job_id),
|
||||
body.clone(),
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
anyhow::bail!("could not register the Restic snapshot")
|
||||
}).await;
|
||||
})
|
||||
.await;
|
||||
match result {
|
||||
Ok(Ok(())) => Ok(()),
|
||||
failure => {
|
||||
|
||||
@@ -211,15 +211,10 @@ async fn beam_restic(repository: &str, hub: &str, token: &str, orbit_id: uuid::U
|
||||
let registered = reply["snapshot_id"]
|
||||
.as_str()
|
||||
.context("hub did not register the Restic snapshot")?;
|
||||
info!(
|
||||
snapshot,
|
||||
registered,
|
||||
"committed Restic backup"
|
||||
);
|
||||
info!(snapshot, registered, "committed Restic backup");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn restic_command(repository: &str) -> Result<tokio::process::Command> {
|
||||
let authority = repository
|
||||
.strip_prefix("rest:https://")
|
||||
@@ -229,7 +224,8 @@ fn restic_command(repository: &str) -> Result<tokio::process::Command> {
|
||||
"TESSERA_RESTIC_REPOSITORY must be a rest:https:// URL without embedded credentials"
|
||||
);
|
||||
let mut command = tokio::process::Command::new("restic");
|
||||
command.env("RESTIC_REPOSITORY", repository)
|
||||
command
|
||||
.env("RESTIC_REPOSITORY", repository)
|
||||
.env_remove("RESTIC_REPOSITORY_FILE")
|
||||
.stdin(std::process::Stdio::null())
|
||||
.kill_on_drop(true);
|
||||
@@ -237,13 +233,23 @@ fn restic_command(repository: &str) -> Result<tokio::process::Command> {
|
||||
}
|
||||
|
||||
async fn restic_snapshot(mut command: tokio::process::Command) -> Result<String> {
|
||||
let output = command.output().await.context("starting restic (install restic on PATH)")?;
|
||||
anyhow::ensure!(output.status.success(), "restic backup failed ({})", output.status);
|
||||
let output = command
|
||||
.output()
|
||||
.await
|
||||
.context("starting restic (install restic on PATH)")?;
|
||||
anyhow::ensure!(
|
||||
output.status.success(),
|
||||
"restic backup failed ({})",
|
||||
output.status
|
||||
);
|
||||
let summary: serde_json::Value = serde_json::from_str(
|
||||
std::str::from_utf8(&output.stdout)?
|
||||
.lines()
|
||||
.last()
|
||||
.context("missing restic summary")?,
|
||||
)?;
|
||||
Ok(summary["snapshot_id"].as_str().context("missing restic snapshot ID")?.to_owned())
|
||||
Ok(summary["snapshot_id"]
|
||||
.as_str()
|
||||
.context("missing restic snapshot ID")?
|
||||
.to_owned())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user