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;
209 virtual void AddTotalItems(
size_t additionalItems) { (void) additionalItems; }
222 if (progress.
state == Progress::State::Error)
232 size_t _errorCount = 0;
235struct NullProgressManager: ErrorTrackingProgressManager
237 void Update(Progress
const& progress)
override
241 void AllDone()
override {}
256LIGHTWEIGHT_API
void Backup(std::filesystem::path
const& outputFile,
257 SqlConnectionString
const& connectionString,
258 unsigned concurrency,
259 ProgressManager& progress,
260 std::string
const& schema = {},
261 std::string
const& tableFilter =
"*",
262 RetrySettings
const& retrySettings = {},
263 BackupSettings
const& backupSettings = {});
276LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
277 SqlConnectionString
const& connectionString,
278 unsigned concurrency,
279 ProgressManager& progress,
280 std::string
const& schema = {},
281 std::string
const& tableFilter =
"*",
282 RetrySettings
const& retrySettings = {});
294LIGHTWEIGHT_API
void Restore(std::filesystem::path
const& inputFile,
295 SqlConnectionString
const& connectionString,
296 unsigned concurrency,
297 ProgressManager& progress,
298 std::string
const& schema,
299 std::string
const& tableFilter,
300 RetrySettings
const& retrySettings,
301 RestoreSettings
const& restoreSettings);
308LIGHTWEIGHT_API std::string CreateMetadata(SqlConnectionString
const& connectionString,
309 SqlSchema::TableList
const& tables,
310 std::string
const& schema = {});
315LIGHTWEIGHT_API std::map<std::string, TableInfo> ParseSchema(std::string_view metadataJson,
316 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 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.