2022-06-08 08:01:44 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2023-10-10 10:06:27 +00:00
|
|
|
use structopt::StructOpt;
|
2022-06-08 08:01:44 +00:00
|
|
|
|
2023-10-10 10:06:27 +00:00
|
|
|
use garage_db::*;
|
2022-06-08 08:01:44 +00:00
|
|
|
|
|
|
|
/// K2V command line interface
|
2023-10-10 10:06:27 +00:00
|
|
|
#[derive(StructOpt, Debug)]
|
|
|
|
pub struct ConvertDbOpt {
|
|
|
|
/// Input database path (not the same as metadata_dir, see
|
|
|
|
/// https://garagehq.deuxfleurs.fr/documentation/reference-manual/configuration/#db-engine-since-v0-8-0)
|
|
|
|
#[structopt(short = "i")]
|
2022-06-08 08:01:44 +00:00
|
|
|
input_path: PathBuf,
|
2023-10-10 10:06:27 +00:00
|
|
|
/// Input database engine (sled, lmdb or sqlite; limited by db engines
|
|
|
|
/// enabled in this build)
|
|
|
|
#[structopt(short = "a")]
|
2024-01-18 16:57:53 +00:00
|
|
|
input_engine: Engine,
|
2022-06-08 08:01:44 +00:00
|
|
|
|
2023-10-10 10:06:27 +00:00
|
|
|
/// Output database path
|
|
|
|
#[structopt(short = "o")]
|
2022-06-08 08:01:44 +00:00
|
|
|
output_path: PathBuf,
|
2023-10-10 10:06:27 +00:00
|
|
|
/// Output database engine
|
|
|
|
#[structopt(short = "b")]
|
2024-01-18 16:57:53 +00:00
|
|
|
output_engine: Engine,
|
2024-01-17 20:20:34 +00:00
|
|
|
|
|
|
|
#[structopt(flatten)]
|
2024-01-22 16:52:39 +00:00
|
|
|
db_open: OpenDbOpt,
|
2024-01-17 20:20:34 +00:00
|
|
|
}
|
|
|
|
|
2024-01-22 16:52:39 +00:00
|
|
|
/// Overrides for database open operation
|
2024-01-17 20:20:34 +00:00
|
|
|
#[derive(StructOpt, Debug, Default)]
|
|
|
|
pub struct OpenDbOpt {
|
|
|
|
#[cfg(feature = "lmdb")]
|
|
|
|
#[structopt(flatten)]
|
|
|
|
lmdb: OpenLmdbOpt,
|
|
|
|
}
|
|
|
|
|
2024-01-22 16:52:39 +00:00
|
|
|
/// Overrides for LMDB database open operation
|
2024-01-17 20:20:34 +00:00
|
|
|
#[cfg(feature = "lmdb")]
|
|
|
|
#[derive(StructOpt, Debug, Default)]
|
|
|
|
pub struct OpenLmdbOpt {
|
2024-01-22 16:52:39 +00:00
|
|
|
/// LMDB map size override
|
2024-01-17 20:20:34 +00:00
|
|
|
/// (supported suffixes: B, KiB, MiB, GiB, TiB, PiB)
|
|
|
|
#[cfg(feature = "lmdb")]
|
|
|
|
#[structopt(long = "lmdb-map-size", name = "bytes", display_order = 1_000)]
|
|
|
|
map_size: Option<bytesize::ByteSize>,
|
2022-06-08 08:01:44 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 10:06:27 +00:00
|
|
|
pub(crate) fn do_conversion(args: ConvertDbOpt) -> Result<()> {
|
2024-01-18 16:57:53 +00:00
|
|
|
if args.input_engine == args.output_engine {
|
|
|
|
return Err(Error("input and output database engine must differ".into()));
|
|
|
|
}
|
|
|
|
|
2024-03-08 11:47:05 +00:00
|
|
|
let opt = OpenOpt {
|
|
|
|
lmdb_map_size: args.db_open.lmdb.map_size.map(|x| x.as_u64() as usize),
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
|
|
|
let input = open_db(&args.input_path, args.input_engine, &opt)?;
|
|
|
|
let output = open_db(&args.output_path, args.output_engine, &opt)?;
|
2022-06-08 08:01:44 +00:00
|
|
|
output.import(&input)?;
|
|
|
|
Ok(())
|
|
|
|
}
|