Skip to content

Commit

Permalink
ol restore has --boundary-only or -b which will not attempt to restor…
Browse files Browse the repository at this point in the history
…e an advanced version. This is the safest restore option.
  • Loading branch information
0o-de-lally committed Jun 18, 2022
1 parent 6f31a60 commit 7f8fddc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
5 changes: 4 additions & 1 deletion ol/cli/src/commands/restore_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ pub struct RestoreCmd {
#[options(short="v", help = "specify a version or height if there is more than one per archive")]
version: Option<u64>,

#[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,
}

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),
};
Expand Down
47 changes: 26 additions & 21 deletions ol/cli/src/mgmt/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn fast_forward_db(
verbose: bool,
epoch: Option<u64>,
version_opt: Option<u64>,
boundary_only: bool,
) -> Result<(), Error> {
let mut backup = Backup::new(epoch);

Expand All @@ -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(())
Expand Down Expand Up @@ -178,18 +176,26 @@ impl Backup {
}

/// Restore Backups
pub fn restore_backup(&self, verbose: bool, version_opt: Option<u64>) -> Result<(), Error> {
pub fn restore_backup(
&self,
verbose: bool,
version_opt: Option<u64>,
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,
Expand All @@ -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(())
}
Expand Down Expand Up @@ -514,7 +519,7 @@ fn get_heighest_version(restore_path: PathBuf) -> anyhow::Result<u64> {
}

if highest > 0 {
return Ok(highest);
return Ok(highest);
}
bail!("No versioned manifest path found in: {:?}", restore_path);
}
Expand Down

0 comments on commit 7f8fddc

Please sign in to comment.