|
| 1 | +--- |
| 2 | +title: Set a blob's access tier |
| 3 | +titleSuffix: Azure Storage |
| 4 | +description: Learn how to specify a blob's access tier when you upload it, or how to change the access tier for an existing blob. |
| 5 | +author: tamram |
| 6 | + |
| 7 | +ms.author: tamram |
| 8 | +ms.date: 10/25/2021 |
| 9 | +ms.service: storage |
| 10 | +ms.subservice: blobs |
| 11 | +ms.topic: how-to |
| 12 | +ms.reviewer: fryu |
| 13 | +ms.custom: devx-track-azurepowershell |
| 14 | +--- |
| 15 | + |
| 16 | +# Set a blob's access tier |
| 17 | + |
| 18 | +You can set a blob's access tier in any of the following ways: |
| 19 | + |
| 20 | +- By setting the default online access tier (Hot or Cool) for the storage account. Blobs in the account inherit this access tier unless you explicitly override the setting for an individual blob. |
| 21 | +- By explicitly setting a blob's tier on upload. You can create a blob in the Hot, Cool, or Archive tier. |
| 22 | +- By changing an existing blob's tier with a Set Blob Tier operation, typically to move from a hotter tier to a cooler one. |
| 23 | +- By copying a blob with a Copy Blob operation, typically to move from a cooler tier to a hotter one. |
| 24 | + |
| 25 | +This article describes how manage a blob in an online access tier (Hot or Cool). For more information about how to move a blob to the Archive tier, see [Archive a blob](archive-blob.md). For more information about how to rehydrate a blob from the Archive tier, see [Rehydrate an archived blob to an online tier](archive-rehydrate-to-online-tier.md). |
| 26 | + |
| 27 | +For more information about access tiers for blobs, see [Hot, cool, and archive access tiers for blob data](access-tiers-overview.md). |
| 28 | + |
| 29 | +## Set the default access tier for a storage account |
| 30 | + |
| 31 | +The default access tier setting for a general-purpose v2 storage account determines in which online tier a new blob is created by default. You can set the default access tier for a general-purpose v2 storage account at the time that you create the account or by updating an existing account's configuration. |
| 32 | + |
| 33 | +When you change the default access tier setting for an existing general-purpose v2 storage account, the change applies to all blobs in the account for which an access tier has not been explicitly set. Changing the default access tier may have a billing impact. For details, see [Default account access tier setting](access-tiers-overview.md#default-account-access-tier-setting). |
| 34 | + |
| 35 | +#### [Portal](#tab/azure-portal) |
| 36 | + |
| 37 | +To set the default access tier for a storage account at create time in the Azure portal, follow these steps: |
| 38 | + |
| 39 | +1. Navigate to the **Storage accounts** page, and select the **Create** button. |
| 40 | +1. Fill out the **Basics** tab. |
| 41 | +1. On the **Advanced** tab, under **Blob storage**, set the **Access tier** to either *Hot* or *Cool*. The default setting is *Hot*. |
| 42 | +1. Select **Review + Create** to validate your settings and create your storage account. |
| 43 | + |
| 44 | + :::image type="content" source="media/access-tiers-online-manage/set-default-access-tier-create-portal.png" alt-text="Screenshot showing how to set the default access tier when creating a storage account."::: |
| 45 | + |
| 46 | +To update the default access tier for an existing storage account in the Azure portal, follow these steps: |
| 47 | + |
| 48 | +1. Navigate to the storage account in the Azure portal. |
| 49 | +1. Under **Settings**, select **Configuration**. |
| 50 | +1. Locate the **Blob access tier (default)** setting, and select either *Hot* or *Cool*. The default setting is *Hot*, if you have not previously set this property. |
| 51 | +1. Save your changes. |
| 52 | + |
| 53 | +#### [PowerShell](#tab/azure-powershell) |
| 54 | + |
| 55 | +To change the default access tier setting for a storage account with PowerShell, call the [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount) command, specifying the new default access tier. |
| 56 | + |
| 57 | +```azurepowershell |
| 58 | +$rgName = <resource-group> |
| 59 | +$accountName = <storage-account> |
| 60 | +
|
| 61 | +# Change the storage account tier to Cool |
| 62 | +Set-AzStorageAccount -ResourceGroupName $rgName -Name $accountName -AccessTier Cool |
| 63 | +``` |
| 64 | + |
| 65 | +#### [Azure CLI](#tab/azure-cli) |
| 66 | + |
| 67 | +To change the default access tier setting for a storage account with PowerShell, call the [Set-AzStorageAccount](/powershell/module/az.storage/set-azstorageaccount) command, specifying the new default access tier. |
| 68 | + |
| 69 | +```azurecli |
| 70 | +# Change the storage account tier to Cool |
| 71 | +az storage account update \ |
| 72 | + --resource-group <resource-group> \ |
| 73 | + --name <storage-account> \ |
| 74 | + --access-tier Cool |
| 75 | +``` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Set a blob's tier on upload |
| 80 | + |
| 81 | +When you upload a blob to Azure Storage, you have two options for setting the blob's tier on upload: |
| 82 | + |
| 83 | +- You can explicitly specify the tier in which the blob will be created. This setting overrides the default access tier for the storage account. You can set the tier for a blob or set of blobs on upload to Hot, Cool, or Archive. |
| 84 | +- You can upload a blob without specifying a tier. In this case, the blob will be created in the default access tier specified for the storage account (either Hot or Cool). |
| 85 | + |
| 86 | +The following sections describe how to specify that a blob is uploaded to either the Hot or Cool tier. For more information about archiving a blob on upload, see [Archive blobs on upload](archive-blob.md#archive-blobs-on-upload). |
| 87 | + |
| 88 | +### Upload a blob to a specific online tier |
| 89 | + |
| 90 | +To create a blob in the Hot or Cool tier tier, specify that tier when you create the blob. The access tier specified on upload overrides the default access tier for the storage account. |
| 91 | + |
| 92 | +### [Portal](#tab/azure-portal) |
| 93 | + |
| 94 | +To upload a blob or set of blobs to a specific tier from the Azure portal, follow these steps: |
| 95 | + |
| 96 | +1. Navigate to the target container. |
| 97 | +1. Select the **Upload** button. |
| 98 | +1. Select the file or files to upload. |
| 99 | +1. Expand the **Advanced** section, and set the **Access tier** to *Hot* or *Cool*. |
| 100 | +1. Select the **Upload** button. |
| 101 | + |
| 102 | + :::image type="content" source="media/access-tiers-online-manage/upload-blob-to-online-tier-portal.png" alt-text="Screenshot showing how to upload blobs to an online tier in the Azure portal."::: |
| 103 | + |
| 104 | +### [PowerShell](#tab/azure-powershell) |
| 105 | + |
| 106 | +To upload a blob or set of blobs to a specific tier with PowerShell, call the [Set-AzStorageBlobContent](/powershell/module/az.storage/set-azstorageblobcontent) command, as shown in the following example. Remember to replace the placeholder values in brackets with your own values: |
| 107 | + |
| 108 | +```azurepowershell |
| 109 | +$rgName = <resource-group> |
| 110 | +$storageAccount = <storage-account> |
| 111 | +$containerName = <container> |
| 112 | +
|
| 113 | +# Get context object |
| 114 | +$ctx = New-AzStorageContext -StorageAccountName $storageAccount -UseConnectedAccount |
| 115 | +
|
| 116 | +# Create new container. |
| 117 | +New-AzStorageContainer -Name $containerName -Context $ctx |
| 118 | +
|
| 119 | +# Upload a single file named blob1.txt to the Cool tier. |
| 120 | +Set-AzStorageBlobContent -Container $containerName ` |
| 121 | + -File "blob1.txt" ` |
| 122 | + -Blob "blob1.txt" ` |
| 123 | + -Context $ctx ` |
| 124 | + -StandardBlobTier Cool |
| 125 | +
|
| 126 | +# Upload the contents of a sample-blobs directory to the Cool tier, recursively. |
| 127 | +Get-ChildItem -Path "C:\sample-blobs" -File -Recurse | |
| 128 | + Set-AzStorageBlobContent -Container $containerName ` |
| 129 | + -Context $ctx ` |
| 130 | + -StandardBlobTier Cool |
| 131 | +``` |
| 132 | + |
| 133 | +### [Azure CLI](#tab/azure-cli) |
| 134 | + |
| 135 | +To upload a blob to a specific tier with Azure CLI, call the [az storage blob upload](/cli/azure/storage/blob#az_storage_blob_upload) command, as shown in the following example. Remember to replace the placeholder values in brackets with your own values: |
| 136 | + |
| 137 | +```azurecli |
| 138 | +az storage blob upload \ |
| 139 | + --account-name <storage-account> \ |
| 140 | + --container-name <container> \ |
| 141 | + --name <blob> \ |
| 142 | + --file <file> \ |
| 143 | + --tier Cool \ |
| 144 | + --auth-mode login |
| 145 | +``` |
| 146 | + |
| 147 | +To upload a set of blobs to a specific tier with Azure CLI, call the [az storage blob upload-batch](/cli/azure/storage/blob#az_storage_blob_upload_batch) command, as shown in the following example. Remember to replace the placeholder values in brackets with your own values: |
| 148 | + |
| 149 | +```azurecli |
| 150 | +az storage blob upload-batch \ |
| 151 | + --destination <container> \ |
| 152 | + --source <source-directory> \ |
| 153 | + --account-name <storage-account> \ |
| 154 | + --tier Cool \ |
| 155 | + --auth-mode login |
| 156 | +``` |
| 157 | + |
| 158 | +--- |
| 159 | + |
| 160 | +### Upload a blob to the default tier |
| 161 | + |
| 162 | +Storage accounts have a default access tier setting that indicates in which online tier a new blob is created. The default access tier setting can be set to either hot or cool. The behavior of this setting is slightly different depending on the type of storage account: |
| 163 | + |
| 164 | +- The default access tier for a new general-purpose v2 storage account is set to the Hot tier by default. You can change the default access tier setting when you create a storage account or after it is created. |
| 165 | +- When you create a legacy Blob Storage account, you must specify the default access tier setting as Hot or Cool when you create the storage account. You can change the default access tier setting for the storage account after it is created. |
| 166 | + |
| 167 | +A blob that doesn't have an explicitly assigned tier infers its tier from the default account access tier setting. You can determine whether a blob's access tier is inferred by using the Azure portal, PowerShell, or Azure CLI. |
| 168 | + |
| 169 | +#### [Portal](#tab/azure-portal) |
| 170 | + |
| 171 | +If a blob's access tier is inferred from the default account access tier setting, then the Azure portal displays the access tier as **Hot (inferred)** or **Cool (inferred)**. |
| 172 | + |
| 173 | +:::image type="content" source="media/access-tiers-online-manage/default-access-tier-portal.png" alt-text="Screenshot showing blobs with the default access tier in the Azure portal."::: |
| 174 | + |
| 175 | +#### [PowerShell](#tab/azure-powershell) |
| 176 | + |
| 177 | +To determine a blob's access tier and whether it is inferred from Azure PowerShell, retrieve the blob, then check its **AccessTier** and **AccessTierInferred** properties. |
| 178 | + |
| 179 | +```azurepowershell |
| 180 | +$rgName = "<resource-group>" |
| 181 | +$storageAccount = "<storage-account>" |
| 182 | +$containerName = "<container>" |
| 183 | +$blobName = "<blob>" |
| 184 | +
|
| 185 | +# Get the storage account context. |
| 186 | +$ctx = New-AzStorageContext -StorageAccountName $storageAccount -UseConnectedAccount |
| 187 | +
|
| 188 | +# Get the blob from the service. |
| 189 | +$blob = Get-AzStorageBlob -Context $ctx -Container $containerName -Blob $blobName |
| 190 | +
|
| 191 | +# Check the AccessTier and AccessTierInferred properties. |
| 192 | +# If the access tier is inferred, that property returns true. |
| 193 | +$blob.BlobProperties.AccessTier |
| 194 | +$blob.BlobProperties.AccessTierInferred |
| 195 | +``` |
| 196 | + |
| 197 | +#### [Azure CLI](#tab/azure-cli) |
| 198 | + |
| 199 | +To determine a blob's access tier and whether it is inferred from Azure CLI, retrieve the blob, then check its **blobTier** and **blobTierInferred** properties. |
| 200 | + |
| 201 | +```azurecli |
| 202 | +az storage blob show \ |
| 203 | + --container-name <container> \ |
| 204 | + --name <blob> \ |
| 205 | + --account-name <storage-account> \ |
| 206 | + --query '[properties.blobTier, properties.blobTierInferred]' \ |
| 207 | + --output tsv \ |
| 208 | + --auth-mode login |
| 209 | +``` |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## Move a blob to a different online tier |
| 214 | + |
| 215 | +You can change the tier of an existing blob in one of two ways: |
| 216 | + |
| 217 | +- By calling the [Set Blob Tier](/rest/api/storageservices/set-blob-tier) operation, either directly or via a [lifecycle management](access-tiers-overview.md#blob-lifecycle-management) policy, to change the blob's tier. |
| 218 | +- By calling the [Copy Blob](/rest/api/storageservices/copy-blob) operation to copy a blob from one tier to another. In this case, the source blob remains in the original tier, and a new blob is created in the target tier. |
| 219 | + |
| 220 | +For more information about each of these options, see [Setting or changing a blob's tier](access-tiers-overview.md#setting-or-changing-a-blobs-tier). |
| 221 | + |
| 222 | +Use PowerShell, Azure CLI, or one of the Azure Storage client libraries to move a blob to a different tier. |
| 223 | + |
| 224 | +### Change a blob's tier |
| 225 | + |
| 226 | +When you change a blob's tier, you move that blob and all of its data to the target tier. Calling [Set Blob Tier](/rest/api/storageservices/set-blob-tier) is typically the best option when you are changing a blob's tier from a hotter tier to a cooler one. |
| 227 | + |
| 228 | +# [Portal](#tab/azure-portal) |
| 229 | + |
| 230 | +To change a blob's tier from Hot to Cool in the Azure portal, follow these steps: |
| 231 | + |
| 232 | +1. Navigate to the blob for which you want to change the tier. |
| 233 | +1. Select the blob, then select the **Change tier** button. |
| 234 | +1. In the **Change tier** dialog, select the target tier. |
| 235 | +1. Select the **Save** button. |
| 236 | + |
| 237 | + :::image type="content" source="media/access-tiers-online-manage/change-blob-tier-portal.png" alt-text="Screenshot showing how to change a blob's tier in the Azure portal"::: |
| 238 | + |
| 239 | +#### [PowerShell](#tab/azure-powershell) |
| 240 | + |
| 241 | +To change a blob's tier from Hot to Cool with PowerShell, use the blob's **BlobClient** property to return a .NET reference to the blob, then call the **SetAccessTier** method on that reference. Remember to replace placeholders in angle brackets with your own values: |
| 242 | + |
| 243 | +```azurepowershell |
| 244 | +# Initialize these variables with your values. |
| 245 | +$rgName = "<resource-group>" |
| 246 | +$accountName = "<storage-account>" |
| 247 | +$containerName = "<container>" |
| 248 | +$blobName = "<blob>" |
| 249 | +
|
| 250 | +# Get the storage account context |
| 251 | +$ctx = (Get-AzStorageAccount ` |
| 252 | + -ResourceGroupName $rgName ` |
| 253 | + -Name $accountName).Context |
| 254 | +
|
| 255 | +# Change the blob's access tier to Cool. |
| 256 | +$blob = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx |
| 257 | +$blob.BlobClient.SetAccessTier("Cool", $null, "Standard") |
| 258 | +``` |
| 259 | + |
| 260 | +#### [Azure CLI](#tab/azure-cli) |
| 261 | + |
| 262 | +To change a blob's tier from Hot to Cool with Azure CLI, call the [az storage blob set-tier](/cli/azure/storage/blob#az_storage_blob_set_tier) command. Remember to replace placeholders in angle brackets with your own values: |
| 263 | + |
| 264 | +```azurecli |
| 265 | +az storage blob set-tier \ |
| 266 | + --account-name <storage-account> \ |
| 267 | + --container-name <container> \ |
| 268 | + --name <blob> \ |
| 269 | + --tier Cool \ |
| 270 | + --auth-mode login |
| 271 | +``` |
| 272 | + |
| 273 | +--- |
| 274 | + |
| 275 | +### Copy a blob to a different online tier |
| 276 | + |
| 277 | +When you copy a blob to a different tier, you move that blob and all of its data to the target tier. Calling [Copy Blob](/rest/api/storageservices/copy-blob) is recommended for most scenarios where you are moving a blob from Cool to Hot, or rehydrating a blob from the Archive tier. |
| 278 | + |
| 279 | +# [Portal](#tab/azure-portal) |
| 280 | + |
| 281 | +N/A |
| 282 | + |
| 283 | +#### [PowerShell](#tab/azure-powershell) |
| 284 | + |
| 285 | +To copy a blob to from Cool to Hot with PowerShell, call the [Start-AzStorageBlobCopy](/powershell/module/az.storage/start-azstorageblobcopy) command and specify the target tier. Remember to replace placeholders in angle brackets with your own values: |
| 286 | + |
| 287 | +```azurepowershell |
| 288 | +# Initialize these variables with your values. |
| 289 | +$rgName = "<resource-group>" |
| 290 | +$accountName = "<storage-account>" |
| 291 | +$srcContainerName = "<source-container>" |
| 292 | +$destContainerName = "<dest-container>" |
| 293 | +$srcBlobName = "<source-blob>" |
| 294 | +$destBlobName = "<dest-blob>" |
| 295 | +
|
| 296 | +# Get the storage account context |
| 297 | +$ctx = (Get-AzStorageAccount ` |
| 298 | + -ResourceGroupName $rgName ` |
| 299 | + -Name $accountName).Context |
| 300 | +
|
| 301 | +# Copy the source blob to a new destination blob in Hot tier with Standard priority. |
| 302 | +Start-AzStorageBlobCopy -SrcContainer $srcContainerName ` |
| 303 | + -SrcBlob $srcBlobName ` |
| 304 | + -DestContainer $destContainerName ` |
| 305 | + -DestBlob $destBlobName ` |
| 306 | + -StandardBlobTier Hot ` |
| 307 | + -Context $ctx |
| 308 | +``` |
| 309 | + |
| 310 | +#### [Azure CLI](#tab/azure-cli) |
| 311 | + |
| 312 | +To copy a blob from Cool to Hot with Azure CLI, call the [az storage blob copy start](/cli/azure/storage/blob/copy#az_storage_blob_copy_start) command and specify the target tier. Remember to replace placeholders in angle brackets with your own values: |
| 313 | + |
| 314 | +```azurecli |
| 315 | +az storage blob copy start \ |
| 316 | + --source-container <source-container> \ |
| 317 | + --source-blob <source-blob> \ |
| 318 | + --destination-container <dest-container> \ |
| 319 | + --destination-blob <dest-blob> \ |
| 320 | + --account-name <storage-account> \ |
| 321 | + --tier hot \ |
| 322 | + --auth-mode login |
| 323 | +``` |
| 324 | + |
| 325 | +--- |
| 326 | + |
| 327 | +## Next steps |
| 328 | + |
| 329 | +- [How to manage the default account access tier of an Azure Storage account](../common/manage-account-default-access-tier.md) |
| 330 | +- [Rehydrate an archived blob to an online tier](archive-rehydrate-to-online-tier.md) |
0 commit comments