/// <summary> /// Handles a restore config info request /// </summary> internal async Task HandleRestoreConfigInfoRequest( RestoreConfigInfoRequestParams restoreConfigInfoParams, RequestContext <RestoreConfigInfoResponse> requestContext) { RestoreConfigInfoResponse response = new RestoreConfigInfoResponse(); try { ConnectionInfo connInfo; bool supported = IsBackupRestoreOperationSupported(restoreConfigInfoParams.OwnerUri, out connInfo); if (supported && connInfo != null) { response = this.restoreDatabaseService.CreateConfigInfoResponse(restoreConfigInfoParams); } else { response.ErrorMessage = SR.RestoreNotSupported; } await requestContext.SendResult(response); } catch (Exception ex) { response.ErrorMessage = ex.Message; await requestContext.SendResult(response); } }
/// <summary> /// Creates response which includes information about the server given to restore (default data location, db names with backupsets) /// </summary> public RestoreConfigInfoResponse CreateConfigInfoResponse(RestoreConfigInfoRequestParams restoreConfigInfoRequest) { RestoreConfigInfoResponse response = new RestoreConfigInfoResponse(); RestoreDatabaseTaskDataObject restoreTaskObject = null; try { restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri); if (restoreTaskObject != null) { // Default Data folder path in the target server response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder); // Default log folder path in the target server 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); } } catch (Exception ex) { Logger.Write(LogLevel.Warning, $"Failed to create restore config info. error: { ex.Message}"); response.ErrorMessage = ex.Message; } finally { ServerConnection serverConnection = restoreTaskObject?.Server?.ConnectionContext; if (serverConnection != null && serverConnection.IsOpen) { restoreTaskObject.Server.ConnectionContext.Disconnect(); } } return(response); }
/// <summary> /// Creates response which includes information about the server given to restore (default data location, db names with backupsets) /// </summary> public RestoreConfigInfoResponse CreateConfigInfoResponse(RestoreConfigInfoRequestParams restoreConfigInfoRequest) { RestoreConfigInfoResponse response = new RestoreConfigInfoResponse(); RestoreDatabaseTaskDataObject restoreTaskObject = CreateRestoreForNewSession(restoreConfigInfoRequest.OwnerUri); if (restoreTaskObject != null) { // Default Data folder path in the target server response.ConfigInfo.Add(RestoreOptionsHelper.DataFileFolder, restoreTaskObject.DefaultDataFileFolder); // Default log folder path in the target server response.ConfigInfo.Add(RestoreOptionsHelper.LogFileFolder, restoreTaskObject.DefaultLogFileFolder); // The db names with backup set response.ConfigInfo.Add(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets, restoreTaskObject.GetDatabaseNamesWithBackupSets()); } return(response); }
public async Task RestoreConfigInfoRequestShouldReturnResponse() { await VerifyBackupFileCreated(); using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) { TestConnectionResult connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath); string filePath = GetBackupFilePath(fullBackupFilePath); RestoreConfigInfoRequestParams restoreParams = new RestoreConfigInfoRequestParams { OwnerUri = queryTempFile.FilePath }; await RunAndVerify <RestoreConfigInfoResponse>( test : (requestContext) => service.HandleRestoreConfigInfoRequest(restoreParams, requestContext), verify : ((result) => { Assert.True(result.ConfigInfo.Any()); Assert.True(result.ConfigInfo.ContainsKey(RestoreOptionsHelper.SourceDatabaseNamesWithBackupSets)); })); } }