supporting restore from db (#429)

* supporting restore from db
This commit is contained in:
Leila Lali
2017-08-09 11:01:52 -07:00
committed by GitHub
parent a4a27f9559
commit 6696b7e72f
12 changed files with 1143 additions and 369 deletions

View File

@@ -0,0 +1,43 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
{
public class RestoreConfigInfoRequestParams
{
/// <summary>
/// The Uri to find the connection to do the restore operations
/// </summary>
public string OwnerUri { get; set; }
}
public class RestoreConfigInfoResponse
{
public RestoreConfigInfoResponse()
{
ConfigInfo = new Dictionary<string, object>();
}
/// <summary>
/// Config Info
/// </summary>
public Dictionary<string, object> ConfigInfo { get; set; }
/// <summary>
/// Errors occurred while creating the restore config info
/// </summary>
public string ErrorMessage { get; set; }
}
public class RestoreConfigInfoRequest
{
public static readonly
RequestType<RestoreConfigInfoRequestParams, RestoreConfigInfoResponse> Type =
RequestType<RestoreConfigInfoRequestParams, RestoreConfigInfoResponse>.Create("disasterrecovery/restoreconfiginfo");
}
}

View File

@@ -0,0 +1,52 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
{
/// <summary>
/// Class to include the plan detail
/// </summary>
public class RestorePlanDetailInfo
{
/// <summary>
/// The name of the option from RestoreOptionsHelper
/// </summary>
public string Name { get; set; }
/// <summary>
/// The current value of the option
/// </summary>
public object CurrentValue { get; set; }
/// <summary>
/// Indicates whether the option is read only or can be changed in client
/// </summary>
public bool IsReadOnly { get; set; }
/// <summary>
/// Indicates whether the option should be visibile in client
/// </summary>
public bool IsVisiable { get; set; }
/// <summary>
/// The default value of the option
/// </summary>
public object DefaultValue { get; set; }
internal static RestorePlanDetailInfo Create(string name, object currentValue, bool isReadOnly = false, bool isVisible = true, object defaultValue = null)
{
return new RestorePlanDetailInfo
{
CurrentValue = currentValue,
IsReadOnly = isReadOnly,
Name = name,
IsVisiable = isVisible,
DefaultValue = defaultValue
};
}
}
}

View File

@@ -0,0 +1,90 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
{
/// <summary>
/// Database file info
/// </summary>
public class RestoreDatabaseFileInfo
{
/// <summary>
/// File type (Rows Data, Log ...)
/// </summary>
public string FileType { get; set; }
/// <summary>
/// Logical Name
/// </summary>
public string LogicalFileName { get; set; }
/// <summary>
/// Original location of the file to restore to
/// </summary>
public string OriginalFileName { get; set; }
/// <summary>
/// The file to restore to
/// </summary>
public string RestoreAsFileName { get; set; }
}
/// <summary>
/// Restore Plan Response
/// </summary>
public class RestorePlanResponse
{
/// <summary>
/// Restore session id, can be used in restore request to use an existing restore plan
/// </summary>
public string SessionId { get; set; }
/// <summary>
/// The list of backup sets to restore
/// </summary>
public DatabaseFileInfo[] BackupSetsToRestore { get; set; }
/// <summary>
/// Indicates whether the restore operation is supported
/// </summary>
public bool CanRestore { get; set; }
/// <summary>
/// Errors occurred while creating restore plan
/// </summary>
public string ErrorMessage { get; set; }
/// <summary>
/// The db files included in the backup file
/// </summary>
public IEnumerable<RestoreDatabaseFileInfo> DbFiles { get; set; }
/// <summary>
/// Database names extracted from backup sets
/// </summary>
public string[] DatabaseNamesFromBackupSets { get; set; }
/// <summary>
/// For testing purpose to verify the target database
/// </summary>
internal string DatabaseName { get; set; }
/// <summary>
/// Plan details
/// </summary>
public Dictionary<string, RestorePlanDetailInfo> PlanDetails { get; set; }
}
public class RestorePlanRequest
{
public static readonly
RequestType<RestoreParams, RestorePlanResponse> Type =
RequestType<RestoreParams, RestorePlanResponse>.Create("disasterrecovery/restoreplan");
}
}

View File

@@ -3,113 +3,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
using Microsoft.SqlTools.ServiceLayer.Utility;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
{
/// <summary>
/// Restore request parameters
/// </summary>
public class RestoreParams : GeneralRequestDetails
{
/// <summary>
/// Restore session id. The parameter is optional and if passed, an existing plan will be used
/// </summary>
internal string SessionId
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.SessionId);
}
set
{
SetOptionValue(RestoreOptionsHelper.SessionId, value);
}
}
/// <summary>
/// The Uri to find the connection to do the restore operations
/// </summary>
public string OwnerUri { get; set; }
/// <summary>
/// Comma delimited list of backup files
/// </summary>
internal string BackupFilePaths
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.BackupFilePaths);
}
set
{
SetOptionValue(RestoreOptionsHelper.BackupFilePaths, value);
}
}
/// <summary>
/// Target Database name to restore to
/// </summary>
internal string TargetDatabaseName
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.TargetDatabaseName);
}
set
{
SetOptionValue(RestoreOptionsHelper.TargetDatabaseName, value);
}
}
/// <summary>
/// Source Database name to restore from
/// </summary>
internal string SourceDatabaseName
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.SourceDatabaseName);
}
set
{
SetOptionValue(RestoreOptionsHelper.SourceDatabaseName, value);
}
}
/// <summary>
/// If set to true, the db files will be relocated to default data location in the server
/// </summary>
internal bool RelocateDbFiles
{
get
{
return GetOptionValue<bool>(RestoreOptionsHelper.RelocateDbFiles);
}
set
{
SetOptionValue(RestoreOptionsHelper.RelocateDbFiles, value);
}
}
/// <summary>
/// Ids of the backup set to restore
/// </summary>
internal string[] SelectedBackupSets
{
get
{
return GetOptionValue<string[]>(RestoreOptionsHelper.SelectedBackupSets);
}
set
{
SetOptionValue(RestoreOptionsHelper.SelectedBackupSets, value);
}
}
}
/// <summary>
/// Restore response
/// </summary>
@@ -132,78 +29,7 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
public string ErrorMessage { get; set; }
}
/// <summary>
/// Database file info
/// </summary>
public class RestoreDatabaseFileInfo
{
/// <summary>
/// File type (Rows Data, Log ...)
/// </summary>
public string FileType { get; set; }
/// <summary>
/// Logical Name
/// </summary>
public string LogicalFileName { get; set; }
/// <summary>
/// Original location of the file to restore to
/// </summary>
public string OriginalFileName { get; set; }
/// <summary>
/// The file to restore to
/// </summary>
public string RestoreAsFileName { get; set; }
}
/// <summary>
/// Restore Plan Response
/// </summary>
public class RestorePlanResponse
{
/// <summary>
/// Restore session id, can be used in restore request to use an existing restore plan
/// </summary>
public string SessionId { get; set; }
/// <summary>
/// The list of backup sets to restore
/// </summary>
public DatabaseFileInfo[] BackupSetsToRestore { get; set; }
/// <summary>
/// Indicates whether the restore operation is supported
/// </summary>
public bool CanRestore { get; set; }
/// <summary>
/// Errors occurred while creating restore plan
/// </summary>
public string ErrorMessage { get; set; }
/// <summary>
/// The db files included in the backup file
/// </summary>
public IEnumerable<RestoreDatabaseFileInfo> DbFiles { get; set; }
/// <summary>
/// Database names extracted from backup sets
/// </summary>
public string[] DatabaseNamesFromBackupSets { get; set; }
/// <summary>
/// For testing purpose to verify the target database
/// </summary>
internal string DatabaseName { get; set; }
/// <summary>
/// Plan details
/// </summary>
public Dictionary<string, object> PlanDetails { get; set; }
}
public class RestoreRequest
{
@@ -212,10 +38,5 @@ namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
RequestType<RestoreParams, RestoreResponse>.Create("disasterrecovery/restore");
}
public class RestorePlanRequest
{
public static readonly
RequestType<RestoreParams, RestorePlanResponse> Type =
RequestType<RestoreParams, RestorePlanResponse>.Create("disasterrecovery/restoreplan");
}
}

View File

@@ -0,0 +1,145 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System.Collections.Generic;
using Microsoft.SqlTools.ServiceLayer.Utility;
using Newtonsoft.Json.Linq;
namespace Microsoft.SqlTools.ServiceLayer.DisasterRecovery.Contracts
{
/// <summary>
/// Restore request parameters
/// </summary>
public class RestoreParams : GeneralRequestDetails
{
/// <summary>
/// Restore session id. The parameter is optional and if passed, an existing plan will be used
/// </summary>
internal string SessionId
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.SessionId);
}
set
{
SetOptionValue(RestoreOptionsHelper.SessionId, value);
}
}
/// <summary>
/// The Uri to find the connection to do the restore operations
/// </summary>
public string OwnerUri { get; set; }
/// <summary>
/// Comma delimited list of backup files
/// </summary>
internal string BackupFilePaths
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.BackupFilePaths);
}
set
{
SetOptionValue(RestoreOptionsHelper.BackupFilePaths, value);
}
}
/// <summary>
/// Target Database name to restore to
/// </summary>
internal string TargetDatabaseName
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.TargetDatabaseName);
}
set
{
SetOptionValue(RestoreOptionsHelper.TargetDatabaseName, value);
}
}
/// <summary>
/// Source Database name to restore from
/// </summary>
internal string SourceDatabaseName
{
get
{
return GetOptionValue<string>(RestoreOptionsHelper.SourceDatabaseName);
}
set
{
SetOptionValue(RestoreOptionsHelper.SourceDatabaseName, value);
}
}
/// <summary>
/// If set to true, the db files will be relocated to default data location in the server
/// </summary>
internal bool RelocateDbFiles
{
get
{
return GetOptionValue<bool>(RestoreOptionsHelper.RelocateDbFiles);
}
set
{
SetOptionValue(RestoreOptionsHelper.RelocateDbFiles, value);
}
}
/// <summary>
/// If set to true, the backup files will be used to create restore plan otehrwise the source database name will be used
/// </summary>
internal bool ReadHeaderFromMedia
{
get
{
//Default is true for now for backward compatibility
return Options.ContainsKey(RestoreOptionsHelper.ReadHeaderFromMedia) ? GetOptionValue<bool>(RestoreOptionsHelper.ReadHeaderFromMedia) : true;
}
set
{
SetOptionValue(RestoreOptionsHelper.ReadHeaderFromMedia, value);
}
}
/// <summary>
/// Ids of the selected backup set to restore. If null, all backup sets will be selected. If empty list,
/// no backup sets will be selected
/// </summary>
internal IEnumerable<string> SelectedBackupSets
{
get
{
var selectedBackupSets = GetOptionValue<object>(RestoreOptionsHelper.SelectedBackupSets);
if (selectedBackupSets != null)
{
JArray array = selectedBackupSets as JArray;
if(array != null)
{
return array.ToObject<IEnumerable<string>>();
}
else
{
IEnumerable<string> list = selectedBackupSets as IEnumerable<string>;
return list;
}
}
return null;
}
set
{
SetOptionValue(RestoreOptionsHelper.SelectedBackupSets, value);
}
}
}
}