Skip to content

Commit

Permalink
feat: allow MongoDB import from stdin (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
markrechler authored May 17, 2022
1 parent a4a907d commit c4b15d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion replibyte/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct RestoreLocalArgs {
/// all backup run commands
#[derive(Args, Debug)]
pub struct DumpCreateArgs {
#[clap(name = "source_type", short, long, value_name = "[postgresql | mysql]", possible_values = &["postgresql", "mysql"], requires = "input")]
#[clap(name = "source_type", short, long, value_name = "[postgresql | mysql | mongodb]", possible_values = &["postgresql", "mysql", "mongodb"], requires = "input")]
/// database source type to import
pub source_type: Option<String>,
/// import dump from stdin
Expand Down
13 changes: 13 additions & 0 deletions replibyte/src/commands/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::destination::postgres_docker::{
DEFAULT_POSTGRES_IMAGE_TAG, DEFAULT_POSTGRES_PASSWORD, DEFAULT_POSTGRES_USER,
};
use crate::source::mongodb::MongoDB;
use crate::source::mongodb_stdin::MongoDBStdin;
use crate::source::mysql::Mysql;
use crate::source::mysql_stdin::MysqlStdin;
use crate::source::postgres::Postgres;
Expand Down Expand Up @@ -182,6 +183,18 @@ where
let task = FullDumpTask::new(mysql, datastore, options);
task.run(progress_callback)?
}
Some(v) if v == "mongodb" => {
if args.file.is_some() {
let dump_file = File::open(args.file.as_ref().unwrap())?;
let mut stdin = stdin(); // FIXME
let reader = BufReader::new(dump_file);
let _ = stdin.read_to_end(&mut reader.buffer().to_vec())?;
}

let mongodb = MongoDBStdin::default();
let task = FullDumpTask::new(mongodb, datastore, options);
task.run(progress_callback)?
}
Some(v) => {
return Err(anyhow::Error::from(Error::new(
ErrorKind::Other,
Expand Down

0 comments on commit c4b15d0

Please sign in to comment.