Configure remote hosts in the TOML file now

This commit is contained in:
Olivier 'reivilibre' 2021-07-07 23:13:04 +01:00
parent 670339d2c9
commit ec278f954f
4 changed files with 22 additions and 7 deletions

View File

@ -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<String>,
},
@ -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();

View File

@ -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)?;

View File

@ -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<String, DestPileDescriptor>,
pub remote_hosts: HashMap<String, RemoteHostDescriptor>,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct RemoteHostDescriptor {
pub user_at_host: String,
pub path_to_datman: Option<String>,
}
#[derive(Clone, Serialize, Deserialize, Debug)]

View File

@ -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")