Skip to content

Commit

Permalink
fixed some small bugs in restore
Browse files Browse the repository at this point in the history
  • Loading branch information
llali committed Aug 17, 2017
1 parent 751764c commit 24baa6b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Travis CI](https://travis-ci.org/Microsoft/sqltoolsservice.svg?branch=dev)](https://travis-ci.org/Microsoft/sqltoolsservice)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/Microsoft/sqltoolsservice?svg=true&retina=true&branch=dev)](https://ci.appveyor.com/project/kburtram/sqltoolsservice)
[![Coverage Status](https://coveralls.io/repos/github/Microsoft/sqltoolsservice/badge.svg?branch=dev)](https://coveralls.io/github/Microsoft/sqltoolsservice?branch=dev)
[![Coverage Status](https://coveralls.io/repos/github/Microsoft/sqltoolsservice/badge.svg?branch=dev)](https://coveralls.io/github/Microsoft/sqltoolsservice?branch=master)

# Microsoft SQL Tools Service
The SQL Tools Service is an application that provides core functionality for various SQL Server tools. These features include the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public RestorePlanResponse CreateRestorePlanResponse(RestoreDatabaseTaskDataObje
response.ErrorMessage += Environment.NewLine;
response.ErrorMessage += ex.InnerException.Message;
}
Logger.Write(LogLevel.Normal, $"Failed to create restore plan. error: { response.ErrorMessage}");
}
return response;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts;
using Microsoft.SqlTools.ServiceLayer.TaskServices;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Microsoft.SqlTools.Utility;

namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.RestoreOperation
{
Expand Down Expand Up @@ -808,21 +809,28 @@ public List<DbFile> GetDbFiles()
{
Database db = null;
List<DbFile> ret = new List<DbFile>();
if (!this.RestorePlanner.ReadHeaderFromMedia)
{
db = this.Server.Databases[this.RestorePlanner.DatabaseName];
}
if (restorePlan != null && restorePlan.RestoreOperations.Count > 0)
try
{
if (db != null && db.Status == DatabaseStatus.Normal)
if (!this.RestorePlanner.ReadHeaderFromMedia)
{
ret = this.Util.GetDbFiles(db);
db = this.Server.Databases[this.RestorePlanner.DatabaseName];
}
else
if (restorePlan != null && restorePlan.RestoreOperations.Count > 0)
{
ret = this.Util.GetDbFiles(restorePlan.RestoreOperations[0]);
if (db != null && db.Status == DatabaseStatus.Normal)
{
ret = this.Util.GetDbFiles(db);
}
else
{
ret = this.Util.GetDbFiles(restorePlan.RestoreOperations[0]);
}
}
}
catch(Exception ex )
{
Logger.Write(LogLevel.Normal, $"Failed to get restore db files. error: {ex.Message}");
}
return ret;
}

Expand Down Expand Up @@ -1254,10 +1262,14 @@ internal void UpdateRestoreTaskObject()
{
bool shouldCreateNewPlan = ShouldCreateNewPlan();

if (!string.IsNullOrEmpty(RestoreParams.BackupFilePaths))
if (!string.IsNullOrEmpty(RestoreParams.BackupFilePaths) && RestoreParams.ReadHeaderFromMedia)
{
AddFiles(RestoreParams.BackupFilePaths);
}
else
{
RestorePlanner.BackupMediaList.Clear();
}
RestorePlanner.ReadHeaderFromMedia = RestoreParams.ReadHeaderFromMedia;

RestoreOptionFactory.Instance.SetAndValidate(RestoreOptionsHelper.SourceDatabaseName, this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,15 @@ private RestoreOptionFactory()
},
ValidateFunction = (IRestoreDatabaseTaskDataObject restoreDataObject, object currentValue, object defaultValue) =>
{
string errorMessage = string.Empty;
if (currentValue!= null && DatabaseUtils.IsSystemDatabaseConnection(currentValue.ToString()))
{
errorMessage = "Cannot restore to system database";
}
return new OptionValidationResult()
{
IsReadOnly = !restoreDataObject.CanChangeTargetDatabase
IsReadOnly = !restoreDataObject.CanChangeTargetDatabase,
ErrorMessage = errorMessage
};
},
SetValueFunction = (IRestoreDatabaseTaskDataObject restoreDataObject, object value) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ public void ServiceInitialization()
[Fact]
public void PrepopulateCommonMetadata()
{
var result = LiveConnectionHelper.InitLiveConnectionInfo();
var connInfo = result.ConnectionInfo;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var result = LiveConnectionHelper.InitLiveConnectionInfo("master", queryTempFile.FilePath);
var connInfo = result.ConnectionInfo;

ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };
ScriptParseInfo scriptInfo = new ScriptParseInfo { IsConnected = true };

LanguageService.Instance.PrepopulateCommonMetadata(connInfo, scriptInfo, null);
LanguageService.Instance.PrepopulateCommonMetadata(connInfo, scriptInfo, null);
}
}

// This test currently requires a live database connection to initialize
Expand Down

0 comments on commit 24baa6b

Please sign in to comment.