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);
        }
Example #2
0
        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);
        }
Example #3
0
        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));
Example #4
0
        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();
        }