| title | Convert append and page blobs into block blobs (Azure Storage) |
|---|---|
| titleSuffix | Azure Storage |
| description | Learn how to convert an append blob or a page blob into a block blob in Azure Blob Storage. |
| author | normesta |
| ms.service | azure-blob-storage |
| ms.topic | how-to |
| ms.date | 01/20/2023 |
| ms.author | normesta |
| ms.reviewer | fryu |
| ms.devlang | powershell |
| ms.custom | devx-track-azurepowershell |
To convert blobs, copy them to a new location by using PowerShell, Azure CLI, or AzCopy. You'll use command parameters to ensure that the destination blob is a block blob. All metadata from the source blob is copied to the destination blob.
-
Open a Windows PowerShell command window.
-
Sign in to your Azure subscription with the Connect-AzAccount command and follow the on-screen directions.
Connect-AzAccount -
If your identity is associated with more than one subscription, then set your active subscription to subscription of the storage account which contains the append or page blobs.
$context = Get-AzSubscription -SubscriptionId '<subscription-id>' Set-AzContext $context
Replace the
<subscription-id>placeholder value with the ID of your subscription. -
Create the storage account context by using the New-AzStorageContext command. Include the
-UseConnectedAccountparameter so that data operations will be performed using your Microsoft Entra credentials.$ctx = New-AzStorageContext -StorageAccountName '<storage account name>' -UseConnectedAccount
-
Use the Copy-AzStorageBlob command and set the
-DestBlobTypeparameter toBlock.$containerName = '<source container name>' $srcblobName = '<source append or page blob name>' $destcontainerName = '<destination container name>' $destblobName = '<destination block blob name>' $destTier = '<destination block blob tier>' Copy-AzStorageBlob -SrcContainer $containerName -SrcBlob $srcblobName -Context $ctx -DestContainer $destcontainerName -DestBlob $destblobName -DestContext $ctx -DestBlobType Block -StandardBlobTier $destTier
-
To copy a page blob snapshot to block blob, use the Get-AzStorageBlob and Copy-AzStorageBlob command with
-DestBlobTypeparameter asBlock.$containerName = '<source container name>' $srcPageBlobName = '<source page blob name>' $srcPageBlobSnapshotTime = '<snapshot time of source page blob>' $destContainerName = '<destination container name>' $destBlobName = '<destination block blob name>' $destTier = '<destination block blob tier>' Get-AzStorageBlob -Container $containerName -Blob $srcPageBlobName -SnapshotTime $srcPageBlobSnapshotTime -Context $ctx | Copy-AzStorageBlob -DestContainer $destContainerName -DestBlob $destBlobName -DestBlobType block -StandardBlobTier $destTier -DestContext $ctx
[!TIP] The
-StandardBlobTierparameter is optional. If you omit that parameter, then the destination blob infers its tier from the default account access tier setting. To change the tier after you've created a block blob, see Change a blob's tier.
-
First, open the Azure Cloud Shell, or if you've installed the Azure CLI locally, open a command console application such as Windows PowerShell.
[!NOTE] If you're using a locally installed version of the Azure CLI, ensure that you are using version 2.44.0 or later.
-
If your identity is associated with more than one subscription, then set your active subscription to subscription of storage account which contains the append or page blobs.
az account set --subscription <subscription-id>Replace the
<subscription-id>placeholder value with the ID of your subscription. -
Use the az storage blob copy start command and set the
--destination-blob-typeparameter toblockBlob.containerName = '<source container name>' srcblobName = '<source append or page blob name>' destcontainerName = '<destination container name>' destBlobName = '<destination block blob name>' destTier = '<destination block blob tier>' az storage blob copy start --account-name $accountName --destination-blob $destBlobName --destination-container $destcontainerName --destination-blob-type BlockBlob --source-blob $srcblobName --source-container $containerName --tier $destTier -
To copy a page blob snapshot to block blob, use the az storage blob copy start command and set the
--destination-blob-typeparameter toblockBlobalong with source page blob snapshot uri.srcPageblobSnapshotUri = '<source page blob snapshot uri>' destcontainerName = '<destination container name>' destblobName = '<destination block blob name>' destTier = '<destination block blob tier>' az storage blob copy start --account-name $accountName --destination-blob $destBlobName --destination-container $destcontainerName --destination-blob-type BlockBlob --source-uri $srcPageblobSnapshotUri --tier $destTier[!TIP] The
--tierparameter is optional. If you omit that parameter, then the destination blob infers its tier from the default account access tier setting. To change the tier after you've created a block blob, see Change a blob's tier.[!WARNING] The optional
--metadataparameter overwrites any existing metadata. Therefore, if you specify metadata by using this parameter, then none of the original metadata from the source blob will be copied to the destination blob.
Use the azcopy copy command. Specify the source and destination paths. Set the blob-type parameter to BlockBlob.
azcopy copy 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<append-or-page-blob-name>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<name-of-new-block-blob>' --blob-type BlockBlob --block-blob-tier <destination-tier>
Tip
The --block-blob-tier parameter is optional. If you omit that parameter, then the destination blob infers its tier from the default account access tier setting. To change the tier after you've created a block blob, see Change a blob's tier.
Warning
The optional --metadata parameter overwrites any existing metadata. Therefore, if you specify metadata by using this parameter, then none of the original metadata from the source blob will be copied to the destination blob.