5#include "../SqlConnectInfo.hpp"
6#include "../SqlQuery/MigrationPlan.hpp"
7#include "../SqlRetryPolicy.hpp"
8#include "../SqlSchema.hpp"
24namespace Lightweight::SqlBackup
33enum class CompressionMethod : std::int32_t
48 CompressionMethod
method = CompressionMethod::Deflate;
108LIGHTWEIGHT_API std::size_t GetAvailableSystemMemory() noexcept;
115LIGHTWEIGHT_API
RestoreSettings CalculateRestoreSettings(std::
size_t availableMemory,
unsigned concurrency);
121LIGHTWEIGHT_API
bool IsCompressionMethodSupported(CompressionMethod method) noexcept;
124LIGHTWEIGHT_API std::vector<CompressionMethod> GetSupportedCompressionMethods() noexcept;
127LIGHTWEIGHT_API std::string_view CompressionMethodName(CompressionMethod method) noexcept;
155 std::vector<SqlSchema::IndexDefinition>
indexes;
235 (void) additionalItems;
271 if (progress.
state == Progress::State::Error)
281 size_t _errorCount = 0;
284struct NullProgressManager: ErrorTrackingProgressManager
286 void Update(Progress
const& progress)
override
290 void AllDone()
override {}
305LIGHTWEIGHT_API
void Backup(std::filesystem::path
const& outputFile,
306 SqlConnectionString
const& connectionString,
307 unsigned concurrency,
308 ProgressManager& progress,
309 std::string
const& schema = {},
310 std::string
const& tableFilter =
"*",
311 RetrySettings
const& retrySettings = {},
312 BackupSettings
const& backupSettings = {});
325LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
326 SqlConnectionString
const& connectionString,
327 unsigned concurrency,
328 ProgressManager& progress,
329 std::string
const& schema = {},
330 std::string
const& tableFilter =
"*",
331 RetrySettings
const& retrySettings = {});
343LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
344 SqlConnectionString
const& connectionString,
345 unsigned concurrency,
346 ProgressManager& progress,
347 std::string
const& schema,
348 std::string
const& tableFilter,
349 RetrySettings
const& retrySettings,
350 RestoreSettings
const& restoreSettings);
370[[nodiscard]] LIGHTWEIGHT_API std::string RedactConnectionStringSecrets(std::string_view connectionString);
377LIGHTWEIGHT_API std::string CreateMetadata(SqlConnectionString
const& connectionString,
378 SqlSchema::TableList
const& tables,
379 std::string
const& schema = {});
384LIGHTWEIGHT_API std::map<std::string, TableInfo> ParseSchema(std::string_view metadataJson,
385 ProgressManager* progress =
nullptr);
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.
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.
virtual void SetTotalItems(size_t totalItems)
ProgressManager()=default
Default constructor.
virtual void SetTotalTables(size_t totalTables)
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.
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.
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.
Information about a table being backed up.
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.