From 7f8fddc85c4f71ec1f4853e853db196039d61e40 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:50:27 -0400 Subject: [PATCH] ol restore has --boundary-only or -b which will not attempt to restore an advanced version. This is the safest restore option. --- ol/cli/src/commands/restore_cmd.rs | 5 +++- ol/cli/src/mgmt/restore.rs | 47 +++++++++++++++++------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/ol/cli/src/commands/restore_cmd.rs b/ol/cli/src/commands/restore_cmd.rs index 22e999b101..9423366361 100644 --- a/ol/cli/src/commands/restore_cmd.rs +++ b/ol/cli/src/commands/restore_cmd.rs @@ -21,6 +21,9 @@ pub struct RestoreCmd { #[options(short="v", help = "specify a version or height if there is more than one per archive")] version: Option, + #[options(short="b", help = "only restore the boundary, not an advanced version.")] + boundary_only: bool, + #[options(help = "get only the exact last block at the end of an epoch. Not extra blocks at the start of following epoch.")] exclude_buffer: bool, } @@ -28,7 +31,7 @@ pub struct RestoreCmd { impl Runnable for RestoreCmd { /// Start the application. fn run(&self) { - match mgmt::restore::fast_forward_db(self.verbose, self.epoch, self.version) { + match mgmt::restore::fast_forward_db(self.verbose, self.epoch, self.version, self.boundary_only) { Ok(_) => {}, Err(e) => println!("ERROR: could not complete db restore, message: {:?}", e), }; diff --git a/ol/cli/src/mgmt/restore.rs b/ol/cli/src/mgmt/restore.rs index 7ab3a448ab..0f4a3deaa9 100644 --- a/ol/cli/src/mgmt/restore.rs +++ b/ol/cli/src/mgmt/restore.rs @@ -53,6 +53,7 @@ pub fn fast_forward_db( verbose: bool, epoch: Option, version_opt: Option, + boundary_only: bool, ) -> Result<(), Error> { let mut backup = Backup::new(epoch); @@ -63,16 +64,13 @@ pub fn fast_forward_db( backup.set_waypoint()?; println!("\nRestoring db from archive to home path"); - backup.restore_backup(verbose, version_opt)?; + backup.restore_backup(verbose, version_opt, boundary_only)?; println!("\nCreating fullnode.node.yaml to home path"); backup.create_fullnode_yaml()?; println!("\nResetting Safety Data in key_store.json\n"); - diem_genesis_tool::key::reset_safety_data( - &backup.home_path, - &backup.node_namespace - ); + diem_genesis_tool::key::reset_safety_data(&backup.home_path, &backup.node_namespace); println!("SUCCESS"); Ok(()) @@ -178,18 +176,26 @@ impl Backup { } /// Restore Backups - pub fn restore_backup(&self, verbose: bool, version_opt: Option) -> Result<(), Error> { + pub fn restore_backup( + &self, + verbose: bool, + version_opt: Option, + boundary_only: bool, + ) -> Result<(), Error> { dbg!(&version_opt); let db_path = &self.home_path.join("db/"); let restore_path = self.restore_path.clone(); - // NOTE: First restore the Epoch before restoring a higher version in the epoch. restore_epoch(db_path, restore_path.to_str().unwrap(), verbose)?; - restore_transaction(db_path, self.restore_path.to_owned().to_str().unwrap(), verbose)?; + restore_transaction( + db_path, + self.restore_path.to_owned().to_str().unwrap(), + verbose, + )?; restore_snapshot( db_path, @@ -199,21 +205,20 @@ impl Backup { )?; // Restore an advanced version in the epoch - - let version = version_opt.unwrap_or(get_heighest_version(restore_path)?); - - let restore_path_for_version = self.restore_path.to_owned().join(version.to_string()); + if !boundary_only { + let version = version_opt.unwrap_or(get_heighest_version(restore_path)?); - dbg!(&restore_path_for_version); + let restore_path_for_version = self.restore_path.to_owned().join(version.to_string()); - restore_transaction(db_path, restore_path_for_version.to_str().unwrap(), verbose)?; + restore_transaction(db_path, restore_path_for_version.to_str().unwrap(), verbose)?; - restore_snapshot( - db_path, - restore_path_for_version.to_str().unwrap(), - &version, - verbose, - )?; + restore_snapshot( + db_path, + restore_path_for_version.to_str().unwrap(), + &version, + verbose, + )?; + } Ok(()) } @@ -514,7 +519,7 @@ fn get_heighest_version(restore_path: PathBuf) -> anyhow::Result { } if highest > 0 { - return Ok(highest); + return Ok(highest); } bail!("No versioned manifest path found in: {:?}", restore_path); }