public async Task BackupAndRestore() { var source = new CancellationTokenSource(TimeSpan.FromMinutes(2)); UriBuilder builder = new UriBuilder(TestEnvironment.StorageUri); builder.Path = BlobContainerName; // Start the backup. BackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, "?" + SasToken, source.Token); // Wait for completion of the LRO. BackupResult backupResult = await backupOperation.WaitForCompletionAsync(source.Token); await WaitForOperationAsync(); Assert.That(source.IsCancellationRequested, Is.False); Assert.That(backupResult, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); // Start the restore. RestoreOperation restoreOperation = await Client.StartRestoreAsync(backupResult.FolderUri, "?" + SasToken, source.Token); // Wait for completion of the LRO var restoreResult = await restoreOperation.WaitForCompletionAsync(source.Token); await WaitForOperationAsync(); Assert.That(source.IsCancellationRequested, Is.False); Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); }
public async Task ResumeBackupRestore() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; // var client = Mode == RecordedTestMode.Playback ? GetClient(null, false) : Client; var client = GetClient(false); // Create a Uri with the storage container UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation originalBackupOperation = await Client.StartBackupAsync(builder.Uri, sasToken); var backupOperationId = originalBackupOperation.Id; #region Snippet:ResumeBackupAsync // Construct a new KeyVaultBackupClient or use an existing one. //@@KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential()); // Construct a BackupOperation using a KeyVaultBackupClient and the Id from a previously started operation. BackupOperation backupOperation = new BackupOperation(client, backupOperationId); // Wait for completion of the BackupOperation. Response <Uri> backupResult = await backupOperation.WaitForCompletionAsync(); // Get the Uri for the location of you backup blob. Uri backupBlobUri = backupResult.Value; #endregion Assert.That(backupBlobUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); // Get the folder name from the backupBlobUri returned from a previous BackupOperation string[] uriSegments = backupBlobUri.Segments; string folderName = uriSegments[uriSegments.Length - 1]; // Start the restore. RestoreOperation originalRestoreOperation = await Client.StartRestoreAsync(builder.Uri, sasToken, folderName); var restoreOperationId = originalRestoreOperation.Id; #region Snippet:ResumeRestoreAsync // Construct a new KeyVaultBackupClient or use an existing one. //@@KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential()); // Construct a RestoreOperation using a KeyVaultBackupClient and the Id from a previously started operation. RestoreOperation restoreOperation = new RestoreOperation(client, restoreOperationId); // Wait for completion of the RestoreOperation. Response restoreResult = await restoreOperation.WaitForCompletionAsync(); #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); }
private Commands.GuiReportPlanStatus BuildGuiReportPlanStatus(Commands.OperationStatus status) { Commands.GuiReportPlanStatus data = null; if (RunningOperation is BackupOperation) { BackupOperation op = RunningOperation as BackupOperation; Models.BackupPlan plan = Model as Models.BackupPlan; data = new Commands.GuiReportPlanStatus { Status = status, StartedAt = op.StartedAt, FinishedAt = op.FinishedAt, LastRunAt = plan.LastRunAt, LastSuccessfulRunAt = plan.LastSuccessfulRunAt, //Sources = op.Sources, }; // Sources if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED || status == Commands.OperationStatus.FINISHED || status == Commands.OperationStatus.FAILED || status == Commands.OperationStatus.CANCELED) { data.Sources = op.Sources; } } else if (RunningOperation is RestoreOperation) { RestoreOperation op = RunningOperation as RestoreOperation; Models.RestorePlan plan = Model as Models.RestorePlan; data = new Commands.GuiReportPlanStatus { Status = status, StartedAt = op.StartedAt, FinishedAt = op.FinishedAt, LastRunAt = plan.LastRunAt, LastSuccessfulRunAt = plan.LastSuccessfulRunAt, //Sources = op.Sources, }; // Sources if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED || status == Commands.OperationStatus.FINISHED || status == Commands.OperationStatus.FAILED || status == Commands.OperationStatus.CANCELED) { data.Sources = op.Sources; } } else { string message = string.Format("Type {0} is not handled", RunningOperation.GetType().FullName); throw new NotImplementedException(message); } return(data); }
public async Task ResumeBackupRestore() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; var client = GetClient(false); // Create a Uri with the storage container UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation originalBackupOperation = await Client.StartBackupAsync(builder.Uri, sasToken); var backupOperationId = originalBackupOperation.Id; #region Snippet:ResumeBackupAsync // Construct a new KeyVaultBackupClient or use an existing one. //@@KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential()); // Construct a BackupOperation using a KeyVaultBackupClient and the Id from a previously started operation. BackupOperation backupOperation = new BackupOperation(client, backupOperationId); /*@@*/ backupOperation._retryAfterSeconds = (int)PollingInterval.TotalSeconds; // Wait for completion of the BackupOperation. Response <BackupResult> backupResult = await backupOperation.WaitForCompletionAsync(); // Get the Uri for the location of you backup blob. Uri folderUri = backupResult.Value.FolderUri; #endregion Assert.That(folderUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); await WaitForOperationAsync(); // Start the restore using the backupBlobUri returned from a previous BackupOperation. RestoreOperation originalRestoreOperation = await Client.StartRestoreAsync(folderUri, sasToken); var restoreOperationId = originalRestoreOperation.Id; #region Snippet:ResumeRestoreAsync // Construct a new KeyVaultBackupClient or use an existing one. //@@KeyVaultBackupClient Client = new KeyVaultBackupClient(new Uri(keyVaultUrl), new DefaultAzureCredential()); // Construct a RestoreOperation using a KeyVaultBackupClient and the Id from a previously started operation. RestoreOperation restoreOperation = new RestoreOperation(client, restoreOperationId); /*@@*/ restoreOperation._operationInternal._retryAfterSeconds = (int)PollingInterval.TotalSeconds; // Wait for completion of the RestoreOperation. RestoreResult restoreResult = await restoreOperation.WaitForCompletionAsync(); #endregion Assert.That(restoreOperation.HasValue, Is.True); Assert.That(restoreResult.StartTime, Is.Not.EqualTo(default));
public void Initialize() { autoRestoreMechanism = new Mock<IAutoRestoreMechanism>(); backup = new Mock<IFeatureConfigurationBackup>(); logger = new Mock<ILogger>(); sessionContext = new SessionContext { AutoRestoreMechanism = autoRestoreMechanism.Object }; sut = new RestoreOperation(backup.Object, logger.Object, sessionContext); }
public async Task BackupAndRestoreSampleSync() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; #region Snippet:HelloFullBackupSync // Create a Uri with the storage container UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation backupOperation = Client.StartBackup(builder.Uri, sasToken); // Wait for completion of the BackupOperation. while (!backupOperation.HasCompleted) { backupOperation.UpdateStatus(); /*@@*/ await DelayAsync(TimeSpan.FromSeconds(3)); //@@Thread.Sleep(3000); } // Get the Uri for the location of you backup blob. Uri backupFolderUri = backupOperation.Value; #endregion Assert.That(backupFolderUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); await WaitForOperationAsync(); #region Snippet:HelloFullRestoreSync // Start the restore using the backupBlobUri returned from a previous BackupOperation. RestoreOperation restoreOperation = Client.StartRestore(backupFolderUri, sasToken); // Wait for completion of the RestoreOperation. while (!restoreOperation.HasCompleted) { restoreOperation.UpdateStatus(); /*@@*/ await DelayAsync(TimeSpan.FromSeconds(3)); //@@Thread.Sleep(3000); } Uri restoreResult = backupOperation.Value; #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); await WaitForOperationAsync(); }
public void UpdateStatusThrowsOnError() { // setup the GetRestoreDetailsAsync to return a failed response var mockClient = new Mock <KeyVaultBackupClient>(); mockClient .Setup(m => m.GetRestoreDetailsAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())) .ReturnsAsync(failedResponse.Object); var operation = new RestoreOperation(mockClient.Object, JobId); Assert.ThrowsAsync <RequestFailedException>(async() => await operation.UpdateStatusAsync(default));
public void BackupAndRestoreSampleSync() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; #region Snippet:HelloFullBackupSync // Create a Uri with the storage container UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation backupOperation = Client.StartBackup(builder.Uri, sasToken); // Wait for completion of the BackupOperation. while (!backupOperation.HasCompleted) { backupOperation.UpdateStatus(); Thread.Sleep(3000); } // Get the Uri for the location of you backup blob. Uri backupBlobUri = backupOperation.Value; #endregion Assert.That(backupBlobUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); #region Snippet:HelloFullRestoreSync // Get the folder name from the backupBlobUri returned from a previous BackupOperation string[] uriSegments = backupBlobUri.Segments; string folderName = uriSegments[uriSegments.Length - 1]; // Start the restore. RestoreOperation restoreOperation = Client.StartRestore(builder.Uri, sasToken, folderName); // Wait for completion of the RestoreOperation. while (!restoreOperation.HasCompleted) { restoreOperation.UpdateStatus(); Thread.Sleep(3000); } Uri restoreResult = backupOperation.Value; #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); }
public async Task BackupAndRestoreSampleAsync() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; // Create a Uri with the storage container. UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Make sure we have a key to back up and restore. KeyVaultKey key = await KeyClient.CreateKeyAsync(Recording.GenerateId(), KeyType.Oct); string keyName = key.Name; RegisterKeyForCleanup(keyName); // Start the backup. BackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, sasToken); // Wait for completion of the BackupOperation. Response <Uri> backupResult = await backupOperation.WaitForCompletionAsync(); await WaitForOperationAsync(); // Get the Uri for the location of you backup blob. Uri backupFolderUri = backupResult.Value; Assert.That(backupFolderUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); #region Snippet:SelectiveRestoreAsync //@@ string keyName = "<key name to restore>"; // Start the restore for a specific key that was previously backed up using the backupBlobUri returned from a previous BackupOperation. RestoreOperation restoreOperation = await Client.StartSelectiveRestoreAsync(keyName, backupFolderUri, sasToken); // Wait for completion of the RestoreOperation. Response restoreResult = await restoreOperation.WaitForCompletionAsync(); #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); await WaitForOperationAsync(); }
public async Task BackupAndRestoreSampleAsync() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; // Create a Uri with the storage container. UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, sasToken); // Wait for completion of the BackupOperation. Response <Uri> backupResult = await backupOperation.WaitForCompletionAsync(); // Get the Uri for the location of you backup blob. Uri backupBlobUri = backupResult.Value; Assert.That(backupBlobUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); string keyName = PreviouslyBackedUpKeyName; #region Snippet:SelectiveRestoreAsync // Get the folder name from the backupBlobUri returned from a previous BackupOperation. string[] uriSegments = backupBlobUri.Segments; string folderName = uriSegments[uriSegments.Length - 1]; //@@ string keyName = <key name to restore>; // Start the restore for a specific key that was previously backed up. RestoreOperation restoreOperation = await Client.StartSelectiveRestoreAsync(keyName, builder.Uri, sasToken, folderName); // Wait for completion of the RestoreOperation. Response restoreResult = await restoreOperation.WaitForCompletionAsync(); #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); }
public async Task BackupAndRestoreSampleAsync() { var blobStorageUrl = TestEnvironment.StorageUri; var blobContainerName = BlobContainerName; var sasToken = "?" + SasToken; #region Snippet:HelloFullBackupAsync // Create a Uri with the storage container UriBuilder builder = new UriBuilder(blobStorageUrl) { Path = blobContainerName, }; // Start the backup. BackupOperation backupOperation = await Client.StartBackupAsync(builder.Uri, sasToken); // Wait for completion of the BackupOperation. Response <Uri> backupResult = await backupOperation.WaitForCompletionAsync(); // Get the Uri for the location of you backup blob. Uri backupFolderUri = backupResult.Value; #endregion Assert.That(backupFolderUri, Is.Not.Null); Assert.That(backupOperation.HasValue, Is.True); await WaitForOperationAsync(); #region Snippet:HelloFullRestoreAsync // Start the restore using the backupBlobUri returned from a previous BackupOperation. RestoreOperation restoreOperation = await Client.StartRestoreAsync(backupFolderUri, sasToken); // Wait for completion of the RestoreOperation. Response restoreResult = await restoreOperation.WaitForCompletionAsync(); #endregion Assert.That(restoreResult, Is.Not.Null); Assert.That(restoreOperation.HasValue, Is.True); await WaitForOperationAsync(); }
private void RestoreUpdateStatsInfo(RestoreOperationStatus status, TransferStatus xferStatus) { if (RunningOperation == null) { return; } Models.RestorePlan plan = Model as Models.RestorePlan; RestoreOperation operation = RunningOperation as RestoreOperation; RestoreOperationReport report = operation.Report; switch (status) { default: throw new ArgumentException("Unhandled status", "status"); case RestoreOperationStatus.Unknown: { break; } case RestoreOperationStatus.Started: case RestoreOperationStatus.Resumed: { logger.Info("{0} restore", status == RestoreOperationStatus.Resumed ? "Resuming" : "Starting"); // Update timestamps. plan.LastRunAt = DateTime.UtcNow; _daoRestorePlan.Update(plan); // Report Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Started ? Commands.OperationStatus.STARTED : Commands.OperationStatus.RESUMED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case RestoreOperationStatus.ScanningFilesStarted: { logger.Info("Scanning files..."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.SCANNING_FILES_STARTED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case RestoreOperationStatus.ScanningFilesFinished: { logger.Info("Scanning files finished."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.SCANNING_FILES_FINISHED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case RestoreOperationStatus.ProcessingFilesStarted: { logger.Info("Processing files..."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.PROCESSING_FILES_STARTED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); Handler.Send(Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData)); break; } case RestoreOperationStatus.ProcessingFilesFinished: { logger.Info("Processing files finished."); logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.PROCESSING_FILES_FINISHED; // Report sources Commands.GuiReportPlanStatus cmdData1 = BuildGuiReportPlanStatus(cmdStatus); string cmd1 = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData1); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd1); // Report counts Commands.GuiReportPlanProgress cmdData2 = BuildGuiReportPlanProgress(cmdStatus); string cmd2 = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData2); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd2); break; } case RestoreOperationStatus.Finished: { //var message = string.Format( // "Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running", // "finished", // TransferResults.Stats.Completed, TransferResults.Stats.Failed, // TransferResults.Stats.Canceled, TransferResults.Stats.Pending, // TransferResults.Stats.Running); //logger.Info(message); // Update success timestamp. plan.LastSuccessfulRunAt = DateTime.UtcNow; _daoRestorePlan.Update(plan); // Signal to the other thread it may terminate. RunningOperationEndedEvent.Set(); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.FINISHED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case RestoreOperationStatus.Updated: { if (xferStatus == TransferStatus.COMPLETED || xferStatus == TransferStatus.CANCELED || xferStatus == TransferStatus.FAILED) { logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total); } // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.UPDATED; Commands.GuiReportPlanProgress cmdData = BuildGuiReportPlanProgress(cmdStatus); string cmd = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case RestoreOperationStatus.Failed: case RestoreOperationStatus.Canceled: { //var message = string.Format( // "Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running", // status == RestoreOperationStatus.Failed ? "failed" : "was canceled", // TransferResults.Stats.Completed, TransferResults.Stats.Failed, // TransferResults.Stats.Canceled, TransferResults.Stats.Pending, // TransferResults.Stats.Running); //logger.Info(message); // Signal to the other thread it may terminate. RunningOperationEndedEvent.Set(); // Report Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Failed ? Commands.OperationStatus.FAILED : Commands.OperationStatus.CANCELED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } } }
private static void ForceLoadingRavenDbAssemblies() { // Just make sure that the Raven.Storage.Managed assembly is loaded var restoreOperation = new RestoreOperation(string.Empty, string.Empty); }
private static void ForceLoadingAssembliesForMsTestRunner() { // Just to make sure the Raven.Storage.Managed assembly is loaded for Microsft Unit Test Runner RestoreOperation restoreOperation = new RestoreOperation("", ""); }