Table of Contents

Class BackupManager

Namespace
CL.MySQL2.Services
Assembly
CL.MySQL2.dll

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

connectionManager ConnectionManager
dataDirectory string
logger ILogger

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

connectionId string

The connection ID to use.

ct CancellationToken

Cancellation token.

Returns

Task<Result<bool>>

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

tableName string

The table to back up.

connectionId string

The connection ID to use.

ct CancellationToken

Cancellation token.

Returns

Task<Result<bool>>

CleanupOldBackupsAsync(int)

Removes backup files older than the specified number of days.

public Task<Result<int>> CleanupOldBackupsAsync(int olderThanDays = 30)

Parameters

olderThanDays int

Files older than this many days will be deleted.

Returns

Task<Result<int>>

The number of files deleted.

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

tableName string

Returns

string

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

tableName string

The table to restore.

backupFile string

Path to the backup file, or null to use the latest.

connectionId string

The connection ID to use.

ct CancellationToken

Cancellation token.

Returns

Task<Result<bool>>