diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-02-12 15:35:11 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2024-02-12 15:35:11 +0100 |
commit | de412840629ec600b28b2e58b7d9b988cf801dd5 (patch) | |
tree | 416e8c211cf935d203d40c2f3f7e094508603ee2 /hbak/src | |
parent | 3f0c79ab0ca444e7b9343cf30fc3e4c542a82d96 (diff) |
hbak: add basic restore subcommand prerequisites
Diffstat (limited to 'hbak/src')
-rw-r--r-- | hbak/src/main.rs | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/hbak/src/main.rs b/hbak/src/main.rs index 607704a..f097ef9 100644 --- a/hbak/src/main.rs +++ b/hbak/src/main.rs @@ -53,7 +53,7 @@ enum Commands { }, /// Add or modify a remote to push to or pull from. AddRemote { - /// The network address and port of the remote node. + /// The network address and optional port of the remote node. address: String, /// The volumes to push to the remote node. push: Vec<String>, @@ -63,7 +63,7 @@ enum Commands { }, /// Remove a remote without deleting anything. RmRemote { - /// The network address and port of the node to forget. + /// The network address and optional port of the node to forget. address: String, }, /// Add or modify authentication and authorization information for a remote client. @@ -113,8 +113,15 @@ enum Commands { /// The volumes to limit pulling to. #[arg(long = "pull")] pull: Vec<String>, - /// The nodes to limit synchronization to. - nodes: Vec<String>, + /// The network addresses and optional ports of the nodes to limit synchronization to. + remote_nodes: Vec<String>, + }, + /// Restore the local node to the latest remote backup. + Restore { + /// The network address and optional port of the node to restore from. + address: String, + /// The subvolumes to limit recovery to. + subvols: Vec<String>, }, } @@ -255,19 +262,35 @@ fn logic() -> Result<()> { local_node.snapshot_now(subvol.clone(), incremental)?; } } - Commands::Synchronize { push, pull, nodes } => { + Commands::Synchronize { + push, + pull, + remote_nodes, + } => { let local_node = LocalNode::new()?; - for node in local_node + for remote_node in local_node .config() .remotes .iter() - .filter(|item| nodes.is_empty() || nodes.contains(&item.address)) + .filter(|item| remote_nodes.is_empty() || remote_nodes.contains(&item.address)) { - println!("Synchronizing with {}...", node.address); - sync(&local_node, node, &push, &pull)?; + println!("Synchronizing with {}...", remote_node.address); + sync(&local_node, remote_node, &push, &pull)?; } } + Commands::Restore { address, subvols } => { + let local_node = LocalNode::new()?; + + let subvols = if !subvols.is_empty() { + &subvols + } else { + &local_node.config().subvols + }; + + println!("Restoring from {}...", address); + restore(&local_node, &address, subvols)?; + } } Ok(()) @@ -379,3 +402,7 @@ fn sync( Ok(()) } + +fn restore(local_node: &LocalNode, address: &str, subvols: &[String]) -> Result<()> { + todo!() +} |