Report import/export status
This commit is contained in:
@@ -1089,6 +1089,8 @@ fn spawn_writer(path: PathBuf) -> (std::thread::JoinHandle<()>, SyncSender<Op>)
|
||||
let (tx, rx) = mpsc::sync_channel(10);
|
||||
|
||||
let handle = std::thread::spawn(move || {
|
||||
println!("Exporting database to {}.", path.to_str().unwrap());
|
||||
|
||||
let mut file =
|
||||
BufWriter::new(std::fs::File::create(path).failed("Failed to create backup file"));
|
||||
file.write_all(&[MAGIC_MARKER, FILE_VERSION])
|
||||
|
||||
@@ -65,6 +65,7 @@ Options:
|
||||
-V, --version Print version
|
||||
"#;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
enum ImportExport {
|
||||
Export(PathBuf),
|
||||
Import(PathBuf),
|
||||
@@ -74,7 +75,7 @@ enum ImportExport {
|
||||
impl BootManager {
|
||||
pub async fn init() -> Self {
|
||||
let mut config_path = std::env::var("CONFIG_PATH").ok();
|
||||
let mut art_vandelay = ImportExport::None;
|
||||
let mut import_export = ImportExport::None;
|
||||
|
||||
if config_path.is_none() {
|
||||
let mut args = std::env::args().skip(1);
|
||||
@@ -91,7 +92,7 @@ impl BootManager {
|
||||
|
||||
match (key.as_str(), value) {
|
||||
("help" | "h", _) => {
|
||||
println!("{HELP}");
|
||||
eprintln!("{HELP}");
|
||||
std::process::exit(0);
|
||||
}
|
||||
("version" | "V", _) => {
|
||||
@@ -106,10 +107,10 @@ impl BootManager {
|
||||
std::process::exit(0);
|
||||
}
|
||||
("export" | "e", Some(value)) => {
|
||||
art_vandelay = ImportExport::Export(value.into());
|
||||
import_export = ImportExport::Export(value.into());
|
||||
}
|
||||
("import" | "i", Some(value)) => {
|
||||
art_vandelay = ImportExport::Import(value.into());
|
||||
import_export = ImportExport::Import(value.into());
|
||||
}
|
||||
(_, None) => {
|
||||
failed(&format!("Unrecognized command '{key}', try '--help'."));
|
||||
@@ -121,7 +122,11 @@ impl BootManager {
|
||||
}
|
||||
|
||||
if config_path.is_none() {
|
||||
println!("{HELP}");
|
||||
if import_export == ImportExport::None {
|
||||
eprintln!("{HELP}");
|
||||
} else {
|
||||
eprintln!("Missing '--config' argument for import/export.")
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
@@ -173,6 +178,9 @@ impl BootManager {
|
||||
|
||||
// Enable tracing
|
||||
let guards = Tracers::parse(&mut config).enable(&mut config);
|
||||
|
||||
match import_export {
|
||||
ImportExport::None => {
|
||||
tracing::info!(
|
||||
"Starting Stalwart Mail Server v{}...",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
@@ -226,7 +234,10 @@ impl BootManager {
|
||||
insert_keys.extend(external_config.keys);
|
||||
}
|
||||
Err(err) => {
|
||||
config.new_build_error("*", format!("Failed to fetch spam filter: {err}"));
|
||||
config.new_build_error(
|
||||
"*",
|
||||
format!("Failed to fetch spam filter: {err}"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,12 +286,14 @@ impl BootManager {
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
config.new_build_error("*", format!("Failed to download webadmin: {err}"));
|
||||
config.new_build_error(
|
||||
"*",
|
||||
format!("Failed to download webadmin: {err}"),
|
||||
);
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
config.new_build_error("*", format!("Failed to access webadmin blob: {err}"))
|
||||
}
|
||||
Err(err) => config
|
||||
.new_build_error("*", format!("Failed to access webadmin blob: {err}")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,7 +304,8 @@ impl BootManager {
|
||||
}
|
||||
|
||||
if let Err(err) = manager.set(insert_keys).await {
|
||||
config.new_build_error("*", format!("Failed to update configuration: {err}"));
|
||||
config
|
||||
.new_build_error("*", format!("Failed to update configuration: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,11 +313,9 @@ impl BootManager {
|
||||
stores.parse_lookups(&mut config).await;
|
||||
|
||||
// Parse settings and build shared core
|
||||
let core = Core::parse(&mut config, stores, manager).await;
|
||||
|
||||
match art_vandelay {
|
||||
ImportExport::None => {
|
||||
let core = core.into_shared();
|
||||
let core = Core::parse(&mut config, stores, manager)
|
||||
.await
|
||||
.into_shared();
|
||||
|
||||
// Parse TCP acceptors
|
||||
servers.parse_tcp_acceptors(&mut config, core.clone());
|
||||
@@ -316,11 +328,17 @@ impl BootManager {
|
||||
}
|
||||
}
|
||||
ImportExport::Export(path) => {
|
||||
core.backup(path).await;
|
||||
Core::parse(&mut config, stores, manager)
|
||||
.await
|
||||
.backup(path)
|
||||
.await;
|
||||
std::process::exit(0);
|
||||
}
|
||||
ImportExport::Import(path) => {
|
||||
core.restore(path).await;
|
||||
Core::parse(&mut config, stores, manager)
|
||||
.await
|
||||
.restore(path)
|
||||
.await;
|
||||
std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,8 @@ impl Core {
|
||||
}
|
||||
|
||||
async fn restore_file(store: Store, blob_store: BlobStore, path: &Path) {
|
||||
println!("Importing database dump from {}.", path.to_str().unwrap());
|
||||
|
||||
let mut reader = OpReader::new(path).await;
|
||||
let mut account_id = u32::MAX;
|
||||
let mut document_id = u32::MAX;
|
||||
|
||||
Reference in New Issue
Block a user