From f1925b8f71cce80eed61c0fd7fdc2954d592e5d8 Mon Sep 17 00:00:00 2001 From: many Date: Thu, 15 Oct 2020 12:06:11 +0200 Subject: [PATCH] fix #1009 --- meilisearch-http/src/main.rs | 6 +++--- meilisearch-http/src/option.rs | 18 +++++++++++------- meilisearch-http/src/snapshot.rs | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/meilisearch-http/src/main.rs b/meilisearch-http/src/main.rs index a53094639..563f75d2f 100644 --- a/meilisearch-http/src/main.rs +++ b/meilisearch-http/src/main.rs @@ -52,7 +52,7 @@ async fn main() -> Result<(), MainError> { _ => unreachable!(), } - if let Some(path) = &opt.load_from_snapshot { + if let Some(path) = &opt.import_snapshot { snapshot::load_snapshot(&opt.db_path, path, opt.ignore_snapshot_if_db_exists, opt.ignore_missing_snapshot)?; } @@ -74,8 +74,8 @@ async fn main() -> Result<(), MainError> { dump::import_dump(&data, path, opt.dump_batch_size)?; } - if let Some(dir) = &opt.snapshot_dir { - snapshot::schedule_snapshot(data.clone(), &dir, opt.snapshot_interval_sec.unwrap_or(86400))?; + if opt.schedule_snapshot { + snapshot::schedule_snapshot(data.clone(), &opt.snapshot_dir, opt.snapshot_interval_sec.unwrap_or(86400))?; } print_launch_resume(&opt, &data); diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index 793cba17e..58e88633a 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -97,23 +97,27 @@ pub struct Opt { /// Defines the path of the snapshot file to import. /// This option will, by default, stop the process if a database already exist or if no snapshot exists at /// the given path. If this option is not specified no snapshot is imported. - #[structopt(long, env = "MEILI_LOAD_FROM_SNAPSHOT")] - pub load_from_snapshot: Option, + #[structopt(long, env = "MEILI_IMPORT_SNAPSHOT")] + pub import_snapshot: Option, /// The engine will ignore a missing snapshot and not return an error in such case. - #[structopt(long, requires = "load-from-snapshot", env = "MEILI_IGNORE_MISSING_SNAPSHOT")] + #[structopt(long, requires = "import-snapshot", env = "MEILI_IGNORE_MISSING_SNAPSHOT")] pub ignore_missing_snapshot: bool, /// The engine will skip snapshot importation and not return an error in such case. - #[structopt(long, requires = "load-from-snapshot", env = "MEILI_IGNORE_SNAPSHOT_IF_DB_EXISTS")] + #[structopt(long, requires = "import-snapshot", env = "MEILI_IGNORE_SNAPSHOT_IF_DB_EXISTS")] pub ignore_snapshot_if_db_exists: bool, /// Defines the directory path where meilisearch will create snapshot each snapshot_time_gap. - #[structopt(long, env = "MEILI_SNAPSHOT_DIR")] - pub snapshot_dir: Option, + #[structopt(long, env = "MEILI_SNAPSHOT_DIR", default_value = "snapshots/")] + pub snapshot_dir: PathBuf, + + /// Activate snapshot scheduling. + #[structopt(long, env = "MEILI_SCHEDULE_SNAPSHOT")] + pub schedule_snapshot: bool, /// Defines time interval, in seconds, between each snapshot creation. - #[structopt(long, requires = "snapshot-path", env = "MEILI_SNAPSHOT_INTERVAL_SEC")] + #[structopt(long, env = "MEILI_SNAPSHOT_INTERVAL_SEC")] pub snapshot_interval_sec: Option, /// Folder where dumps are created when the dump route is called. diff --git a/meilisearch-http/src/snapshot.rs b/meilisearch-http/src/snapshot.rs index 39a4555ae..c391dbdfa 100644 --- a/meilisearch-http/src/snapshot.rs +++ b/meilisearch-http/src/snapshot.rs @@ -20,7 +20,7 @@ pub fn load_snapshot( if !db_path.exists() && snapshot_path.exists() { compression::from_tar_gz(snapshot_path, db_path) } else if db_path.exists() && !ignore_snapshot_if_db_exists { - Err(Error::Internal(format!("database already exists at {:?}", db_path))) + Err(Error::Internal(format!("database already exists at {:?}, try to delete it or rename it", db_path))) } else if !snapshot_path.exists() && !ignore_missing_snapshot { Err(Error::Internal(format!("snapshot doesn't exist at {:?}", snapshot_path))) } else {