diff --git a/datman/src/bin/datman.rs b/datman/src/bin/datman.rs
index 2b69457..30ea158 100644
--- a/datman/src/bin/datman.rs
+++ b/datman/src/bin/datman.rs
@@ -26,6 +26,7 @@ use datman::commands::backup::{backup_all_sources_to_destination, backup_source_
use datman::commands::ilabel::interactive_labelling_session;
use datman::commands::init_descriptor;
use datman::descriptor::{load_descriptor, SourceDescriptor};
+use datman::get_hostname;
use datman::remote::backup_source_requester::backup_remote_source_to_destination;
use datman::remote::backup_source_responder;
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
@@ -69,6 +70,11 @@ pub enum DatmanCommand {
},
BackupAll {
+ /// Name of the remote to back up.
+ /// Special value 'self' means 'this host only'.
+ /// Special value 'all' means 'all hosts'.
+ remote_name: String,
+
/// Name of the destination to back up to.
destination_name: String,
},
@@ -226,7 +232,10 @@ fn main() -> anyhow::Result<()> {
};
with_exitcode(with_obvious_successfail_message(result))
}
- DatmanCommand::BackupAll { destination_name } => {
+ DatmanCommand::BackupAll {
+ remote_name,
+ destination_name,
+ } => {
let descriptor = load_descriptor(Path::new(".")).unwrap();
let destination = &descriptor.piles[&destination_name];
@@ -245,6 +254,7 @@ fn main() -> anyhow::Result<()> {
&destination_name,
yama::utils::get_number_of_workers("YAMA_CHUNKERS"),
&mut pbar,
+ remote_name,
)
.unwrap();
}
diff --git a/datman/src/commands/backup.rs b/datman/src/commands/backup.rs
index 18b4f03..9a52682 100644
--- a/datman/src/commands/backup.rs
+++ b/datman/src/commands/backup.rs
@@ -16,6 +16,7 @@ along with Yama. If not, see .
*/
use crate::descriptor::{Descriptor, DestPileDescriptor, SourceDescriptor, VirtualSourceKind};
+use crate::get_hostname;
use crate::labelling::{label_node, load_labelling_rules, str_to_label, Label, State};
use crate::tree::{scan, FileTree, FileTree1};
use anyhow::{anyhow, bail};
@@ -331,8 +332,24 @@ pub fn backup_all_sources_to_destination(
dest_name: &str,
num_workers: u8,
progress_bar: &mut PT,
+ restricted_remote_name: String,
) -> anyhow::Result<()> {
+ let restricted_remote = match restricted_remote_name.as_str() {
+ "all" => None,
+ "self" | "this" | "here" => Some(get_hostname()),
+ other => Some(other.to_string()),
+ };
+
for (source_name, source_descriptor) in descriptor.source.iter() {
+ if let (Some(source_host), Some(restricted_host)) = (
+ source_descriptor.get_remote_hostname(),
+ restricted_remote.as_ref(),
+ ) {
+ if source_host != restricted_host {
+ // Skip this one, it wasn't requested right now.
+ continue;
+ }
+ }
backup_source_to_destination(
source_descriptor,
dest,
diff --git a/datman/src/descriptor.rs b/datman/src/descriptor.rs
index 9b930c5..13d9359 100644
--- a/datman/src/descriptor.rs
+++ b/datman/src/descriptor.rs
@@ -68,6 +68,16 @@ pub enum SourceDescriptor {
},
}
+impl SourceDescriptor {
+ /// Gets the hostname that this source descriptor is for, if possible.
+ pub fn get_remote_hostname(&self) -> Option<&str> {
+ match self {
+ SourceDescriptor::DirectorySource { hostname, .. } => Some(hostname.as_str()),
+ SourceDescriptor::VirtualSource { .. } => None,
+ }
+ }
+}
+
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(untagged)]
pub enum VirtualSourceKind {