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;
83LIGHTWEIGHT_API std::size_t GetAvailableSystemMemory() noexcept;
90LIGHTWEIGHT_API
RestoreSettings CalculateRestoreSettings(std::
size_t availableMemory,
unsigned concurrency);
96LIGHTWEIGHT_API
bool IsCompressionMethodSupported(CompressionMethod method) noexcept;
99LIGHTWEIGHT_API std::vector<CompressionMethod> GetSupportedCompressionMethods() noexcept;
102LIGHTWEIGHT_API std::string_view CompressionMethodName(CompressionMethod method) noexcept;
108 unsigned maxRetries = 3;
111 std::chrono::milliseconds initialDelay { 500 };
114 double backoffMultiplier = 2.0;
117 std::chrono::milliseconds maxDelay { 30000 };
136 std::vector<SqlSchema::IndexDefinition>
indexes;
217 if (progress.
state == Progress::State::Error)
227 size_t _errorCount = 0;
230struct NullProgressManager: ErrorTrackingProgressManager
232 void Update(Progress
const& progress)
override
236 void AllDone()
override {}
251LIGHTWEIGHT_API
void Backup(std::filesystem::path
const& outputFile,
252 SqlConnectionString
const& connectionString,
253 unsigned concurrency,
254 ProgressManager& progress,
255 std::string
const& schema = {},
256 std::string
const& tableFilter =
"*",
257 RetrySettings
const& retrySettings = {},
258 BackupSettings
const& backupSettings = {});
271LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
272 SqlConnectionString
const& connectionString,
273 unsigned concurrency,
274 ProgressManager& progress,
275 std::string
const& schema = {},
276 std::string
const& tableFilter =
"*",
277 RetrySettings
const& retrySettings = {});
289LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
290 SqlConnectionString
const& connectionString,
291 unsigned concurrency,
292 ProgressManager& progress,
293 std::string
const& schema,
294 std::string
const& tableFilter,
295 RetrySettings
const& retrySettings,
296 RestoreSettings
const& restoreSettings);
303LIGHTWEIGHT_API std::string CreateMetadata(SqlConnectionString
const& connectionString,
304 SqlSchema::TableList
const& tables,
305 std::string
const& schema = {});
310LIGHTWEIGHT_API std::map<std::string, TableInfo> ParseSchema(std::string_view metadataJson,
311 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.
CompressionMethod method
The compression method to use.
std::size_t chunkSizeBytes
bool schemaOnly
If true, only export schema metadata without backing up table data.
The interface for progress updates.
virtual void AddTotalItems(size_t)
virtual void Update(Progress const &p)=0
Gets called when the progress of an individual backup/restore operation changes.
virtual void OnItemsProcessed(size_t)
virtual void SetMaxTableNameLength(size_t)
virtual size_t ErrorCount() const noexcept
Returns the number of errors encountered during the operation.
virtual void AllDone()=0
Gets called when all backup/restore operations are finished.
virtual void SetTotalItems(size_t)
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.