diff --git a/datman/src/bin/datman.rs b/datman/src/bin/datman.rs index 21461e6..c866d53 100644 --- a/datman/src/bin/datman.rs +++ b/datman/src/bin/datman.rs @@ -56,7 +56,7 @@ pub enum DatmanCommand { /// Name of the destination to back up to. destination_name: String, - /// Specify the remote user@host name. + /// Specify the remote name. #[clap(short, long)] remote: Option, }, @@ -164,7 +164,13 @@ fn main() -> anyhow::Result<()> { } } - if let Some(remote_user_at_host) = remote { + if let Some(remote_name) = remote { + let remote_host_descriptor = + if let Some(rhd) = descriptor.remote_hosts.get(&remote_name) { + rhd + } else { + bail!("No remote found by that name."); + }; backup_remote_source_to_destination( source, destination, @@ -172,7 +178,7 @@ fn main() -> anyhow::Result<()> { Path::new("."), &source_name, &destination_name, - &remote_user_at_host, + remote_host_descriptor, yama::utils::get_number_of_workers("YAMA_CHUNKERS"), ) .unwrap(); diff --git a/datman/src/commands.rs b/datman/src/commands.rs index 5597bb8..081f69b 100644 --- a/datman/src/commands.rs +++ b/datman/src/commands.rs @@ -48,6 +48,7 @@ pub fn init_descriptor(path: &Path) -> anyhow::Result<()> { ], source, piles: Default::default(), + remote_hosts: Default::default(), })?; datman_toml_file.write_all(&bytes)?; diff --git a/datman/src/descriptor.rs b/datman/src/descriptor.rs index f766273..9b930c5 100644 --- a/datman/src/descriptor.rs +++ b/datman/src/descriptor.rs @@ -36,6 +36,14 @@ pub struct Descriptor { /// Paths to destination Yama Piles. Remote Piles need a local virtual pile to specify the layers. pub piles: HashMap, + + pub remote_hosts: HashMap, +} + +#[derive(Clone, Serialize, Deserialize, Debug)] +pub struct RemoteHostDescriptor { + pub user_at_host: String, + pub path_to_datman: Option, } #[derive(Clone, Serialize, Deserialize, Debug)] diff --git a/datman/src/remote/backup_source_requester.rs b/datman/src/remote/backup_source_requester.rs index e93adc7..3f18520 100644 --- a/datman/src/remote/backup_source_requester.rs +++ b/datman/src/remote/backup_source_requester.rs @@ -1,5 +1,5 @@ use crate::commands::backup::{get_pointer_name_at, label_filter_and_convert}; -use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor}; +use crate::descriptor::{Descriptor, DestPileDescriptor, RemoteHostDescriptor, SourceDescriptor}; use crate::tree::FileTree; use anyhow::{anyhow, bail}; use chrono::Utc; @@ -80,7 +80,7 @@ pub fn backup_remote_source_to_destination( desc_path: &Path, source_name: &str, dest_name: &str, - user_at_host: &str, + remote_host_descriptor: &RemoteHostDescriptor, _num_workers: u8, ) -> anyhow::Result<()> { match source { @@ -90,11 +90,11 @@ pub fn backup_remote_source_to_destination( } => { info!( "Looking to backup {} (from {}) to {}", - source_name, user_at_host, dest_name + source_name, remote_host_descriptor.user_at_host, dest_name ); let connection = Command::new("ssh") - .arg(user_at_host) + .arg(&remote_host_descriptor.user_at_host) .arg("--") .arg("datman") .arg("_backup_source_responder")