Adding option for snapshot file in replay
Summary:
Adding a new option in `below replay` to be able to accept the compressed file from the `snapshot` and run replay using the files.
**Usage**
```
below replay -- --snapshot <snapshot_file> --time <timestamp>
```
@@ -37,7 +37,7 @@ use structopt::{
clap::{AppSettings, Shell},
StructOpt,
};
-use tar::Builder as TarBuilder;
+use tar::{Archive, Builder as TarBuilder};
use tempdir::TempDir;
use users::{get_current_uid, get_user_by_uid};
@@ -209,6 +209,10 @@ enum Command {
/// * 09/01/2020 17:00: below replay -r yy -t "09/03/2020 17:00"
#[structopt(short = "r", verbatim_doc_comment)]
yesterdays: Option<String>,
+ /// Replay from a snapshot file generated by the snapshot
+ /// command instead of from the store directory.
+ #[structopt(long)]
+ snapshot: Option<String>,
},
/// Debugging facilities (for development use)
Debug {
@@ -620,11 +624,13 @@ fn real_main(init: init::InitToken) {
ref host,
ref port,
ref yesterdays,
+ ref snapshot,
} => {
let time = time.clone();
let host = host.clone();
let port = port.clone();
let days_adjuster = yesterdays.clone();
+ let snapshot = snapshot.clone();
run(
init,
debug,
@@ -632,7 +638,16 @@ fn real_main(init: init::InitToken) {
Service::Off,
RedirectLogOnFail::Off,
|_, below_config, logger, errs| {
- replay(logger, errs, time, below_config, host, port, days_adjuster)
+ replay(
+ logger,
+ errs,
+ time,
+ below_config,
+ host,
+ port,
+ days_adjuster,
+ snapshot,
+ )
},
)
}
@@ -747,14 +762,27 @@ fn replay(
host: Option<String>,
port: Option<u16>,
days_adjuster: Option<String>,
+ snapshot: Option<String>,
) -> Result<()> {
let timestamp =
cliutil::system_time_from_date_and_adjuster(time.as_str(), days_adjuster.as_deref())?;
- let mut advance = if let Some(host) = host {
- new_advance_remote(logger.clone(), host, port, timestamp)?
- } else {
+ let mut advance = match (host, snapshot) {
+ (None, None) => {
new_advance_local(logger.clone(), below_config.store_dir.clone(), timestamp)
+ }
+ (Some(host), None) => new_advance_remote(logger.clone(), host, port, timestamp)?,
+ (None, Some(snapshot)) => {
+ let mut tarball =
+ Archive::new(fs::File::open(&snapshot).context("Failed to open snapshot file")?);
+ let mut snapshot_dir = TempDir::new("snapshot_replay")?.into_path();
+ tarball.unpack(&snapshot_dir)?;
+ snapshot_dir.push(snapshot);
+ new_advance_local(logger.clone(), snapshot_dir, timestamp)
+ }
+ (Some(_), Some(_)) => {
+ bail!("--host and --snapshot are incompatible options")
+ }
};
// Fill the last_sample for forward iteration. If no previous sample exists,
