public async Task CreatePageBlob_ImmutableStorageWithVersioning() { // Arrange await using DisposingImmutableStorageWithVersioningContainer vlwContainer = await GetTestVersionLevelWormContainer(TestConfigOAuth); PageBlobClient pageBlob = InstrumentClient(vlwContainer.Container.GetPageBlobClient(GetNewBlobName())); BlobImmutabilityPolicy immutabilityPolicy = new BlobImmutabilityPolicy { ExpiresOn = Recording.UtcNow.AddMinutes(5), PolicyMode = BlobImmutabilityPolicyMode.Unlocked }; // The service rounds Immutability Policy Expiry to the nearest second. DateTimeOffset expectedImmutabilityPolicyExpiry = RoundToNearestSecond(immutabilityPolicy.ExpiresOn.Value); PageBlobCreateOptions options = new PageBlobCreateOptions { ImmutabilityPolicy = immutabilityPolicy, LegalHold = true }; // Act Response <BlobContentInfo> createResponse = await pageBlob.CreateAsync(size : Constants.KB, options); // Assert Response <BlobProperties> propertiesResponse = await pageBlob.GetPropertiesAsync(); Assert.AreEqual(expectedImmutabilityPolicyExpiry, propertiesResponse.Value.ImmutabilityPolicy.ExpiresOn); Assert.AreEqual(immutabilityPolicy.PolicyMode, propertiesResponse.Value.ImmutabilityPolicy.PolicyMode); Assert.IsTrue(propertiesResponse.Value.HasLegalHold); }
/// <summary> /// This method copies the first incremental snapshot as a base blob in the target region /// </summary> /// <param name="backupStorageAccountBlobClient">An instance of BlobClient which represents the storage account where the base blob is stored.</param> /// <param name="targetContainerName">The name of container in the target storage account where the base blob is stored</param> /// <param name="targetBaseBlobName">The name of the base blob used for storing the backups in the target storage account </param> /// <param name="sourceSnapshotSASUri">The SAS URI of the source snapshot</param> /// <returns></returns> private static async Task CopyFirstSnapshotToBackupStorageAccount(PageBlobClient targetBaseBlob, string sourceSnapshotSASUri) { PageBlobClient sourceSnapshot = new PageBlobClient(new Uri(sourceSnapshotSASUri)); //Get the size of the source snapshot var snapshotProperties = await sourceSnapshot.GetPropertiesAsync(); long sourceSnapshotSize = snapshotProperties.Value.ContentLength; //Create the target base blob with the same size as the source snapshot await targetBaseBlob.CreateAsync(sourceSnapshotSize); //Snapshots are stored as page blobs under the hood //Get all the valid page ranges from the source snapshot. //Learn more about page blobs and page ranges: //https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-pageblob-overview ///https://blogs.msdn.microsoft.com/windowsazurestorage/2012/03/26/getting-the-page-ranges-of-a-large-page-blob-in-segments/ ///https://docs.microsoft.com/en-us/rest/api/storageservices/get-page-ranges PageRangesInfo pageRanges = await sourceSnapshot.GetPageRangesAsync(); await WritePageRanges(sourceSnapshotSASUri, targetBaseBlob, pageRanges); await targetBaseBlob.CreateSnapshotAsync(); }