Skip to content

Latest commit

 

History

History
67 lines (47 loc) · 3.02 KB

File metadata and controls

67 lines (47 loc) · 3.02 KB

MySqlBackup.NET.RawBytes

A dependency-free C# library for MySQL backup and restore, built as a new foundation for the successor to MySqlBackup.NET.

It speaks the MySQL wire protocol directly. Exported row values stay as bytes: numbers pass through unchanged, text is escaped, and binary values become SQL hex literals. No ADO.NET driver, DataTable, or per-cell DateTime/decimal/string conversion.

Features

  • Export to any writable Stream, including files, gzip, and network streams.
  • Reusable row buffers, multi-packet rows, and bounded INSERT sizes.
  • Preserve Unicode, NULLs, binary data, zero dates, and microsecond precision; export and restore timestamps in UTC.
  • Export tables, generated-column definitions, invisible-column data, views, routines, triggers, and events.
  • InnoDB consistent snapshots, session-setting restoration, and fail-fast restore.
  • UTF-8 SQL import with DELIMITER, quoted values, and MySQL executable comments.
  • TLS with certificate validation; native-password and caching-SHA2 authentication.

Targets .NET Framework 4.8, .NET Standard 2.0, and .NET 8. The library has no third-party runtime dependencies.

Use

Build the solution and reference src/MySqlBackup.RawBytes/MySqlBackup.RawBytes.csproj.

using System;
using System.IO;
using MySqlBackup.RawBytes;

using (var connection = MySqlConnection.Open(new ConnectionOptions
{
    Host = "db.example.com",
    User = "backup_user",
    Password = Environment.GetEnvironmentVariable("MYSQL_PASSWORD"),
    Database = "app"
}))
{
    using (var file = File.Create("app.sql"))
        new BackupEngine(connection).Export("app", file);
}

To restore, open a connection with the existing target database selected:

using (var file = File.OpenRead("app.sql"))
    new RestoreEngine(connection).Restore(file);

Use BackupOptions for schema/data selection, object selection, row layout, and MaxInsertBytes. Wrap the output in GZipStream for compression.

Build and test

dotnet build MySqlBackup.RawBytes.sln -c Release
dotnet run --project tests/MySqlBackup.RawBytes.Tests -c Release -f net8.0

The console suite asserts protocol framing, parsing, escaping, limits, and allocations. Live integration tests verify exact restored values, schema objects, concurrent-write snapshots, TLS, and interoperability with mysql and mysqldump. Any failure returns a nonzero exit code.

Current scope

Tested with MySQL 8.0.34; view dependency discovery requires MySQL 8.0.13 or newer. Other server versions and MariaDB are not yet certified. This is a new API, not a drop-in replacement for MySqlBackup.NET.

Prevent schema changes during export. The default snapshot requires InnoDB; quiesce other engines before choosing BackupConsistency.None. Memory scales with the largest row/statement, not the whole database. Restore is not atomic, and definers and external schema references must be valid on the target. See design and limitations.

License

The Unlicense — public domain.