@@ -59,7 +59,7 @@ public static SqliteConfiguration Parse(string connectionString)
5959/// SQLite connection for CosmoSQLClient. Wraps <see cref="Microsoft.Data.Sqlite.SqliteConnection"/>
6060/// and inherits from <see cref="DbConnection"/> for compatibility with ADO.NET.
6161/// </summary>
62- public sealed class SqliteConnection : DbConnection , ISqlDatabase
62+ public sealed class SqliteConnection : DbConnection , ISqlDatabase , ISqlBackupable
6363{
6464 private SqliteConfiguration _config ;
6565 private readonly Microsoft . Data . Sqlite . SqliteConnection _conn ;
@@ -426,4 +426,18 @@ private static SqlValue TryParseString(string s)
426426 return new SqlValue . Date ( dt ) ;
427427 return new SqlValue . Text ( s ) ;
428428 }
429+
430+ public async Task BackupDatabaseAsync ( string databaseName , BackupOptions options , CancellationToken ct = default )
431+ {
432+ // SQLite uses VACUUM INTO for a safe, consistent online backup
433+ var sql = $ "VACUUM INTO '{ options . DestinationPath } ';";
434+ await ExecuteAsync ( sql , null , ct ) . ConfigureAwait ( false ) ;
435+ }
436+
437+ public Task RestoreDatabaseAsync ( string databaseName , string sourcePath , CancellationToken ct = default )
438+ {
439+ // For SQLite, restore is usually just a file copy, but since we are a driver,
440+ // we can't easily overwrite the file we are currently connected to.
441+ throw new NotSupportedException ( "SQLite restore via SQL command is not supported. Use file copy while the connection is closed." ) ;
442+ }
429443}
0 commit comments