Class BackupManager
Creates and manages schema backup files for MySQL tables and databases. Backups contain DDL (CREATE TABLE statements) and are stored as .sql files.
public sealed class BackupManager
- Inheritance
-
BackupManager
- Inherited Members
Constructors
BackupManager(ConnectionManager, string, ILogger?)
public BackupManager(ConnectionManager connectionManager, string dataDirectory, ILogger? logger = null)
Parameters
connectionManagerConnectionManagerdataDirectorystringloggerILogger
Methods
BackupDatabaseSchemaAsync(string, CancellationToken)
Backs up the DDL for all tables in the current database.
public Task<Result<bool>> BackupDatabaseSchemaAsync(string connectionId = "Default", CancellationToken ct = default)
Parameters
connectionIdstringThe connection ID to use.
ctCancellationTokenCancellation token.
Returns
BackupTableSchemaAsync(string, string, CancellationToken)
Backs up the CREATE TABLE DDL for the specified table to a timestamped .sql file.
public Task<Result<bool>> BackupTableSchemaAsync(string tableName, string connectionId = "Default", CancellationToken ct = default)
Parameters
tableNamestringThe table to back up.
connectionIdstringThe connection ID to use.
ctCancellationTokenCancellation token.
Returns
CleanupOldBackupsAsync(int)
Removes backup files older than the specified number of days.
public Task<Result<int>> CleanupOldBackupsAsync(int olderThanDays = 30)
Parameters
olderThanDaysintFiles older than this many days will be deleted.
Returns
GetLatestBackupFile(string)
Returns the most recent schema backup file for a table, or null if none exists. Backups are
named {table}_{yyyyMMdd_HHmmss}.sql in the backup directory.
public string? GetLatestBackupFile(string tableName)
Parameters
tableNamestring
Returns
RestoreTableSchemaAsync(string, string?, string, CancellationToken)
Restores a table's schema by replaying a backup .sql file: drops the table, then re-runs the
captured CREATE TABLE. Destructive and operator-driven — the table's data is lost (only the
DDL was ever backed up). When backupFile is null the latest backup is used.
public Task<Result<bool>> RestoreTableSchemaAsync(string tableName, string? backupFile = null, string connectionId = "Default", CancellationToken ct = default)
Parameters
tableNamestringThe table to restore.
backupFilestringPath to the backup file, or null to use the latest.
connectionIdstringThe connection ID to use.
ctCancellationTokenCancellation token.