mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Fix/restore options issues (#515)
* fixed the bug with tail log option * fix the bug with the tail gate file name * closing connections before restore
This commit is contained in:
@@ -73,8 +73,8 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
private DatabaseRestorePlanner restorePlanner;
|
private DatabaseRestorePlanner restorePlanner;
|
||||||
private string tailLogBackupFile;
|
private string tailLogBackupFile;
|
||||||
private BackupSetsFilterInfo backupSetsFilterInfo = new BackupSetsFilterInfo();
|
private BackupSetsFilterInfo backupSetsFilterInfo = new BackupSetsFilterInfo();
|
||||||
private bool? isTailLogBackupPossible = false;
|
private bool? isTailLogBackupPossible = null;
|
||||||
private bool? isTailLogBackupWithNoRecoveryPossible = false;
|
private bool? isTailLogBackupWithNoRecoveryPossible = null;
|
||||||
private string backupMediaList = string.Empty;
|
private string backupMediaList = string.Empty;
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
@@ -520,6 +520,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
{
|
{
|
||||||
if (!isTailLogBackupPossible.HasValue)
|
if (!isTailLogBackupPossible.HasValue)
|
||||||
{
|
{
|
||||||
|
//TODO: get the value from DatabaseRestorePlanner.IsTailLogBackupPossible
|
||||||
if (this.Server.Version.Major < 9 || String.IsNullOrEmpty(this.restorePlanner.DatabaseName))
|
if (this.Server.Version.Major < 9 || String.IsNullOrEmpty(this.restorePlanner.DatabaseName))
|
||||||
{
|
{
|
||||||
isTailLogBackupPossible = false;
|
isTailLogBackupPossible = false;
|
||||||
@@ -566,6 +567,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
{
|
{
|
||||||
if (!isTailLogBackupWithNoRecoveryPossible.HasValue)
|
if (!isTailLogBackupWithNoRecoveryPossible.HasValue)
|
||||||
{
|
{
|
||||||
|
//TODO: get the value from DatabaseRestorePlanner.IsTailLogBackupWithNoRecoveryPossible
|
||||||
string databaseName = this.RestorePlanner.DatabaseName;
|
string databaseName = this.RestorePlanner.DatabaseName;
|
||||||
if (!IsTailLogBackupPossible)
|
if (!IsTailLogBackupPossible)
|
||||||
{
|
{
|
||||||
@@ -748,11 +750,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
{
|
{
|
||||||
string currentDatabaseName = this.RestorePlanner.DatabaseName;
|
string currentDatabaseName = this.RestorePlanner.DatabaseName;
|
||||||
this.RestorePlanner.DatabaseName = value;
|
this.RestorePlanner.DatabaseName = value;
|
||||||
|
|
||||||
if (string.Compare(currentDatabaseName, value, StringComparison.InvariantCultureIgnoreCase) != 0)
|
|
||||||
{
|
|
||||||
ResetOptions();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -961,6 +958,10 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
this.RestorePlan = new RestorePlan(this.Server);
|
this.RestorePlan = new RestorePlan(this.Server);
|
||||||
this.Util.AddCredentialNameForUrlBackupSet(this.RestorePlan, this.CredentialName);
|
this.Util.AddCredentialNameForUrlBackupSet(this.RestorePlan, this.CredentialName);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ResetOptions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ShouldCreateNewPlan()
|
public bool ShouldCreateNewPlan()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
|
using System.Globalization;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
||||||
{
|
{
|
||||||
@@ -57,16 +58,13 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
|
|||||||
{
|
{
|
||||||
DateTime dt = DateTime.MinValue;
|
DateTime dt = DateTime.MinValue;
|
||||||
|
|
||||||
//TODO: the code is moved from ssms and used for restore differential backups
|
|
||||||
//Uncomment when restore operation for differential backups is supported
|
|
||||||
/*
|
|
||||||
string query = "SELECT GETDATE()";
|
string query = "SELECT GETDATE()";
|
||||||
DataSet dataset = this.server.ExecutionManager.ExecuteWithResults(query);
|
DataSet dataset = this.server.ExecutionManager.ConnectionContext.ExecuteWithResults(query);
|
||||||
if (dataset != null && dataset.Tables.Count > 0 && dataset.Tables[0].Rows.Count > 0)
|
if (dataset != null && dataset.Tables.Count > 0 && dataset.Tables[0].Rows.Count > 0)
|
||||||
{
|
{
|
||||||
dt = Convert.ToDateTime(dataset.Tables[0].Rows[0][0], SmoApplication.DefaultCulture);
|
dt = Convert.ToDateTime(dataset.Tables[0].Rows[0][0], CultureInfo.CurrentCulture);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
using Microsoft.SqlServer.Management.Smo;
|
using Microsoft.SqlServer.Management.Smo;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
||||||
{
|
{
|
||||||
@@ -83,20 +84,38 @@ namespace Microsoft.SqlTools.ServiceLayer.TaskServices
|
|||||||
|
|
||||||
public bool GainAccessToDatabase()
|
public bool GainAccessToDatabase()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (LockedDatabaseManager != null)
|
if (LockedDatabaseManager != null)
|
||||||
{
|
{
|
||||||
return LockedDatabaseManager.GainFullAccessToDatabase(ServerName, DatabaseName);
|
result = LockedDatabaseManager.GainFullAccessToDatabase(ServerName, DatabaseName);
|
||||||
}
|
}
|
||||||
return false;
|
if(result && SourceDatabas != null && string.Compare(DatabaseName , SourceDatabas, StringComparison.InvariantCultureIgnoreCase) != 0)
|
||||||
|
{
|
||||||
|
result = LockedDatabaseManager.GainFullAccessToDatabase(ServerName, SourceDatabas);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool ReleaseAccessToDatabase()
|
public bool ReleaseAccessToDatabase()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (LockedDatabaseManager != null)
|
if (LockedDatabaseManager != null)
|
||||||
{
|
{
|
||||||
return LockedDatabaseManager.ReleaseAccess(ServerName, DatabaseName);
|
result = LockedDatabaseManager.ReleaseAccess(ServerName, DatabaseName);
|
||||||
|
}
|
||||||
|
if (result && SourceDatabas != null && string.Compare(DatabaseName, SourceDatabas, StringComparison.InvariantCultureIgnoreCase) != 0)
|
||||||
|
{
|
||||||
|
result = LockedDatabaseManager.ReleaseAccess(ServerName, SourceDatabas);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string SourceDatabas
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Server?.ConnectionContext.DatabaseName;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user