add option to backup a single device

This commit is contained in:
Robin Appelman 2024-06-25 21:14:24 +02:00
commit 0e7839f2b9

View file

@ -16,6 +16,7 @@ mod config;
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Args { struct Args {
config: PathBuf, config: PathBuf,
device: Option<String>,
} }
#[tokio::main] #[tokio::main]
@ -35,16 +36,18 @@ async fn main() -> Result<()> {
let devices = client.current_devices(); let devices = client.current_devices();
info!("found {} devices", devices.len()); info!("found {} devices", devices.len());
for device in devices { for device in devices {
let result = timeout( if args.device.is_none() || args.device.as_deref() == Some(device.as_str()) {
Duration::from_secs(120), let result = timeout(
download(&client, &device, &config.output.target, &device_password), Duration::from_secs(120),
) download(&client, &device, &config.output.target, &device_password),
.await; )
let result = result .await;
.with_context(|| format!("Timeout while downloading config for {device}")) let result = result
.and_then(|res| res); .with_context(|| format!("Timeout while downloading config for {device}"))
if let Err(e) = result { .and_then(|res| res);
error!(device = device, error = %e, "Failed to download config for {device}"); if let Err(e) = result {
error!(device = device, error = %e, "Failed to download config for {device}");
}
} }
} }