Skip to content

Commit

Permalink
Implement verbint
Browse files Browse the repository at this point in the history
  • Loading branch information
cincuranet committed Jun 6, 2024
1 parent 73b0082 commit 5181a7d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
37 changes: 33 additions & 4 deletions src/FirebirdSql.Data.FirebirdClient.Tests/FbServicesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,40 @@ public async Task BackupRestoreZipTest()
var backupName = $"{Guid.NewGuid()}.bak";
var csb = BuildServicesConnectionStringBuilder(ServerType, Compression, WireCrypt, true);
var connectionString = csb.ToString();
await BackupPartHelper(backupName, connectionString, FbBackupFlags.Zip);
await BackupPartHelper(backupName, connectionString, x =>
{
x.Options |= FbBackupFlags.Zip;
});
await RestorePartHelper(backupName, connectionString);
// test the database was actually restored fine
await Connection.OpenAsync();
await Connection.CloseAsync();
}

[Test]
public async Task BackupRestoreVerbIntTest()
{
if (!EnsureServerVersionAtLeast(new Version(3, 0, 0, 0)))
return;

var backupName = $"{Guid.NewGuid()}.bak";
var csb = BuildServicesConnectionStringBuilder(ServerType, Compression, WireCrypt, true);
var connectionString = csb.ToString();
await BackupPartHelper(backupName, connectionString, x =>
{
x.Verbose = true;
x.VerboseInterval = 1_000_000;
});
await RestorePartHelper(backupName, connectionString, x =>
{
x.Verbose = true;
x.VerboseInterval = 1_000_000;
});
// test the database was actually restored fine
await Connection.OpenAsync();
await Connection.CloseAsync();
}

[Test]
public async Task BackupRestoreParallelTest()
{
Expand Down Expand Up @@ -469,18 +496,19 @@ public async Task NFixupTest()
Assert.DoesNotThrowAsync(() => Connection.OpenAsync());
}

static Task BackupPartHelper(string backupName, string connectionString, FbBackupFlags backupFlags = FbBackupFlags.IgnoreLimbo)
static Task BackupPartHelper(string backupName, string connectionString, Action<FbBackup> configure = null)
{
var backupSvc = new FbBackup();
backupSvc.ConnectionString = connectionString;
backupSvc.Options = backupFlags;
backupSvc.Options = FbBackupFlags.IgnoreLimbo;
backupSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048));
backupSvc.Verbose = true;
backupSvc.Statistics = FbBackupRestoreStatistics.TotalTime | FbBackupRestoreStatistics.TimeDelta;
backupSvc.ServiceOutput += ServiceOutput;
configure?.Invoke(backupSvc);
return backupSvc.ExecuteAsync();
}
static Task RestorePartHelper(string backupName, string connectionString)
static Task RestorePartHelper(string backupName, string connectionString, Action<FbRestore> configure = null)
{
var restoreSvc = new FbRestore();
restoreSvc.ConnectionString = connectionString;
Expand All @@ -490,6 +518,7 @@ static Task RestorePartHelper(string backupName, string connectionString)
restoreSvc.Statistics = FbBackupRestoreStatistics.TotalTime | FbBackupRestoreStatistics.TimeDelta;
restoreSvc.BackupFiles.Add(new FbBackupFile(backupName, 2048));
restoreSvc.ServiceOutput += ServiceOutput;
configure?.Invoke(restoreSvc);
return restoreSvc.ExecuteAsync();
}

Expand Down
3 changes: 3 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient/Services/FbBackup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class FbBackup : FbService
{
public FbBackupFileCollection BackupFiles { get; }
public bool Verbose { get; set; }
public int? VerboseInterval { get; set; }
public int Factor { get; set; }
public string SkipData { get; set; }
public FbBackupFlags Options { get; set; }
Expand Down Expand Up @@ -59,6 +60,8 @@ public void Execute()
}
if (Verbose)
startSpb.Append(IscCodes.isc_spb_verbose);
if (VerboseInterval.HasValue)
startSpb.Append(IscCodes.isc_spb_verbint, (int)VerboseInterval);
if (Factor > 0)
startSpb.Append(IscCodes.isc_spb_bkp_factor, Factor);
if (!string.IsNullOrEmpty(SkipData))
Expand Down
3 changes: 3 additions & 0 deletions src/FirebirdSql.Data.FirebirdClient/Services/FbRestore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public int? PageSize

public FbBackupFileCollection BackupFiles { get; }
public bool Verbose { get; set; }
public int? VerboseInterval { get; set; }
public int? PageBuffers { get; set; }
public bool ReadOnly { get; set; }
public string SkipData { get; set; }
Expand Down Expand Up @@ -71,6 +72,8 @@ public void Execute()
startSpb.Append2(IscCodes.isc_spb_dbname, ConnectionStringOptions.Database);
if (Verbose)
startSpb.Append(IscCodes.isc_spb_verbose);
if (VerboseInterval.HasValue)
startSpb.Append(IscCodes.isc_spb_verbint, (int)VerboseInterval);
if (PageBuffers.HasValue)
startSpb.Append(IscCodes.isc_spb_res_buffers, (int)PageBuffers);
if (_pageSize.HasValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public int? PageSize

public Stream InputStream { get; set; }
public bool Verbose { get; set; }
public int? VerboseInterval { get; set; }
public int? PageBuffers { get; set; }
public bool ReadOnly { get; set; }
public string SkipData { get; set; }
Expand All @@ -68,9 +69,9 @@ public void Execute()
startSpb.Append2(IscCodes.isc_spb_bkp_file, "stdin");
startSpb.Append2(IscCodes.isc_spb_dbname, ConnectionStringOptions.Database);
if (Verbose)
{
startSpb.Append(IscCodes.isc_spb_verbose);
}
if (VerboseInterval.HasValue)
startSpb.Append(IscCodes.isc_spb_verbint, (int)VerboseInterval);
if (PageBuffers.HasValue)
startSpb.Append(IscCodes.isc_spb_res_buffers, (int)PageBuffers);
if (_pageSize.HasValue)
Expand Down

0 comments on commit 5181a7d

Please sign in to comment.