Skip to content

Commit

Permalink
fix: restore local -o command
Browse files Browse the repository at this point in the history
  • Loading branch information
evoxmusic committed May 8, 2022
1 parent c58568b commit a1f6f06
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
6 changes: 3 additions & 3 deletions replibyte/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use clap::{Args, Parser, Subcommand};

/// RepliByte is a tool to synchronize cloud databases and fake sensitive data, just pass `-h`
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
#[clap(author, about, long_about = None)]
#[clap(propagate_version = true)]
pub struct CLI {
/// replibyte configuration file
/// Replibyte configuration file
#[clap(short, long, parse(from_os_str), value_name = "configuration file")]
pub config: PathBuf,
#[clap(subcommand)]
Expand Down Expand Up @@ -89,7 +89,7 @@ pub struct RestoreLocalArgs {
pub remove: bool,
/// Docker image type
#[clap(short, long, value_name = "[postgresql | mysql | mongodb]")]
pub image: String,
pub image: Option<String>,
}

/// all backup run commands
Expand Down
49 changes: 31 additions & 18 deletions replibyte/src/commands/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::cli::{RestoreArgs, RestoreLocalArgs};
use crate::config::{Config, ConnectionUri};
use crate::datastore::Datastore;
use crate::datastore::ReadOptions;
use crate::destination;
use crate::destination::generic_stdout::GenericStdout;
use crate::destination::mongodb_docker::{MongoDBDocker, DEFAULT_MONGO_CONTAINER_PORT};
use crate::destination::mysql_docker::{
Expand All @@ -30,6 +29,8 @@ use crate::tasks::full_dump::FullDumpTask;
use crate::tasks::full_restore::FullRestoreTask;
use crate::tasks::Task;
use crate::utils::{epoch_millis, table, to_human_readable_unit};
use crate::{destination, CLI};
use clap::CommandFactory;

/// List all dumps
pub fn list(datastore: &mut Box<dyn Datastore>) -> Result<(), Error> {
Expand Down Expand Up @@ -235,7 +236,19 @@ where
return Ok(());
}

if args.image == "postgres".to_string() || args.image == "postgresql".to_string() {
let image = match &args.image {
Some(image) => image,
None => {
let mut cmd = CLI::command();
cmd.error(
clap::ErrorKind::MissingRequiredArgument,
"you must use --output or --image [database_type] option",
)
.exit();
}
};

if image.as_str() == "postgres" || image.as_str() == "postgresql" {
let port = args.port.unwrap_or(DEFAULT_POSTGRES_CONTAINER_PORT);
let tag = match &args.tag {
Some(tag) => tag,
Expand Down Expand Up @@ -283,7 +296,7 @@ where
}
}

if args.image == "mongodb".to_string() {
if image.as_str() == "mongodb" {
let port = args.port.unwrap_or(DEFAULT_MONGO_CONTAINER_PORT);
let tag = match &args.tag {
Some(tag) => tag,
Expand Down Expand Up @@ -328,7 +341,7 @@ where
}
}

if args.image == "mysql".to_string() {
if image.as_str() == "mysql" {
let port = args.port.unwrap_or(DEFAULT_MYSQL_CONTAINER_PORT);
let tag = match &args.tag {
Some(tag) => tag,
Expand Down Expand Up @@ -390,22 +403,22 @@ where
datastore.set_encryption_key(encryption_key);
}

match config.destination {
Some(destination) => {
let options = match args.value.as_str() {
"latest" => ReadOptions::Latest,
v => ReadOptions::Dump {
name: v.to_string(),
},
};
let options = match args.value.as_str() {
"latest" => ReadOptions::Latest,
v => ReadOptions::Dump {
name: v.to_string(),
},
};

if args.output {
let mut generic_stdout = GenericStdout::new();
let task = FullRestoreTask::new(&mut generic_stdout, datastore, options);
let _ = task.run(|_, _| {})?; // do not display the progress bar
return Ok(());
}
if args.output {
let mut generic_stdout = GenericStdout::new();
let task = FullRestoreTask::new(&mut generic_stdout, datastore, options);
let _ = task.run(|_, _| {})?; // do not display the progress bar
return Ok(());
}

match config.destination {
Some(destination) => {
match destination.connection_uri()? {
ConnectionUri::Postgres(host, port, username, password, database) => {
let mut postgres = destination::postgres::Postgres::new(
Expand Down
1 change: 0 additions & 1 deletion replibyte/src/datastore/s3.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::io::SeekFrom::End;
use std::io::{Error, ErrorKind};
use std::str::FromStr;

Expand Down

0 comments on commit a1f6f06

Please sign in to comment.