Add remote support for backup one

This commit is contained in:
Olivier 'reivilibre' 2021-07-04 20:50:10 +01:00
parent 40636a098a
commit 670339d2c9
3 changed files with 68 additions and 12 deletions

20
Cargo.lock generated
View File

@ -1,5 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.3.8" version = "0.3.8"
@ -276,6 +278,7 @@ dependencies = [
"clap", "clap",
"env_logger", "env_logger",
"glob", "glob",
"hostname",
"humansize", "humansize",
"indicatif", "indicatif",
"itertools 0.10.1", "itertools 0.10.1",
@ -433,6 +436,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "hostname"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c731c3e10504cc8ed35cfe2f1db4c9274c3d35fa486e3b31df46f068ef3e867"
dependencies = [
"libc",
"match_cfg",
"winapi",
]
[[package]] [[package]]
name = "humansize" name = "humansize"
version = "1.1.1" version = "1.1.1"
@ -545,6 +559,12 @@ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
] ]
[[package]]
name = "match_cfg"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4"
[[package]] [[package]]
name = "maybe-uninit" name = "maybe-uninit"
version = "2.0.0" version = "2.0.0"

View File

@ -28,5 +28,5 @@ glob = "0.3.0"
humansize = "1.1.1" humansize = "1.1.1"
chrono = "0.4.19" chrono = "0.4.19"
itertools = "0.10.1" itertools = "0.10.1"
hostname = "0.3.1"
yama = { path = "../yama", version = "0.4.0" } yama = { path = "../yama", version = "0.4.0" }

View File

@ -25,7 +25,8 @@ use chrono::{DateTime, Local, NaiveDate, NaiveDateTime, TimeZone, Utc};
use datman::commands::backup::{backup_all_sources_to_destination, backup_source_to_destination}; use datman::commands::backup::{backup_all_sources_to_destination, backup_source_to_destination};
use datman::commands::ilabel::interactive_labelling_session; use datman::commands::ilabel::interactive_labelling_session;
use datman::commands::init_descriptor; use datman::commands::init_descriptor;
use datman::descriptor::load_descriptor; use datman::descriptor::{load_descriptor, SourceDescriptor};
use datman::remote::backup_source_requester::backup_remote_source_to_destination;
use std::str::FromStr; use std::str::FromStr;
#[derive(Clap)] #[derive(Clap)]
@ -54,6 +55,10 @@ pub enum DatmanCommand {
/// Name of the destination to back up to. /// Name of the destination to back up to.
destination_name: String, destination_name: String,
/// Specify the remote user@host name.
#[clap(short, long)]
remote: Option<String>,
}, },
BackupAll { BackupAll {
@ -139,24 +144,55 @@ fn main() -> anyhow::Result<()> {
DatmanCommand::BackupOne { DatmanCommand::BackupOne {
source_name, source_name,
destination_name, destination_name,
remote,
} => { } => {
let my_hostname = hostname::get()
.expect("No hostname")
.into_string()
.expect("Hostname string must be sensible.");
let descriptor = load_descriptor(Path::new(".")).unwrap(); let descriptor = load_descriptor(Path::new(".")).unwrap();
let source = &descriptor.source[&source_name]; let source = &descriptor.source[&source_name];
let destination = &descriptor.piles[&destination_name]; let destination = &descriptor.piles[&destination_name];
backup_source_to_destination(
source, if let SourceDescriptor::DirectorySource { hostname, .. } = source {
destination, if hostname != &my_hostname && remote.is_none() {
&descriptor, bail!(
Path::new("."), "Wrong hostname. Hostname should be {:?} but is {:?}",
&source_name, hostname,
&destination_name, my_hostname
yama::utils::get_number_of_workers("YAMA_CHUNKERS"), );
) }
.unwrap(); }
if let Some(remote_user_at_host) = remote {
backup_remote_source_to_destination(
source,
destination,
&descriptor,
Path::new("."),
&source_name,
&destination_name,
&remote_user_at_host,
yama::utils::get_number_of_workers("YAMA_CHUNKERS"),
)
.unwrap();
} else {
backup_source_to_destination(
source,
destination,
&descriptor,
Path::new("."),
&source_name,
&destination_name,
yama::utils::get_number_of_workers("YAMA_CHUNKERS"),
)
.unwrap();
}
} }
DatmanCommand::BackupAll { destination_name } => { DatmanCommand::BackupAll { destination_name } => {
let descriptor = load_descriptor(Path::new(".")).unwrap(); let descriptor = load_descriptor(Path::new(".")).unwrap();
let destination = &descriptor.piles[&destination_name]; let destination = &descriptor.piles[&destination_name];
backup_all_sources_to_destination( backup_all_sources_to_destination(
destination, destination,
&descriptor, &descriptor,