Add remote support for backup one
This commit is contained in:
parent
40636a098a
commit
670339d2c9
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -1,5 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.3.8"
|
||||
@ -276,6 +278,7 @@ dependencies = [
|
||||
"clap",
|
||||
"env_logger",
|
||||
"glob",
|
||||
"hostname",
|
||||
"humansize",
|
||||
"indicatif",
|
||||
"itertools 0.10.1",
|
||||
@ -433,6 +436,17 @@ dependencies = [
|
||||
"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]]
|
||||
name = "humansize"
|
||||
version = "1.1.1"
|
||||
@ -545,6 +559,12 @@ dependencies = [
|
||||
"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]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
|
@ -28,5 +28,5 @@ glob = "0.3.0"
|
||||
humansize = "1.1.1"
|
||||
chrono = "0.4.19"
|
||||
itertools = "0.10.1"
|
||||
|
||||
hostname = "0.3.1"
|
||||
yama = { path = "../yama", version = "0.4.0" }
|
||||
|
@ -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::ilabel::interactive_labelling_session;
|
||||
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;
|
||||
|
||||
#[derive(Clap)]
|
||||
@ -54,6 +55,10 @@ pub enum DatmanCommand {
|
||||
|
||||
/// Name of the destination to back up to.
|
||||
destination_name: String,
|
||||
|
||||
/// Specify the remote user@host name.
|
||||
#[clap(short, long)]
|
||||
remote: Option<String>,
|
||||
},
|
||||
|
||||
BackupAll {
|
||||
@ -139,24 +144,55 @@ fn main() -> anyhow::Result<()> {
|
||||
DatmanCommand::BackupOne {
|
||||
source_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 source = &descriptor.source[&source_name];
|
||||
let destination = &descriptor.piles[&destination_name];
|
||||
backup_source_to_destination(
|
||||
source,
|
||||
destination,
|
||||
&descriptor,
|
||||
Path::new("."),
|
||||
&source_name,
|
||||
&destination_name,
|
||||
yama::utils::get_number_of_workers("YAMA_CHUNKERS"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
if let SourceDescriptor::DirectorySource { hostname, .. } = source {
|
||||
if hostname != &my_hostname && remote.is_none() {
|
||||
bail!(
|
||||
"Wrong hostname. Hostname should be {:?} but is {:?}",
|
||||
hostname,
|
||||
my_hostname
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
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 } => {
|
||||
let descriptor = load_descriptor(Path::new(".")).unwrap();
|
||||
let destination = &descriptor.piles[&destination_name];
|
||||
|
||||
backup_all_sources_to_destination(
|
||||
destination,
|
||||
&descriptor,
|
||||
|
Loading…
Reference in New Issue
Block a user