diff --git a/pageserver/src/bin/import.rs b/pageserver/src/bin/import.rs index e710cd09d5..a4d96bcc9c 100644 --- a/pageserver/src/bin/import.rs +++ b/pageserver/src/bin/import.rs @@ -1,10 +1,26 @@ use anyhow; +use camino::Utf8PathBuf; +use clap::Parser; use pageserver::{pg_import, virtual_file::{self, api::IoEngineKind}}; use utils::logging::{self, LogFormat, TracingErrorLayerEnablement}; -fn main() -> anyhow::Result<()> { - println!("Hey!"); +//project_git_version!(GIT_VERSION); +#[derive(Parser)] +#[command( + //version = GIT_VERSION, + about = "Utility to import a Postgres data directory directly into image layers", + //long_about = "..." +)] +struct CliOpts { + /// Input Postgres data directory + pgdata: Utf8PathBuf, + + /// Path to local dir where the layer files will be stored + dest_path: Utf8PathBuf, +} + +fn main() -> anyhow::Result<()> { logging::init( LogFormat::Plain, TracingErrorLayerEnablement::EnableWithRustLogFilter, @@ -21,7 +37,15 @@ fn main() -> anyhow::Result<()> { .enable_all() .build()?; - rt.block_on(pg_import::do_import())?; - + let cli = CliOpts::parse(); + + rt.block_on(async_main(cli))?; + + Ok(()) +} + +async fn async_main(cli: CliOpts) -> anyhow::Result<()> { + let mut import = pg_import::PgImportEnv::init().await?; + import.import_datadir(&cli.pgdata, &cli.dest_path).await?; Ok(()) } diff --git a/pageserver/src/pg_import.rs b/pageserver/src/pg_import.rs index 643bb9978e..6ef6b54342 100644 --- a/pageserver/src/pg_import.rs +++ b/pageserver/src/pg_import.rs @@ -18,16 +18,6 @@ use tokio::io::AsyncReadExt; use pageserver_api::key::Key; - -pub async fn do_import() -> anyhow::Result<()> { - - let mut import = PgImportEnv::init().await?; - - import.import_datadir(&Utf8PathBuf::from("pg_in"), &Utf8PathBuf::from("pg_out")).await?; - - Ok(()) -} - pub struct PgImportEnv { ctx: RequestContext, conf: &'static PageServerConf, @@ -37,7 +27,7 @@ pub struct PgImportEnv { impl PgImportEnv { - async fn init() -> anyhow::Result { + pub async fn init() -> anyhow::Result { let ctx: RequestContext = RequestContext::new(TaskKind::DebugTool, DownloadBehavior::Error); let config = toml_edit::Document::new(); let conf = PageServerConf::parse_and_validate( @@ -63,7 +53,7 @@ impl PgImportEnv { }) } - async fn import_datadir(&mut self, pgdata_path: &Utf8Path, _tenant_path: &Utf8Path) -> anyhow::Result<()> { + pub async fn import_datadir(&mut self, pgdata_path: &Utf8Path, _tenant_path: &Utf8Path) -> anyhow::Result<()> { let pgdata_lsn = import_datadir::get_lsn_from_controlfile(&pgdata_path)?.align();