Update restore service to return default backup folder (#475)

* Fix restore to return default backup folder

* fix break

* fix tests

* fix file validator for invalid filepath
This commit is contained in:
Kate Shin
2017-10-03 16:11:30 -07:00
committed by GitHub
parent 05702182ab
commit d30b9c870d
8 changed files with 34 additions and 14 deletions

View File

@@ -142,7 +142,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
{
BackupConfigInfo configInfo = new BackupConfigInfo();
configInfo.RecoveryModel = GetRecoveryModel(databaseName);
configInfo.DefaultBackupFolder = GetDefaultBackupFolder();
configInfo.DefaultBackupFolder = CommonUtilities.GetDefaultBackupFolder(this.serverConnection);
configInfo.LatestBackups = GetLatestBackupLocations(databaseName);
configInfo.BackupEncryptors = GetBackupEncryptors();
return configInfo;
@@ -338,11 +338,6 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
return recoveryModel.ToString();
}
public string GetDefaultBackupFolder()
{
return this.backupRestoreUtil.GetDefaultBackupFolder();
}
/// <summary>
/// Return the latest backup locations
/// </summary>

View File

@@ -320,7 +320,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
return recoveryModelString;
}
public string GetDefaultBackupFolder()
public static string GetDefaultBackupFolder(ServerConnection connection)
{
string backupFolder = "";
@@ -330,7 +330,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
Request req = new Request();
en = new Enumerator();
req.Urn = "Server/Setting";
ds = en.Process(this.sqlConnection, req);
ds = en.Process(connection, req);
if (ds.Tables[0].Rows.Count > 0)
{

View File

@@ -85,18 +85,25 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
#region private methods
/// <summary>
/// Check if the folder path exists
/// </summary>
/// <param name="connection">sql connection</param>
/// <param name="filePath">full file path</param>
/// <returns></returns>
internal static string IsFolderPathExisting(SqlConnection connection, string filePath)
{
// If the file path doesn't exist, check if the folder exists
string folderPath = PathWrapper.GetDirectoryName(filePath);
string errorMessage = string.Empty;
if (string.Compare(GetMachineName(connection.DataSource), Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0)
if (string.IsNullOrEmpty(folderPath))
{
if (!string.IsNullOrEmpty(folderPath) && !Directory.Exists(folderPath))
{
errorMessage = SR.InvalidBackupPathError;
}
errorMessage = SR.InvalidBackupPathError;
}
else if (string.Compare(GetMachineName(connection.DataSource), Environment.MachineName, StringComparison.OrdinalIgnoreCase) == 0
&& !Directory.Exists(folderPath))
{
errorMessage = SR.InvalidBackupPathError;
}
else
{

View File

@@ -41,6 +41,8 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder);
// The db names with backup set
response.ConfigInfo.Add(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets, restoreTaskObject.GetDatabaseNamesWithBackupSets());
// Default backup folder path in the target server
response.ConfigInfo.Add(RestoreOptionsHelper.DefaultBackupFolder, restoreTaskObject.DefaultBackupFolder);
}
return response;

View File

@@ -25,6 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
string LogFilesFolder { get; set; }
string DefaultLogFileFolder { get; }
List<DbFile> DbFiles { get; }
string DefaultBackupFolder { get; }
RestoreOptions RestoreOptions { get; }
@@ -851,6 +852,14 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
}
}
public string DefaultBackupFolder
{
get
{
return CommonUtilities.GetDefaultBackupFolder(this.server.ConnectionContext);
}
}
internal RestorePlan CreateRestorePlan(DatabaseRestorePlanner planner, RestoreOptions restoreOptions)
{
this.CreateOrUpdateRestorePlanException = null;

View File

@@ -53,6 +53,9 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery
//Option name logFileFolder
internal const string LogFileFolder = "logFileFolder";
//Option name defaultBackupFolder
internal const string DefaultBackupFolder = "defaultBackupFolder";
//The key name to use to set the session id in the request
internal const string SessionId = "sessionId";