pub struct BackupManager { /* private fields */ }Expand description
Manages creation, listing, rotation, and restoration of database backups.
Implementations§
Source§impl BackupManager
impl BackupManager
Sourcepub fn new(db_path: PathBuf, backup_dir: PathBuf) -> Self
pub fn new(db_path: PathBuf, backup_dir: PathBuf) -> Self
Create a new backup manager.
db_path is the live SQLite database. backup_dir is the directory
where backups will be written. The directory will be created if it does
not exist.
Sourcepub fn with_max_backups(self, max: usize) -> Self
pub fn with_max_backups(self, max: usize) -> Self
Set the maximum number of backups to retain.
Sourcepub fn with_compression(self, compress: bool) -> Self
pub fn with_compression(self, compress: bool) -> Self
Enable or disable gzip compression for backups.
Sourcepub async fn create_backup(&self) -> PunchResult<BackupInfo>
pub async fn create_backup(&self) -> PunchResult<BackupInfo>
Create a new backup of the live database.
Uses SQLite’s VACUUM INTO to produce a consistent snapshot without
interrupting readers/writers on the live database.
Sourcepub async fn list_backups(&self) -> PunchResult<Vec<BackupInfo>>
pub async fn list_backups(&self) -> PunchResult<Vec<BackupInfo>>
List all existing backups, newest first.
Sourcepub async fn restore_backup(&self, backup_id: &str) -> PunchResult<()>
pub async fn restore_backup(&self, backup_id: &str) -> PunchResult<()>
Restore the live database from a backup identified by backup_id.
The backup_id is the file stem (e.g. punch_backup_20260101_120000).
If the backup is gzip-compressed it will be decompressed first.
Sourcepub async fn cleanup_old_backups(&self) -> PunchResult<usize>
pub async fn cleanup_old_backups(&self) -> PunchResult<usize>
Remove old backups, keeping only the most recent max_backups.
Returns the number of backups removed.