|
| 1 | +--- |
| 2 | +title: Convert append and page blobs into block blobs (Azure Storage) |
| 3 | +titleSuffix: Azure Storage |
| 4 | +description: Learn how to convert an append blob or a page blob into a block blob in Azure Blob Storage. |
| 5 | +author: normesta |
| 6 | + |
| 7 | +ms.service: storage |
| 8 | +ms.topic: how-to |
| 9 | +ms.date: 01/20/2023 |
| 10 | +ms.author: normesta |
| 11 | +ms.reviewer: fryu |
| 12 | +ms.subservice: blobs |
| 13 | +ms.devlang: powershell, azurecli |
| 14 | +ms.custom: devx-track-azurepowershell, devx-track-azurecli |
| 15 | +--- |
| 16 | + |
| 17 | +# Convert append blobs and page blobs into block blobs |
| 18 | + |
| 19 | +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. |
| 20 | + |
| 21 | +## Convert append and page blobs |
| 22 | + |
| 23 | +### [PowerShell](#tab/azure-powershell) |
| 24 | + |
| 25 | +1. Open a Windows PowerShell command window. |
| 26 | + |
| 27 | +2. Sign in to your Azure subscription with the [Connect-AzAccount](/powershell/module/az.accounts/connect-azaccount) command and follow the on-screen directions. |
| 28 | + |
| 29 | + ```powershell |
| 30 | + Connect-AzAccount |
| 31 | + ``` |
| 32 | + |
| 33 | +3. 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. |
| 34 | + |
| 35 | + ```powershell |
| 36 | + $context = Get-AzSubscription -SubscriptionId '<subscription-id>' |
| 37 | + Set-AzContext $context |
| 38 | + ``` |
| 39 | + |
| 40 | + Replace the `<subscription-id>` placeholder value with the ID of your subscription. |
| 41 | + |
| 42 | +4. Create the storage account context by using the [New-AzStorageContext](/powershell/module/az.storage/new-azstoragecontext) command. Include the `-UseConnectedAccount` parameter so that data operations will be performed using your Azure Active Directory (Azure AD) credentials. |
| 43 | + |
| 44 | + ```powershell |
| 45 | + $ctx = New-AzStorageContext -StorageAccountName '<storage account name>' -UseConnectedAccount |
| 46 | + ``` |
| 47 | + |
| 48 | +5. Use the [Copy-AzStorageBlob](/powershell/module/az.storage/copy-azstorageblob) command and set the `-DestBlobType` parameter to `Block`. |
| 49 | + |
| 50 | + ```powershell |
| 51 | + $containerName = '<source container name>' |
| 52 | + $srcblobName = '<source append or page blob name>' |
| 53 | + $destcontainerName = '<destination container name>' |
| 54 | + $destblobName = '<destination block blob name>' |
| 55 | + $destTier = '<destination block blob tier>' |
| 56 | +
|
| 57 | + Copy-AzStorageBlob -SrcContainer $containerName -SrcBlob $srcblobName -Context $ctx -DestContainer $destcontainerName -DestBlob $destblobName -DestContext $ctx -DestBlobType Block -StandardBlobTier $destTier |
| 58 | + ``` |
| 59 | + |
| 60 | + > [!TIP] |
| 61 | + > The `-StandardBlobTier` parameter is optional. If you omit that parameter, then the destination blob infers its tier from the [default account access tier setting](access-tiers-overview.md#default-account-access-tier-setting). To change the tier after you've created a block blob, see [Change a blob's tier](access-tiers-online-manage.md#change-a-blobs-tier). |
| 62 | +
|
| 63 | + |
| 64 | +### [Azure CLI](#tab/azure-cli) |
| 65 | + |
| 66 | +1. First, open the [Azure Cloud Shell](../../cloud-shell/overview.md), or if you've [installed](/cli/azure/install-azure-cli) the Azure CLI locally, open a command console application such as Windows PowerShell. |
| 67 | + |
| 68 | + > [!NOTE] |
| 69 | + > If you're using a locally installed version of the Azure CLI, ensure that you are using version 2.44.0 or later. |
| 70 | +
|
| 71 | +2. 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. |
| 72 | + |
| 73 | + ```azurecli-interactive |
| 74 | + az account set --subscription <subscription-id> |
| 75 | + ``` |
| 76 | + |
| 77 | + Replace the `<subscription-id>` placeholder value with the ID of your subscription. |
| 78 | + |
| 79 | +3. Use the [az storage blob copy start](/cli/azure/storage/blob/copy#az-storage-blob-copy-start) command and set the `--destination-blob-type` parameter to `blockBlob`. |
| 80 | + |
| 81 | + ```azurecli |
| 82 | + containerName = '<source container name>' |
| 83 | + srcblobName = '<source append or page blob name>' |
| 84 | + destcontainerName = '<destination container name>' |
| 85 | + destblobName = '<destination block blob name>' |
| 86 | + destTier = '<destination block blob tier>' |
| 87 | +
|
| 88 | + 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 |
| 89 | + ``` |
| 90 | + |
| 91 | + > [!TIP] |
| 92 | + > The `--tier` parameter is optional. If you omit that parameter, then the destination blob infers its tier from the [default account access tier setting](access-tiers-overview.md#default-account-access-tier-setting). To change the tier after you've created a block blob, see [Change a blob's tier](access-tiers-online-manage.md#change-a-blobs-tier). |
| 93 | +
|
| 94 | + > [!WARNING] |
| 95 | + > 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. |
| 96 | +
|
| 97 | + |
| 98 | +### [AzCopy](#tab/azcopy) |
| 99 | + |
| 100 | +Use the [azcopy copy](../common/storage-ref-azcopy-copy.md) command. Specify the source and destination paths. Set the `blob-type` parameter to `BlockBlob`. |
| 101 | + |
| 102 | +```azcopy |
| 103 | +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> |
| 104 | +``` |
| 105 | + |
| 106 | +> [!TIP] |
| 107 | +> 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](access-tiers-overview.md#default-account-access-tier-setting). To change the tier after you've created a block blob, see [Change a blob's tier](access-tiers-online-manage.md#change-a-blobs-tier). |
| 108 | +
|
| 109 | +> [!WARNING] |
| 110 | +> 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. |
| 111 | +
|
| 112 | +--- |
| 113 | + |
| 114 | +## See also |
| 115 | + |
| 116 | +- [Hot, Cool, and Archive access tiers for blob data](access-tiers-overview.md) |
| 117 | +- [Set a blob's access tier](access-tiers-online-manage.md) |
| 118 | +- [Best practices for using blob access tiers](access-tiers-best-practices.md) |
0 commit comments