aboutsummaryrefslogtreecommitdiff
path: root/hbak/src
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2024-02-14 18:35:05 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2024-02-14 18:35:05 +0100
commitbe3e8bc51930913732a5b9c7e514635eb2a75745 (patch)
tree67a5466415b0841e0e4fae8f8b3341c0f8a8ea9b /hbak/src
parent90ee9e99e0ea2caf8f016ad527c2abf51af10312 (diff)
hbak: restore subcommand: restore latest snapshot to subvolume (opt-out)
Diffstat (limited to 'hbak/src')
-rw-r--r--hbak/src/main.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/hbak/src/main.rs b/hbak/src/main.rs
index 4b8ab0f..7224ac5 100644
--- a/hbak/src/main.rs
+++ b/hbak/src/main.rs
@@ -122,6 +122,9 @@ enum Commands {
},
/// Restore the local node to the latest remote backup.
Restore {
+ /// Do not restore the latest snapshots to the subvolumes.
+ #[arg(short = 'r', long)]
+ no_restore: bool,
/// The device file the local btrfs file system is located at.
device: String,
/// The name this node was previously known under.
@@ -288,6 +291,7 @@ fn logic() -> Result<()> {
}
}
Commands::Restore {
+ no_restore,
device,
node_name,
address,
@@ -309,7 +313,7 @@ fn logic() -> Result<()> {
)?;
println!("Restoring from {}...", address);
- restore(&local_node, &address)?;
+ restore(&local_node, &address, no_restore)?;
}
}
@@ -427,7 +431,7 @@ fn sync(
Ok(())
}
-fn restore(local_node: &LocalNode, address: &str) -> Result<()> {
+fn restore(local_node: &LocalNode, address: &str, no_restore: bool) -> Result<()> {
let address = match address.parse() {
Ok(address) => address,
Err(_) => SocketAddr::new(address.parse()?, DEFAULT_PORT),
@@ -495,7 +499,7 @@ fn restore(local_node: &LocalNode, address: &str) -> Result<()> {
};
match stream_conn.data_sync(Vec::<(Empty, Snapshot)>::default(), rx_setup, rx_finish) {
- Ok(_) => Ok(()),
+ Ok(_) => {}
Err(e) => {
for (snapshot, child) in children.lock().unwrap().iter_mut() {
match child.kill() {
@@ -504,7 +508,16 @@ fn restore(local_node: &LocalNode, address: &str) -> Result<()> {
}
}
- Err(e.into())
+ return Err(e.into());
+ }
+ }
+
+ if !no_restore {
+ for subvol in &local_node.config().subvols {
+ println!("Restoring subvolume {}", subvol);
+ local_node.restore(subvol.clone())?;
}
}
+
+ Ok(())
}