5#include "../SqlConnectInfo.hpp"
6#include "../SqlQuery/MigrationPlan.hpp"
7#include "../SqlSchema.hpp"
17namespace Lightweight::SqlBackup
26enum class CompressionMethod : std::int32_t
40 CompressionMethod
method = CompressionMethod::Deflate;
99LIGHTWEIGHT_API std::size_t GetAvailableSystemMemory() noexcept;
106LIGHTWEIGHT_API
RestoreSettings CalculateRestoreSettings(std::
size_t availableMemory,
unsigned concurrency);
112LIGHTWEIGHT_API
bool IsCompressionMethodSupported(CompressionMethod method) noexcept;
115LIGHTWEIGHT_API std::vector<CompressionMethod> GetSupportedCompressionMethods() noexcept;
118LIGHTWEIGHT_API std::string_view CompressionMethodName(CompressionMethod method) noexcept;
124 unsigned maxRetries = 3;
127 std::chrono::milliseconds initialDelay { 500 };
130 double backoffMultiplier = 2.0;
133 std::chrono::milliseconds maxDelay { 30000 };
152 std::vector<SqlSchema::IndexDefinition>
indexes;
230 (void) additionalItems;
247 if (progress.
state == Progress::State::Error)
257 size_t _errorCount = 0;
260struct NullProgressManager: ErrorTrackingProgressManager
262 void Update(Progress
const& progress)
override
266 void AllDone()
override {}
281LIGHTWEIGHT_API
void Backup(std::filesystem::path
const& outputFile,
282 SqlConnectionString
const& connectionString,
283 unsigned concurrency,
284 ProgressManager& progress,
285 std::string
const& schema = {},
286 std::string
const& tableFilter =
"*",
287 RetrySettings
const& retrySettings = {},
288 BackupSettings
const& backupSettings = {});
301LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
302 SqlConnectionString
const& connectionString,
303 unsigned concurrency,
304 ProgressManager& progress,
305 std::string
const& schema = {},
306 std::string
const& tableFilter =
"*",
307 RetrySettings
const& retrySettings = {});
319LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
320 SqlConnectionString
const& connectionString,
321 unsigned concurrency,
322 ProgressManager& progress,
323 std::string
const& schema,
324 std::string
const& tableFilter,
325 RetrySettings
const& retrySettings,
326 RestoreSettings
const& restoreSettings);
333LIGHTWEIGHT_API std::string CreateMetadata(SqlConnectionString
const& connectionString,
334 SqlSchema::TableList
const& tables,
335 std::string
const& schema = {});
340LIGHTWEIGHT_API std::map<std::string, TableInfo> ParseSchema(std::string_view metadataJson,
341 ProgressManager* progress =
nullptr);
Base class for progress managers that tracks errors automatically.
size_t ErrorCount() const noexcept override
Returns the number of errors encountered during the operation.
void Update(Progress const &progress) override
Gets called when the progress of an individual backup/restore operation changes.
Configuration for backup operations including compression and chunking.
std::size_t workerArchiveBytes
CompressionMethod method
The compression method to use.
bool forceMssqlConcurrency
std::size_t chunkSizeBytes
bool schemaOnly
If true, only export schema metadata without backing up table data.
The interface for progress updates.
virtual void SetTotalItems(size_t totalItems)
ProgressManager()=default
Default constructor.
virtual void Update(Progress const &p)=0
Gets called when the progress of an individual backup/restore operation changes.
virtual void SetMaxTableNameLength(size_t)
virtual size_t ErrorCount() const noexcept
Returns the number of errors encountered during the operation.
ProgressManager & operator=(ProgressManager const &)=default
Default copy assignment operator.
virtual void OnItemsProcessed(size_t count)
ProgressManager(ProgressManager &&)=default
Default move constructor.
ProgressManager & operator=(ProgressManager &&)=default
Default move assignment operator.
virtual void AddTotalItems(size_t additionalItems)
virtual void AllDone()=0
Gets called when all backup/restore operations are finished.
ProgressManager(ProgressManager const &)=default
Default copy constructor.
Progress information for backup/restore operations status updates.
size_t currentRows
The current number of rows processed.
State state
The state of an individual backup/restore operation.
std::string message
A message associated with the progress update.
std::optional< size_t > totalRows
The total number of rows to be processed, if known.
std::string tableName
The name of the table being backed up / restored.
State
The state of an individual backup/restore operation.
Configuration for restore operations including memory management.
std::size_t memoryLimitBytes
Memory limit in bytes (0 = auto-detect from system).
std::size_t maxRowsPerCommit
bool schemaOnly
If true, only recreate schema without importing data.
Configuration for retry behavior on transient errors during backup/restore operations.
Information about a table being backed up.
size_t rowCount
The number of rows in the table.
std::vector< SqlColumnDeclaration > columns
The list of columns in the table.
std::vector< SqlSchema::IndexDefinition > indexes
The indexes on the table (excluding primary key index).
std::vector< bool > isBinaryColumn
The list of columns in the table.
std::vector< SqlSchema::ForeignKeyConstraint > foreignKeys
The list of foreign key constraints in the table.
std::string fields
The list of columns in the table in SQL format.