25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(backup): recreate the per-run directory dbx itself removed (#13722)
dienaso7821294ad164
diff --git a/crates/dbx-core/src/data/database_export.rs b/crates/dbx-core/src/data/database_export.rsindex a043d12ab6..d635220cfb 100644--- a/crates/dbx-core/src/data/database_export.rs+++ b/crates/dbx-core/src/data/database_export.rs@@ -3516,13 +3516,32 @@ async fn ensure_export_destination_dir(save_export_destination_identity(state, dir, current_identity.as_ref()).await?;return Ok(current_identity);} else {+ // The recorded state is `Option<Option<_>>`: an outer `Some` means the+ // directory was previously used by dbx (or recorded when the schedule+ // was configured); the inner value carries its filesystem identity.if recorded_identity.is_some() {- return Err(format!(- "Backup directory {} is missing. It was configured or previously used for exports to \- this location, so dbx will not recreate it automatically -- if this is on a removable \- or network drive, reconnect it and try again.",- dir.display()- ));+ // Recreating the directory is only safe when it would land on the+ // same filesystem it was recorded on, so compare the recorded+ // identity against the destination's parent. A missing or+ // differently-resolving parent keeps the fail-closed behavior for+ // vanished removable/network mounts (#6327). A matching parent+ // means dbx removed the empty leaf itself -- backup deletion+ // cleans up the per-run directory once its files are gone -- and+ // the next run must be able to recreate it (#13610). A record+ // without a usable identity cannot prove the filesystem and also+ // keeps failing closed.+ let parent_identity = dir.parent().and_then(export_destination_identity_for_path);+ let same_filesystem = recorded_identity.flatten().is_some_and(|recorded| {+ !recorded_export_destination_identity_mismatch(&recorded, parent_identity.as_ref())+ });+ if !same_filesystem {+ return Err(format!(+ "Backup directory {} is missing. It was configured or previously used for exports to \+ this location, so dbx will not recreate it automatically -- if this is on a removable \+ or network drive, reconnect it and try again.",+ dir.display()+ ));+ }}// A run-specific child directory is intentionally new on every// scheduled backup. Before creating it, still honor a recorded parent@@ -9288,6 +9307,37 @@ mod tests {let _ = std::fs::remove_dir_all(&scratch);}+ // Regression test for #13610: deleting the last backup of a run removes the+ // emptied per-run directory (`remove_empty_directories`), while its recorded+ // destination identity survives in state. The next run into the same dated+ // directory refused to recreate it even though dbx itself had removed the+ // directory and the parent still resolved to the same filesystem. The+ // vanished-mount refusals above stay intact: there the parent is missing,+ // so the identity comparison fails closed.+ #[tokio::test]+ async fn ensure_export_destination_dir_recreates_a_recorded_destination_whose_parent_kept_the_same_filesystem() {+ let scratch = std::env::temp_dir().join(format!("dbx-export-dest-cleaned-{}", uuid::Uuid::new_v4()));+ std::fs::create_dir_all(&scratch).unwrap();+ let state = test_app_state(&scratch).await;++ let destination = scratch.join("backups").join("mydb");+ ensure_export_destination_dir(&state, &destination).await.expect("initial export should create the directory");+ assert!(destination.is_dir());++ // Simulates dbx's own cleanup after the last backup file in the+ // directory is deleted: the empty run directory is removed, its parent+ // stays.+ std::fs::remove_dir(&destination).unwrap();+ assert!(!destination.exists());++ ensure_export_destination_dir(&state, &destination)+ .await+ .expect("a leaf directory dbx itself removed must be recreated when the parent still matches");+ assert!(destination.is_dir());++ let _ = std::fs::remove_dir_all(&scratch);+ }+// Regression test for review feedback on #6327: `ensure_export_destination_dir`// only remembered a destination *after* a successful export, so a mount// that was present when a schedule was configured but vanished before its