Create backups for tables that will be modified by a write operation
(&self, table_name: &str)
| 72 | |
| 73 | /// Create backups for tables that will be modified by a write operation |
| 74 | pub fn backup_table(&self, table_name: &str) -> Result<Option<PathBuf>> { |
| 75 | if !self.backup_enabled { |
| 76 | return Ok(None); |
| 77 | } |
| 78 | |
| 79 | let source_path = self.get_table_path(table_name)?; |
| 80 | |
| 81 | if !source_path.exists() { |
| 82 | return Ok(None); |
| 83 | } |
| 84 | |
| 85 | let backup_path = create_backup_path(&source_path); |
| 86 | |
| 87 | fs::copy(&source_path, &backup_path).map_err(|e| { |
| 88 | Error::BackupFailed(format!( |
| 89 | "Failed to backup {} to {}: {}", |
| 90 | source_path.display(), |
| 91 | backup_path.display(), |
| 92 | e |
| 93 | )) |
| 94 | })?; |
| 95 | |
| 96 | Ok(Some(backup_path)) |
| 97 | } |
| 98 | |
| 99 | /// Restore a table from its backup |
| 100 | #[allow(dead_code)] |
no test coverage detected