Blob 版本控制Blob versioning

可以启用 Blob 存储版本控制来自动维护对象的先前版本。You can enable Blob storage versioning to automatically maintain previous versions of an object. 启用 blob 版本控制后,如果错误地修改或删除了数据,则可以还原 blob 的先前版本以恢复数据。When blob versioning is enabled, you can restore an earlier version of a blob to recover your data if it is erroneously modified or deleted.

Blob 版本控制已在存储帐户上启用,并且适用于存储帐户中的所有 blob。Blob versioning is enabled on the storage account and applies to all blobs in the storage account. 为存储帐户启用 blob 版本控制后,Azure 存储将自动维护存储帐户中每个 blob 的版本。After you enable blob versioning for a storage account, Azure Storage automatically maintains versions for every blob in the storage account.

Azure 建议使用 blob 版本控制来维护 blob 的先前版本,以实现高级数据保护。Azure recommends using blob versioning to maintain previous versions of a blob for superior data protection. 如果可能,请使用 blob 版本控制而不是 blob 快照来维护先前版本。When possible, use blob versioning instead of blob snapshots to maintain previous versions. Blob 快照提供类似的功能,因为它们可以维护 blob 的早期版本,但快照必须通过应用程序手动维护。Blob snapshots provide similar functionality in that they maintain earlier versions of a blob, but snapshots must be maintained manually by your application.

若要了解如何启用 blob 版本控制,请参阅启用和管理 blob 版本控制To learn how to enable blob versioning, see Enable and manage blob versioning.

重要

Blob 版本控制无法帮助你恢复意外删除的存储帐户或容器。Blob versioning cannot help you to recover from the accidental deletion of a storage account or container. 若要防止意外删除存储帐户,请在存储帐户资源上配置一个锁定。To prevent accidental deletion of the storage account, configure a lock on the storage account resource. 若要详细了解如何锁定 Azure 资源,请参阅锁定资源以防止意外更改For more information on locking Azure resources, see Lock resources to prevent unexpected changes.

备注

具有分层命名空间 (Azure Data Lake Storage Gen2) 的帐户尚不支持此功能。This feature is not yet supported in accounts that have a hierarchical namespace (Azure Data Lake Storage Gen2). 若要了解详细信息,请参阅 Azure Data Lake Storage Gen2 中可用的 Blob 存储功能To learn more, see Blob storage features available in Azure Data Lake Storage Gen2.

Blob 版本控制的工作原理How blob versioning works

版本在给定时间点捕获 blob 的状态。A version captures the state of a blob at a given point in time. 为存储帐户启用 blob 版本控制后,每次修改或删除 blob 时,Azure 存储都会自动创建 blob 的新版本。When blob versioning is enabled for a storage account, Azure Storage automatically creates a new version of a blob each time that blob is modified or deleted.

创建启用了版本控制的 blob 时,新 blob 是 blob(或基本 blob)的当前版本。When you create a blob with versioning enabled, the new blob is the current version of the blob (or the base blob). 如果随后修改了该 blob,则 Azure 存储将创建一个版本,用于捕获 blob 在修改之前的状态。If you subsequently modify that blob, Azure Storage creates a version that captures the state of the blob before it was modified. 修改后的 blob 将成为新的当前版本。The modified blob becomes the new current version. 每次修改 blob 时都会创建一个新版本。A new version is created each time you modify the blob.

下图显示了如何在写入和删除操作中创建版本,以及如何将先前版本提升为当前版本:The following diagram shows how versions are created on write and delete operations, and how a previous version may be promoted to be the current version:

显示 blob 版本控制工作原理的示意图

如果每个 blob 都具有大量版本,则会增加 blob 列表操作的延迟。Having a large number of versions per blob can increase the latency for blob listing operations. Azure 建议每个 blob 保留的版本少于 1000 个。Azure recommends maintaining fewer than 1000 versions per blob. 可以使用生命周期管理来自动删除旧版本。You can use lifecycle management to automatically delete old versions. 有关生命周期管理的详细信息,请参阅通过自动执行 Azure Blob 存储访问层来优化成本For more information about lifecycle management, see Optimize costs by automating Azure Blob Storage access tiers.

删除启用了版本控制的 blob 时,Azure 存储将创建一个新版本,用于捕获 blob 在删除之前的状态。When you delete a blob with versioning enabled, Azure Storage creates a version that captures the state of the blob before it was deleted. 然后,将删除 blob 的当前版本,但 blob 的该版本仍然存在,以便可以在需要时重新创建。The current version of the blob is then deleted, but the blob's versions persist, so that it can be re-created if needed.

Blob 版本是不可变的。Blob versions are immutable. 不能修改现有 blob 版本的内容或元数据。You cannot modify the content or metadata of an existing blob version.

Blob 版本控制可用于常规用途 v2、块 blob 和 Blob 存储帐户。Blob versioning is available for general-purpose v2, block blob, and Blob storage accounts. 当前不支持启用了分层命名空间以与 Azure Data Lake Storage Gen2 一起使用的存储帐户。Storage accounts with a hierarchical namespace enabled for use with Azure Data Lake Storage Gen2 are not currently supported.

Azure 存储 REST API 2019-10-10 版及更高版本支持 blob 版本控制。Version 2019-10-10 and higher of the Azure Storage REST API supports blob versioning.

版本 IDVersion ID

每个 blob 版本都由一个版本 ID 标识。Each blob version is identified by a version ID. 版本 ID 的值是写入或更新 blob 时的时间戳。The value of the version ID is the timestamp at which the blob was written or updated. 创建版本时分配版本 ID。The version ID is assigned at the time that the version is created.

可以通过提供 blob 的特定版本 ID 来对其执行读取或删除操作。You can perform read or delete operations on a specific version of a blob by providing its version ID. 如果省略了版本 ID,则操作将针对当前版本(基本 blob)进行。If you omit the version ID, the operation acts against the current version (the base blob).

调用写入操作来创建或修改 blob 时,Azure 存储将在响应中返回 x-ms-version-id 标头。When you call a write operation to create or modify a blob, Azure Storage returns the x-ms-version-id header in the response. 此标头包含由写入操作创建的 blob 的当前版本的版本 ID。This header contains the version ID for the current version of the blob that was created by the write operation.

版本 ID 在版本的生存期内保持不变。The version ID remains the same for the lifetime of the version.

写入操作时的版本控制Versioning on write operations

启用 blob 版本控制后,对 blob 的每次写入操作都会创建一个新版本。When blob versioning is turned on, each write operation to a blob creates a new version. 写入操作包括放置 Blob放置块列表复制 Blob设置 Blob 元数据Write operations include Put Blob, Put Block List, Copy Blob, and Set Blob Metadata.

如果写入操作创建了新的 blob,则生成的 blob 为 blob 的当前版本。If the write operation creates a new blob, then the resulting blob is the current version of the blob. 如果写入操作修改了现有 blob,则会在更新后的 blob(即当前版本)中捕获新数据,Azure 存储将创建一个新版本来保存 blob 的先前状态。If the write operation modifies an existing blob, then the new data is captured in the updated blob, which is the current version, and Azure Storage creates a version that saves the blob's previous state.

为简单起见,本文中的示意图将版本 ID 显示为一个简单的整数值。For simplicity, the diagrams shown in this article display the version ID as a simple integer value. 实际上,版本 ID 是一个时间戳。In reality, the version ID is a timestamp. 当前版本显示为蓝色,先前版本显示为灰色。The current version is shown in blue, and previous versions are shown in gray.

下图显示了写入操作对 blob 版本的影响。The following diagram shows how write operations affect blob versions. 创建 blob 时,该 blob 为当前版本。When a blob is created, that blob is the current version. 修改相同的 blob 时,将创建一个新版本来保存该 blob 的先前状态,并且更新后的 blob 将成为当前版本。When the same blob is modified, a new version is created to save the blob's previous state, and the updated blob becomes the current version.

显示写入操作如何影响接受版本控制的 blob 的示意图。

备注

如果 blob 是在为存储帐户启用版本控制之前创建的,则它没有版本 ID。A blob that was created prior to versioning being enabled for the storage account does not have a version ID. 修改该 blob 时,修改后的 blob 将成为当前版本,并将创建一个版本来保存 blob 在更新前的状态。When that blob is modified, the modified blob becomes the current version, and a version is created to save the blob's state before the update. 为版本分配的版本 ID 是其创建时间。The version is assigned a version ID that is its creation time.

删除操作时的版本控制Versioning on delete operations

删除某个 blob 时,该 blob 的当前版本将成为先前版本,并且会删除基本 blob。When you delete a blob, the current version of the blob becomes a previous version, and the base blob is deleted. 删除 blob 时,将保留该 blob 的所有现有先前版本。All existing previous versions of the blob are preserved when the blob is deleted.

如果在没有版本 ID 的情况下调用删除 Blob 操作,则会删除基本 blob。Calling the Delete Blob operation without a version ID deletes the base blob. 若要删除特定版本,请在删除操作中提供该版本的 ID。To delete a specific version, provide the ID for that version on the delete operation.

下图显示了删除操作对接受版本控制的 blob 的影响:The following diagram shows the effect of a delete operation on a versioned blob:

显示删除接受版本控制的 blob 的示意图。

将新数据写入 blob 时将创建 blob 的新版本。Writing new data to the blob creates a new version of the blob. 任何现有版本不受影响,如下图所示。Any existing versions are unaffected, as shown in the following diagram.

显示在删除后重新创建接受版本控制的 blob 的示意图。

Blob 类型Blob types

为存储帐户启用 blob 版本控制后,除放置块操作外,针对块 blob 的所有写入和删除操作都会触发创建新版本。When blob versioning is enabled for a storage account, all write and delete operations on block blobs trigger the creation of a new version, with the exception of the Put Block operation.

对于页 blob 和追加 blob,仅部分写入和删除操作会触发创建新版本。For page blobs and append blobs, only a subset of write and delete operations trigger the creation of a version. 这些操作包括:These operations include:

以下操作不会触发创建新版本。The following operations do not trigger the creation of a new version. 若要从这些操作捕获更改,请手动生成快照:To capture changes from those operations, take a manual snapshot:

Blob 的所有版本必须具有相同的 blob 类型。All versions of a blob must be of the same blob type. 如果 blob 具有先前版本,则除非先删除该 blob 及其所有版本,否则无法使用其他类型的 blob 覆盖此类型的 blob。If a blob has previous versions, you cannot overwrite a blob of one type with another type unless you first delete the blob and all its versions.

访问层级Access tiers

可以通过调用设置 Blob 层操作将块 blob 的任何版本(包括当前版本)移到不同的 blob 访问层。You can move any version of a block blob, including the current version, to a different blob access tier by calling the Set Blob Tier operation. 要利用较低的容量定价,可以将较早版本的 blob 移到冷访问层或存档访问层。You can take advantage of lower capacity pricing by moving older versions of a blob to the cool or archive tier. 有关详细信息,请参阅 Azure Blob 存储:热、冷和存档访问层For more information, see Azure Blob storage: hot, cool, and archive access tiers.

若要自动将块 blob 移到相应的层,请使用 blob 生命周期管理。To automate the process of moving block blobs to the appropriate tier, use blob life cycle management. 有关生命周期管理的详细信息,请参阅管理 Azure Blob 存储生命周期For more information on life cycle management, see Manage the Azure Blob storage life cycle.

启用或禁用 blob 版本控制Enable or disable blob versioning

若要了解如何启用或禁用 blob 版本控制,请参阅启用和管理 blob 版本控制To learn how to enable or disable blob versioning, see Enable and manage blob versioning.

禁用 blob 版本控制不会删除现有的 blob、版本或快照。Disabling blob versioning does not delete existing blobs, versions, or snapshots. 关闭 blob 版本控制后,任何现有版本在存储帐户中仍可访问。When you turn off blob versioning, any existing versions remain accessible in your storage account. 后续不会再创建新版本。No new versions are subsequently created.

如果在存储帐户上禁用版本控制后创建或修改了 blob,则将覆盖该 blob 并创建新版本。If a blob was created or modified after versioning was disabled on the storage account, then overwriting the blob creates a new version. 更新的 blob 不再是当前版本,并且没有版本 ID。The updated blob is no longer the current version and does not have a version ID. 对该 blob 的所有后续更新都将覆盖其数据,而不会保存先前的状态。All subsequent updates to the blob will overwrite its data without saving the previous state.

禁用版本控制后,可以使用版本 ID 读取或删除版本。You can read or delete versions using the version ID after versioning is disabled. 禁用版本控制后,还可以列出 blob 的版本。You can also list a blob's versions after versioning is disabled.

下图显示了禁用版本控制后,修改 blob 时如何创建未接受版本控制的 blob。The following diagram shows how modifying a blob after versioning is disabled creates a blob that is not versioned. 与 blob 关联的任何现有版本都将保持不变。Any existing versions associated with the blob persist.

显示禁用版本控制后修改的基本 blob 的示意图。

Blob 版本控制和软删除Blob versioning and soft delete

Blob 版本控制和 blob 软删除协同工作,为你提供最佳的数据保护。Blob versioning and blob soft delete work together to provide you with optimal data protection. 启用软删除后,需指定 Azure 存储应将软删除的 blob 保留多长时间。When you enable soft delete, you specify how long Azure Storage should retain a soft-deleted blob. 任何软删除的 blob 版本都将保留在系统中,并可在软删除保留期内撤消删除。Any soft-deleted blob version remains in the system and can be undeleted within the soft delete retention period. 有关 blob 软删除的详细信息,请参阅 Azure 存储 blob 的软删除For more information about blob soft delete, see Soft delete for Azure Storage blobs.

删除 blob 或版本Deleting a blob or version

软删除为删除 blob 版本提供额外的保护。Soft delete offers additional protection for deleting blob versions. 如果在存储帐户上同时启用了版本控制和软删除,则删除 blob 时,Azure 存储会创建一个新版本来保存 blob 在删除前的状态并删除当前版本。If both versioning and soft delete are enabled on the storage account, then when you delete a blob, Azure Storage creates a new version to save the state of the blob immediately prior to deletion and deletes the current version. 系统不会软删除新版本,并且不会在软删除保留期到期时删除该版本。The new version is not soft-deleted and is not removed when the soft-delete retention period expires.

删除 blob 的先前版本时,该版本将被软删除。When you delete a previous version of the blob, the version is soft-deleted. 软删除的版本在存储帐户的“软删除”设置中指定的保留期内将保留,在软删除保留期到期时将永久删除。The soft-deleted version is retained throughout the retention period specified in the soft delete settings for the storage account and is permanently deleted when the soft delete retention period expires.

若要删除 blob 的先前版本,请通过指定版本 ID 将其显式删除。To remove a previous version of a blob, explicitly delete it by specifying the version ID.

下图显示了在删除 blob 或 blob 版本时会发生的情况。The following diagram shows what happens when you delete a blob or a blob version.

显示删除已启用软删除的版本的示意图。

如果在存储帐户上同时启用了版本控制和软删除,则在修改或删除 blob 或 blob 版本时,不会创建软删除的快照。If both versioning and soft delete are enabled on a storage account, then no soft-deleted snapshot is created when a blob or blob version is modified or deleted.

还原软删除的版本Restoring a soft-deleted version

在软删除保留期生效期间,可以通过对版本调用撤销删除 Blob 操作来还原软删除的 blob 版本。You can restore a soft-deleted blob version by calling the Undelete Blob operation on the version while the soft delete retention period is in effect. “撤消删除 Blob”操作将还原 blob 的所有软删除的版本。The Undelete Blob operation restores all soft-deleted versions of the blob.

使用“撤消删除 Blob”操作还原软删除的版本不会将任何版本提升为当前版本。Restoring soft-deleted versions with the Undelete Blob operation does not promote any version to be the current version. 若要还原当前版本,请首先还原所有软删除的版本,然后使用复制 Blob 操作复制先前的版本以还原 blob。To restore the current version, first restore all soft-deleted versions, and then use the Copy Blob operation to copy a previous version to restore the blob.

下图显示了如何通过“撤销删除 Blob”操作还原软删除的 blob 版本,以及如何通过“复制 Blob”操作还原 blob 的当前版本 。The following diagram shows how to restore soft-deleted blob versions with the Undelete Blob operation, and how to restore the current version of the blob with the Copy Blob operation.

显示如何还原软删除的版本的示意图。

在软删除保留期结束之后,将永久删除任何软删除的 blob 版本。After the soft-delete retention period has elapsed, any soft-deleted blob versions are permanently deleted.

Blob 版本控制和 blob 快照Blob versioning and blob snapshots

Blob 快照是在某一特定时间点拍摄的 blob 的只读副本。A blob snapshot is a read-only copy of a blob that's taken at a specific point in time. Blob 快照和 blob 版本类似,但快照是由你或你的应用程序手动创建的,而 blob 版本是在为存储帐户启用 blob 版本控制后,在写入或删除操作中自动创建的。Blob snapshots and blob versions are similar, but a snapshot is created manually by you or your application, while a blob version is created automatically on a write or delete operation when blob versioning is enabled for your storage account.

重要

Azure 建议在启用 blob 版本控制后,还应更新应用程序以停止为块 blob 拍摄快照。Azure recommends that after you enable blob versioning, you also update your application to stop taking snapshots of block blobs. 如果存储帐户启用了版本控制,则将按版本捕获和保留所有块 blob 更新和删除。If versioning is enabled for your storage account, all block blob updates and deletions are captured and preserved by versions. 如果启用了 blob 版本控制,则拍摄快照不会向块 blob 数据提供任何额外的保护,并且可能会增加成本和应用程序复杂性。Taking snapshots does not offer any additional protections to your block blob data if blob versioning is enabled, and may increase costs and application complexity.

启用版本控制时为 blob 拍摄快照Snapshot a blob when versioning is enabled

尽管不建议这样做,但也可以为接受版本控制的 blob 拍摄快照。Although it is not recommended, you can take a snapshot of a blob that is also versioned. 如果在启用版本控制时无法更新应用程序以停止为 blob 拍摄快照,则应用程序可以同时支持快照和版本。If you cannot update your application to stop taking snapshots of blobs when you enable versioning, your application can support both snapshots and versions.

为接受版本控制的 blob 拍摄快照时,会在创建快照的同时创建一个新版本。When you take a snapshot of a versioned blob, a new version is created at the same time that the snapshot is created. 在拍摄快照时,还会创建一个新的当前版本。A new current version is also created when a snapshot is taken.

下图显示为接受版本控制的 blob 拍摄快照时会发生的情况。The following diagram shows what happens when you take a snapshot of a versioned blob. 在此示意图中,版本 ID 为 2 和 3 的 blob 版本和快照包含相同的数据。In the diagram, blob versions and snapshots with version ID 2 and 3 contain identical data.

显示接受版本控制的 blob 的快照的示意图。

授予对 blob 版本的操作权限Authorize operations on blob versions

可以使用以下方法之一来授予对 blob 版本的访问权限:You can authorize access to blob versions using one of the following approaches:

Blob 版本控制旨在保护数据免遭意外或恶意删除。Blob versioning is designed to protect your data from accidental or malicious deletion. 为了增强保护,删除 blob 版本时需要特殊权限。To enhance protection, deleting a blob version requires special permissions. 以下各节描述了删除 blob 版本所需的权限。The following sections describe the permissions needed to delete a blob version.

用于删除 blob 版本的 Azure RBAC 操作Azure RBAC action to delete a blob version

下表显示了支持删除 blob 或 blob 版本的 Azure RBAC 操作。The following table shows which Azure RBAC actions support deleting a blob or a blob version.

说明Description Blob 服务操作Blob service operation 需要 Azure RBAC 数据操作Azure RBAC data action required Azure 内置角色支持Azure built-in role support
删除 blob 的当前版本Deleting the current version of the blob 删除 BlobDelete Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/deleteMicrosoft.Storage/storageAccounts/blobServices/containers/blobs/delete 存储 Blob 数据参与者Storage Blob Data Contributor
删除版本Deleting a version 删除 BlobDelete Blob Microsoft.Storage/storageAccounts/blobServices/containers/blobs/deleteBlobVersion/actionMicrosoft.Storage/storageAccounts/blobServices/containers/blobs/deleteBlobVersion/action 存储 Blob 数据所有者Storage Blob Data Owner

共享访问签名 (SAS) 参数Shared access signature (SAS) parameters

Blob 版本的已签名资源为 bvThe signed resource for a blob version is bv. 有关详细信息,请参阅创建服务 SAS创建用户委托 SASFor more information, see Create a service SAS or Create a user delegation SAS.

下表显示了在 SAS 上删除 blob 版本时所需的权限。The following table shows the permission required on a SAS to delete a blob version.

权限Permission URI 符号URI symbol 允许的操作Allowed operations
删除Delete xx 删除 blob 版本。Delete a blob version.

定价和计费Pricing and billing

启用 blob 版本控制可能会导致帐户产生额外的数据存储费用。Enabling blob versioning can result in additional data storage charges to your account. 在设计应用程序时,有必要了解在哪些情况下会产生这些费用,以便最大程度地减少费用。When designing your application, it is important to be aware of how these charges might accrue so that you can minimize costs.

Blob 版本和 blob 快照一样,按与活动数据相同的费率计费。Blob versions, like blob snapshots, are billed at the same rate as active data. 如何对版本进行计费取决于是否已为基本 blob 或其任何版本(或快照)显式设置层级。How versions are billed depends on whether you have explicitly set the tier for the base blob or for any of its versions (or snapshots). 有关 blob 层的详细信息,请参阅 Azure Blob 存储:热、冷和存档访问层For more information about blob tiers, see Azure Blob storage: hot, cool, and archive access tiers.

如果尚未更改 blob 或版本的层级,则会针对该 blob、其版本及其拥有的任何快照中不重复的数据块进行计费。If you have not changed a blob or version's tier, then you are billed for unique blocks of data across that blob, its versions, and any snapshots it may have. 有关详细信息,请参阅在未显式设置 blob 层级时进行计费For more information, see Billing when the blob tier has not been explicitly set.

如果已更改 blob 或版本的层级,则会对整个对象进行计费,而不考虑 blob 和版本是否最终在同一层级中。If you have changed a blob or version's tier, then you are billed for the entire object, regardless of whether the blob and version are eventually in the same tier again. 有关详细信息,请参阅在显式设置了 blob 层级时进行计费For more information, see Billing when the blob tier has been explicitly set.

备注

为频繁覆盖的数据启用版本控制可能会增加存储容量费用,并增加列出操作期间的延迟。Enabling versioning for data that is frequently overwritten may result in increased storage capacity charges and increased latency during listing operations. 若要缓解这些问题,请将频繁覆盖的数据存储在禁用了版本控制的单独存储帐户中。To mitigate these concerns, store frequently overwritten data in a separate storage account with versioning disabled.

有关 blob 快照的计费详细信息,请参阅 Blob 快照For more information about billing details for blob snapshots, see Blob snapshots.

在未显式设置 blob 层级时进行计费Billing when the blob tier has not been explicitly set

如果没有为基本 blob 或其任何版本显式设置 blob 层级,则会针对该 blob、其版本及其拥有的任何快照中不重复的块或页面进行计费。If you have not explicitly set the blob tier for a base blob or any of its versions, then you are charged for unique blocks or pages across the blob, its versions, and any snapshots it may have. 对于跨 blob 及其版本共享的数据,只会收费一次。Data that is shared across a blob and its versions is charged only once. 当 blob 更新时,基本 blob 中的数据与其版本中存储的数据将会相异,并且会按块或页面对不重复的数据进行计费。When a blob is updated, then data in a base blob diverges from the data stored in its versions, and the unique data is charged per block or page.

在替换块 Blob 中的某个块后,会将该块作为唯一块进行收费。When you replace a block within a block blob, that block is subsequently charged as a unique block. 即使该块具有的块 ID 和数据与它在先前版本中所具有的 ID 和数据相同也是如此。This is true even if the block has the same block ID and the same data as it has in the previous version. 重新提交块后,它将与它在先前版本中的对应部分相异,并且你要为其数据付费。After the block is committed again, it diverges from its counterpart in the previous version, and you will be charged for its data. 对于使用相同数据更新的页 Blob 中的页面来说,情况也是如此。The same holds true for a page in a page blob that's updated with identical data.

Blob 存储无法确定两个块是否包含相同的数据。Blob storage does not have a means to determine whether two blocks contain identical data. 每个上传和提交的块均被视为唯一的块,即使它具有相同的数据和块 ID 也是如此。Each block that is uploaded and committed is treated as unique, even if it has the same data and the same block ID. 由于不重复的块会产生费用,因此请务必记住,在启用版本控制后更新 Blob 将导致产生更多不重复的块和额外费用。Because charges accrue for unique blocks, it's important to keep in mind that updating a blob when versioning is enabled will result in additional unique blocks and additional charges.

启用 blob 版本控制后,请对块 blob 调用更新操作,以使它们更新尽可能少的块。When blob versioning is enabled, call update operations on block blobs so that they update the least possible number of blocks. 允许对块进行精细控制的写入操作是放置块放置块列表The write operations that permit fine-grained control over blocks are Put Block and Put Block List. 另一方面,放置 Blob 操作会替换 blob 的全部内容,因此可能会导致额外的费用。The Put Blob operation, on the other hand, replaces the entire contents of a blob and so may lead to additional charges.

下列方案说明了未显式设置 blob 层级时块 Blob 及其版本将如何产生费用。The following scenarios demonstrate how charges accrue for a block blob and its versions when the blob tier has not been explicitly set.

方案 1Scenario 1

在方案 1 中,blob 具有先前版本。In scenario 1, the blob has a previous version. 自该版本创建以来,blob 尚未更新,因此仅针对不重复的块 1、2 和 3 产生费用。The blob has not been updated since the version was created, so charges are incurred only for unique blocks 1, 2, and 3.

图 1 显示了如何对基本 blob 和先前版本中不重复的块进行计费。

方案 2Scenario 2

在方案 2 中,blob 中的一个块(图中的块 3)已更新。In scenario 2, one block (block 3 in the diagram) in the blob has been updated. 即使更新的块包含相同的数据和 ID,它也与先前版本中的块 3 不同。Even though the updated block contains the same data and the same ID, it is not the same as block 3 in the previous version. 因此,帐户需要为四个块支付费用。As a result, the account is charged for four blocks.

图 2 显示了如何对基本 blob 和先前版本中不重复的块进行计费。

方案 3Scenario 3

在方案 3 中,已更新 blob,但未更新版本。In scenario 3, the blob has been updated, but the version has not. 块 3 已替换为基础 blob 中的块 4,但先前版本仍反映块 3。Block 3 was replaced with block 4 in the base blob, but the previous version still reflects block 3. 因此,帐户需要为四个块支付费用。As a result, the account is charged for four blocks.

图 3 显示了如何对基本 blob 和先前版本中不重复的块进行计费。

方案 4Scenario 4

在方案 4 中,已完全更新基本 Blob,并且其中不包含任何原始块。In scenario 4, the base blob has been completely updated and contains none of its original blocks. 因此,该帐户将为所有八个不重复的块 — 付费,其中四个在基本 blob 中,四个在先前版本中。As a result, the account is charged for all eight unique blocks — four in the base blob, and four in the previous version. 如果使用放置 Blob 操作写入 blob,则会发生这种情况,因为它会替换基本 blob 的全部内容。This scenario can occur if you are writing to a blob with the Put Blob operation, because it replaces the entire contents of the base blob.

图 4 显示了如何对基本 blob 和先前版本中不重复的块进行计费。

在显式设置了 blob 层级时进行计费Billing when the blob tier has been explicitly set

如果为 blob 或版本(或快照)显式设置了 blob 层级,则会针对新层级中对象的完整内容长度计费,而不考虑它是否与原始层级中的对象共享块。If you have explicitly set the blob tier for a blob or version (or snapshot), then you are charged for the full content length of the object in the new tier, regardless of whether it shares blocks with an object in the original tier. 你还需要为原始层级中最早版本的完整内容长度付费。You are also charged for the full content length of the oldest version in the original tier. 对于保留在原始层级中的任何其他先前版本或快照,都将针对其可能共享的不重复的块进行计费,如在未显式设置 blob 层级时进行计费中所述。Any other previous versions or snapshots that remain in the original tier are charged for unique blocks that they may share, as described in Billing when the blob tier has not been explicitly set.

将 blob 移到新层级Moving a blob to a new tier

下表描述了将 blob 或版本移动到新层级时的计费行为。The following table describes the billing behavior for a blob or version when it is moved to a new tier.

当针对以下项显式设置了 blob 层级时...When blob tier is set explicitly on… 你需要为以下项付费Then you are billed for...
具有先前版本的基本 blobA base blob with a previous version 新层级中的基本 blob 和原始层级中的最早版本,以及其他版本中的任何不重复的块。1The base blob in the new tier and the oldest version in the original tier, plus any unique blocks in other versions.1
具有先前版本和快照的基本 blobA base blob with a previous version and a snapshot 新层级中的基本 blob、原始层级中的最早版本、原始层级中的最早快照,以及其他版本或快照中的任何不重复的块1The base blob in the new tier, the oldest version in the original tier, and the oldest snapshot in the original tier, plus any unique blocks in other versions or snapshots1.
先前版本A previous version 新层级中的版本和原始层级中的基本 blob,以及其他版本中的任何不重复的块。1The version in the new tier and the base blob in the original tier, plus any unique blocks in other versions.1

1如果有其他先前版本或快照尚未从其原始层级中移出,则会根据这些版本或快照包含的不重复的块的数量对它们进行收费,如在未显式设置 blob 层级时进行计费中所述。1If there are other previous versions or snapshots that have not been moved from their original tier, those versions or snapshots are charged based on the number of unique blocks they contain, as described in Billing when the blob tier has not been explicitly set.

下图说明了当接受版本控制的 blob 移到另一个层级时,如何针对对象进行计费。The following diagram illustrates how objects are billed when a versioned blob is moved to a different tier.

此图显示了当对接受版本控制的 blob 显式分层时,如何针对对象进行计费。

为 blob、版本或快照显式设置层级不能撤消。Explicitly setting the tier for a blob, version, or snapshot cannot be undone. 如果你将 blob 移动到新层级,然后将其移回其原始层级,则即使该对象与原始层级中的其他对象共享块,也会针对该对象的完整内容长度向你收费。If you move a blob to a new tier and then move it back to its original tier, you are charged for the full content length of the object even if it shares blocks with other objects in the original tier.

显式设置 blob、版本或快照的层级的操作包括:Operations that explicitly set the tier of a blob, version, or snapshot include:

在启用了软删除的情况下删除 blobDeleting a blob when soft delete is enabled

当启用了 blob 软删除时,如果你删除或覆盖已显式设置其层级的基本 blob,则软删除的 blob 的任何先前版本都将按完整内容长度进行计费。When blob soft delete is enabled, if you delete or overwrite a base blob that has had its tier explicitly set, then any previous versions of the soft-deleted blob are billed at full content length. 有关如何结合使用 blob 版本控制和软删除的详细信息,请参阅 Blob 版本控制和软删除For more information about how blob versioning and soft delete work together, see Blob versioning and soft delete.

下表描述了软删除的 blob 的计费行为,具体取决于是启用还是禁用了版本控制。The following table describes the billing behavior for a blob that is soft-deleted, depending on whether versioning is enabled or disabled. 启用版本控制后,软删除 blob 时将创建一个新版本。When versioning is enabled, a version is created when a blob is soft-deleted. 禁用版本控制后,软删除 blob 时将创建软删除快照。When versioning is disabled, soft-deleting a blob creates a soft-delete snapshot.

当你覆盖已显式设置了其层级的基本 blob 时...When you overwrite a base blob with its tier explicitly set… 你需要为以下项付费Then you are billed for...
如果同时启用了 blob 软删除和版本控制If blob soft delete and versioning are both enabled 所有现有版本(按完整内容长度),不考虑层级。All existing versions at full content length regardless of tier.
如果启用了 blob 软删除但禁用了版本控制If blob soft delete is enabled but versioning is disabled 所有现有软删除快照(按完整内容长度),不考虑层级。All existing soft-delete snapshots at full content length regardless of tier.

另请参阅See also