mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
* fixing the order of setting backup properties so that they are correctly propogated to actual action * Adding a backup type specific test and enabling 'few' old ones which seem to work consistentenly * Adding finally block, close connection and name change as per PR comments
This commit is contained in:
@@ -172,11 +172,12 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override void Execute()
|
public override void Execute()
|
||||||
{
|
{
|
||||||
|
// set the operation properties before using them to create backup obejct
|
||||||
|
this.SetBackupProps();
|
||||||
this.backup = new Backup();
|
this.backup = new Backup();
|
||||||
this.backup.Database = this.backupInfo.DatabaseName;
|
this.backup.Database = this.backupInfo.DatabaseName;
|
||||||
this.backup.Action = this.backupActionType;
|
this.backup.Action = this.backupActionType;
|
||||||
this.backup.Incremental = this.isBackupIncremental;
|
this.backup.Incremental = this.isBackupIncremental;
|
||||||
this.SetBackupProps();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,165 +71,239 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create simple backup test
|
/// Create simple backup test
|
||||||
/// </summary>
|
/// </summary>
|
||||||
//[Fact]
|
[Fact]
|
||||||
public void CreateBackupTest()
|
public void CreateBackupTest()
|
||||||
{
|
{
|
||||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||||
string databaseName = "testbackup_" + new Random().Next(10000000, 99999999);
|
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
||||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
|
||||||
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
|
||||||
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
|
||||||
|
|
||||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
try
|
||||||
|
{
|
||||||
|
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||||
|
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
||||||
|
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
||||||
|
|
||||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||||
BackupType.Full,
|
|
||||||
new List<string>() { backupPath },
|
|
||||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
|
||||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
|
||||||
|
|
||||||
// Backup the database
|
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||||
service.PerformBackup(backupOperation);
|
BackupType.Full,
|
||||||
|
new List<string>() { backupPath },
|
||||||
|
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||||
|
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
VerifyAndCleanBackup(backupPath);
|
// Backup the database
|
||||||
testDb.Cleanup();
|
service.PerformBackup(backupOperation);
|
||||||
|
|
||||||
|
VerifyAndCleanBackup(backupPath);
|
||||||
|
sqlConn.Close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
testDb.Cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Fact]
|
[Fact]
|
||||||
public void ScriptBackupTest()
|
public void ScriptBackupTest()
|
||||||
{
|
{
|
||||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||||
string databaseName = "testbackup_" + new Random().Next(10000000, 99999999);
|
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
||||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
|
||||||
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
|
||||||
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
|
||||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
|
||||||
|
|
||||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
try
|
||||||
BackupType.Full,
|
{
|
||||||
new List<string>() { backupPath },
|
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
||||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
||||||
|
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
// Generate script for backup
|
|
||||||
service.ScriptBackup(backupOperation);
|
|
||||||
string script = backupOperation.ScriptContent;
|
|
||||||
Assert.True(!string.IsNullOrEmpty(script));
|
|
||||||
|
|
||||||
// Execute the script
|
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||||
testDb.RunQuery(script);
|
BackupType.Full,
|
||||||
|
new List<string>() { backupPath },
|
||||||
|
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||||
|
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
VerifyAndCleanBackup(backupPath);
|
// Generate script for backup
|
||||||
testDb.Cleanup();
|
service.ScriptBackup(backupOperation);
|
||||||
|
string script = backupOperation.ScriptContent;
|
||||||
|
Assert.True(!string.IsNullOrEmpty(script));
|
||||||
|
|
||||||
|
// Execute the script
|
||||||
|
testDb.RunQuery(script);
|
||||||
|
|
||||||
|
VerifyAndCleanBackup(backupPath);
|
||||||
|
sqlConn.Close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
testDb.Cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test creating backup with advanced options set.
|
/// Test creating backup with advanced options set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
//[Fact]
|
[Fact]
|
||||||
public void CreateBackupWithAdvancedOptionsTest()
|
public void CreateBackupWithAdvancedOptionsTest()
|
||||||
{
|
{
|
||||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||||
string databaseName = "testbackup_" + new Random().Next(10000000, 99999999);
|
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
||||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
|
||||||
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
|
||||||
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
|
||||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
|
||||||
|
|
||||||
string certificateName = CreateCertificate(testDb);
|
try
|
||||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
{
|
||||||
|
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||||
|
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
||||||
|
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
||||||
|
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
string certificateName = CreateCertificate(testDb);
|
||||||
BackupType.Full,
|
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||||
new List<string>(){ backupPath },
|
|
||||||
new Dictionary<string, int>(){{ backupPath, (int)DeviceType.File }});
|
|
||||||
backupInfo.ContinueAfterError = true;
|
|
||||||
backupInfo.FormatMedia = true;
|
|
||||||
backupInfo.SkipTapeHeader = true;
|
|
||||||
backupInfo.Initialize = true;
|
|
||||||
backupInfo.MediaName = "backup test media";
|
|
||||||
backupInfo.MediaDescription = "backup test";
|
|
||||||
backupInfo.RetainDays = 90;
|
|
||||||
backupInfo.CompressionOption = (int)BackupCompressionOptions.On;
|
|
||||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
|
||||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
|
||||||
backupInfo.EncryptorName = certificateName;
|
|
||||||
|
|
||||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||||
|
BackupType.Full,
|
||||||
// Backup the database
|
new List<string>() { backupPath },
|
||||||
Console.WriteLine("Perform backup operation..");
|
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||||
service.PerformBackup(backupOperation);
|
backupInfo.ContinueAfterError = true;
|
||||||
|
backupInfo.FormatMedia = true;
|
||||||
|
backupInfo.SkipTapeHeader = true;
|
||||||
|
backupInfo.Initialize = true;
|
||||||
|
backupInfo.MediaName = "backup test media";
|
||||||
|
backupInfo.MediaDescription = "backup test";
|
||||||
|
backupInfo.RetainDays = 90;
|
||||||
|
backupInfo.CompressionOption = (int)BackupCompressionOptions.On;
|
||||||
|
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||||
|
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||||
|
backupInfo.EncryptorName = certificateName;
|
||||||
|
|
||||||
// Remove the backup file
|
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||||
Console.WriteLine("Verify the backup file exists and remove..");
|
|
||||||
VerifyAndCleanBackup(backupPath);
|
|
||||||
|
|
||||||
// Delete certificate and master key
|
// Backup the database
|
||||||
Console.WriteLine("Remove certificate and master key..");
|
Console.WriteLine("Perform backup operation..");
|
||||||
testDb.RunQuery(cleanupCertificateQuery);
|
service.PerformBackup(backupOperation);
|
||||||
|
|
||||||
// Clean up the database
|
// Remove the backup file
|
||||||
Console.WriteLine("Clean up database..");
|
Console.WriteLine("Verify the backup file exists and remove..");
|
||||||
testDb.Cleanup();
|
VerifyAndCleanBackup(backupPath);
|
||||||
|
|
||||||
|
// Delete certificate and master key
|
||||||
|
Console.WriteLine("Remove certificate and master key..");
|
||||||
|
testDb.RunQuery(cleanupCertificateQuery);
|
||||||
|
|
||||||
|
sqlConn.Close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Clean up the database
|
||||||
|
Console.WriteLine("Clean up database..");
|
||||||
|
testDb.Cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test creating backup with advanced options set.
|
/// Test creating backup with advanced options set.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
//[Fact]
|
[Fact]
|
||||||
public void ScriptBackupWithAdvancedOptionsTest()
|
public void ScriptBackupWithAdvancedOptionsTest()
|
||||||
{
|
{
|
||||||
DisasterRecoveryService service = new DisasterRecoveryService();
|
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||||
string databaseName = "testbackup_" + new Random().Next(10000000, 99999999);
|
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||||
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
||||||
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
|
||||||
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
|
||||||
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
|
||||||
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
|
||||||
|
|
||||||
string certificateName = CreateCertificate(testDb);
|
try
|
||||||
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
{
|
||||||
|
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||||
|
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
||||||
|
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
||||||
|
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
string certificateName = CreateCertificate(testDb);
|
||||||
BackupType.Full,
|
string cleanupCertificateQuery = string.Format(CleanupCertificateQueryFormat, certificateName);
|
||||||
new List<string>() { backupPath },
|
|
||||||
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
|
||||||
backupInfo.FormatMedia = true;
|
|
||||||
backupInfo.SkipTapeHeader = true;
|
|
||||||
backupInfo.Initialize = true;
|
|
||||||
backupInfo.MediaName = "backup test media";
|
|
||||||
backupInfo.MediaDescription = "backup test";
|
|
||||||
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
|
||||||
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
|
||||||
backupInfo.EncryptorName = certificateName;
|
|
||||||
|
|
||||||
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
BackupInfo backupInfo = CreateDefaultBackupInfo(databaseName,
|
||||||
|
BackupType.Full,
|
||||||
|
new List<string>() { backupPath },
|
||||||
|
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||||
|
backupInfo.FormatMedia = true;
|
||||||
|
backupInfo.SkipTapeHeader = true;
|
||||||
|
backupInfo.Initialize = true;
|
||||||
|
backupInfo.MediaName = "backup test media";
|
||||||
|
backupInfo.MediaDescription = "backup test";
|
||||||
|
backupInfo.EncryptionAlgorithm = (int)BackupEncryptionAlgorithm.Aes128;
|
||||||
|
backupInfo.EncryptorType = (int)BackupEncryptorType.ServerCertificate;
|
||||||
|
backupInfo.EncryptorName = certificateName;
|
||||||
|
|
||||||
// Backup the database
|
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfo, helper.DataContainer, sqlConn);
|
||||||
Console.WriteLine("Generate script for backup operation..");
|
|
||||||
service.ScriptBackup(backupOperation);
|
|
||||||
string script = backupOperation.ScriptContent;
|
|
||||||
|
|
||||||
// Run the script
|
// Backup the database
|
||||||
Console.WriteLine("Execute the script..");
|
Console.WriteLine("Generate script for backup operation..");
|
||||||
testDb.RunQuery(script);
|
service.ScriptBackup(backupOperation);
|
||||||
|
string script = backupOperation.ScriptContent;
|
||||||
|
|
||||||
// Remove the backup file
|
// Run the script
|
||||||
Console.WriteLine("Verify the backup file exists and remove..");
|
Console.WriteLine("Execute the script..");
|
||||||
VerifyAndCleanBackup(backupPath);
|
testDb.RunQuery(script);
|
||||||
|
|
||||||
// Delete certificate and master key
|
// Remove the backup file
|
||||||
Console.WriteLine("Remove certificate and master key..");
|
Console.WriteLine("Verify the backup file exists and remove..");
|
||||||
testDb.RunQuery(cleanupCertificateQuery);
|
VerifyAndCleanBackup(backupPath);
|
||||||
|
|
||||||
// Clean up the database
|
// Delete certificate and master key
|
||||||
Console.WriteLine("Clean up database..");
|
Console.WriteLine("Remove certificate and master key..");
|
||||||
testDb.Cleanup();
|
testDb.RunQuery(cleanupCertificateQuery);
|
||||||
|
sqlConn.Close();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Clean up the database
|
||||||
|
Console.WriteLine("Clean up database..");
|
||||||
|
testDb.Cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Test the correct script generation for different backup action types
|
||||||
|
/// </summary>
|
||||||
|
[Fact]
|
||||||
|
public void ScriptBackupWithDifferentActionTypesTest()
|
||||||
|
{
|
||||||
|
string databaseName = "SqlToolsService_TestBackup_" + new Random().Next(10000000, 99999999);
|
||||||
|
SqlTestDb testDb = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Create Full backup script
|
||||||
|
string script = GenerateScriptForBackupType(BackupType.Full, databaseName);
|
||||||
|
|
||||||
|
// Validate Full backup script
|
||||||
|
Assert.Contains("BACKUP DATABASE", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.DoesNotContain("BACKUP LOG", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.DoesNotContain("DIFFERENTIAL", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// Create log backup script
|
||||||
|
script = GenerateScriptForBackupType(BackupType.TransactionLog, databaseName);
|
||||||
|
|
||||||
|
// Validate Log backup script
|
||||||
|
Assert.Contains("BACKUP LOG", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.DoesNotContain("BACKUP DATABASE", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.DoesNotContain("DIFFERENTIAL", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
// Create differential backup script
|
||||||
|
script = GenerateScriptForBackupType(BackupType.Differential, databaseName);
|
||||||
|
|
||||||
|
// Validate differential backup script
|
||||||
|
Assert.Contains("BACKUP DATABASE", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.DoesNotContain("BACKUP LOG", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
Assert.Contains("WITH DIFFERENTIAL", script, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Clean up the database
|
||||||
|
Console.WriteLine("Clean up database..");
|
||||||
|
testDb.Cleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Fact]
|
//[Fact]
|
||||||
@@ -393,6 +467,37 @@ CREATE CERTIFICATE {1} WITH SUBJECT = 'Backup Encryption Certificate'; ";
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string GenerateScriptForBackupType(BackupType backupType, string databaseName)
|
||||||
|
{
|
||||||
|
DisasterRecoveryService service = new DisasterRecoveryService();
|
||||||
|
var liveConnection = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
|
||||||
|
DatabaseTaskHelper helper = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
|
||||||
|
SqlConnection sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
|
||||||
|
string backupPath = GetDefaultBackupFullPath(service, databaseName, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
|
BackupInfo backupInfoLog = CreateDefaultBackupInfo(databaseName,
|
||||||
|
backupType,
|
||||||
|
new List<string>() { backupPath },
|
||||||
|
new Dictionary<string, int>() { { backupPath, (int)DeviceType.File } });
|
||||||
|
backupInfoLog.FormatMedia = true;
|
||||||
|
backupInfoLog.SkipTapeHeader = true;
|
||||||
|
backupInfoLog.Initialize = true;
|
||||||
|
backupInfoLog.MediaName = "backup test media";
|
||||||
|
backupInfoLog.MediaDescription = "backup test";
|
||||||
|
BackupOperation backupOperation = CreateBackupOperation(service, liveConnection.ConnectionInfo.OwnerUri, backupInfoLog, helper.DataContainer, sqlConn);
|
||||||
|
|
||||||
|
// Generate Script
|
||||||
|
Console.WriteLine("Generate script for backup operation..");
|
||||||
|
service.ScriptBackup(backupOperation);
|
||||||
|
string script = backupOperation.ScriptContent;
|
||||||
|
|
||||||
|
// There shouldnt be any backup file created
|
||||||
|
Assert.True(!File.Exists(backupPath), "Backup file is not expected to be created");
|
||||||
|
|
||||||
|
sqlConn.Close();
|
||||||
|
return script;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user