Skip to content

Commit b44ab83

Browse files
committed
update CLI examples per customer feedback
1 parent d2d7ac0 commit b44ab83

File tree

1 file changed

+47
-41
lines changed

1 file changed

+47
-41
lines changed

articles/storage/blobs/blob-cli.md

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Manage block blobs with Azure CLI
33
titleSuffix: Azure Storage
4-
description: Manage blobs with Azure CLI
4+
description: Manage blobs with Azure CLI.
55
author: StevenMatthew
66

77
ms.author: shaas
@@ -102,65 +102,71 @@ az storage blob upload-batch \
102102

103103
## List blobs
104104

105-
By default, the `az storage blob list` command lists all blobs stored within a container. You can use various approaches to refine the scope of your search. There's no restriction on the number of containers or blobs a storage account may have. To potentially avoid retrieving thousands of blobs, it's a good idea to limit the amount of data returned.
105+
By default, the `az storage blob list` command lists all blobs stored within a container. You can use various approaches to refine the scope of your search. There's no restriction on the number of containers or blobs a storage account can have. To potentially avoid retrieving thousands of blobs, it's a good idea to limit the amount of data returned.
106106

107107
Use the `--prefix` parameter to select either a single known file or a range of files whose names begin with a defined string.
108108

109-
By default, only blobs are returned in a listing operation. In some scenarios, you may want to pass a value for the `--include` parameter to return additional types of objects such as soft-deleted blobs, snapshots, and versions. These values can be combined to return more than multiple object types.
109+
By default, only blobs are returned in a listing operation. In some scenarios, you might want to pass a value for the `--include` parameter to return additional types of objects such as soft-deleted blobs, snapshots, and versions. These values can be combined to return more than multiple object types.
110110

111111
The `--num-results` parameter can be used to limit the number of unfiltered blobs returned from a container. A service limit of 5,000 is imposed on all Azure resources. This limit ensures that manageable amounts of data are retrieved and that performance isn't impacted. If the number of blobs returned exceeds either the `--num-results` value or the service limit, a continuation token is returned. This token allows you to use multiple requests to retrieve any number of blobs. More information is available on [Enumerating blob resources](/rest/api/storageservices/enumerating-blob-resources).
112112

113113
The following example shows several approaches used to provide a list of blobs. The first approach lists a single blob within a specific container resource. The second approach uses the `--prefix` parameter to list all blobs in all containers with a prefix of *louis*. The search is restricted to five containers using the `--num-results` parameter. The third approach uses `--num-results` and `--marker` parameters to limit the retrieval of all blobs within a container.
114114

115-
For additional information, see the [az storage blob list](/cli/azure/storage/blob#az-storage-blob-list) reference.
115+
For more information, see the [az storage blob list](/cli/azure/storage/blob#az-storage-blob-list) reference.
116116

117117
```azurecli-interactive
118-
119118
#!/bin/bash
120119
storageAccount="<storage-account>"
121-
blobName="demo-file.txt"
122120
containerName="demo-container"
123121
blobPrefix="img-louis"
124122
numResults=5
125123
126-
#Approach 1: List all blobs in a named container
124+
#Approach 1: List all blobs in a container
125+
127126
az storage blob list \
127+
--account-name $storageAccount \
128128
--container $containerName \
129+
--query "[].name" \
130+
--auth-mode login \
131+
--output tsv
132+
133+
#Approach 2: Use the --prefix parameter to list blobs starting with specified prefix
134+
135+
az storage blob list \
129136
--account-name $storageAccount \
130-
--prefix $blobName
131-
--auth-mode login
137+
--container $containerName \
138+
--prefix $blobPrefix \
139+
--query "[].name" \
140+
--auth-mode login \
141+
--output tsv
142+
143+
#Approach 3: Use the continuation token to return the next set of blobs.
144+
145+
$resultSet=$(az storage blob list `
146+
--account-name $storageAccount `
147+
--container $containerName `
148+
--prefix $blobPrefix `
149+
--num-results $numResults `
150+
--show-next-marker `
151+
--query "[].{Name:name, Marker:nextMarker}" `
152+
--auth-mode login `
153+
--output tsv)
154+
155+
$markerEntry=$resultSet[$numResults] | cut -f2
156+
$marker= echo $markerEntry | cut -f2
132157
133-
#Approach 2: Use the --prefix parameter to list blobs in all containers
134158
135-
containerList=$( \
136-
az storage container list \
137-
--query "[].name" \
138-
--num-results $numResults \
139-
--account-name $storageAccount \
140-
--auth-mode login \
141-
--output tsv
142-
)
143-
for row in $containerList
144-
do
145-
tmpName=$(echo $row | sed -e 's/\r//g')
146-
echo $tmpName
147-
az storage blob list \
148-
--prefix $blobPrefix \
149-
--container $tmpName \
150-
--account-name $storageAccount \
151-
--auth-mode login
152-
done
153159
```
154160

155161
## Download a blob
156162

157-
Depending on your use case, you'll use either the `az storage blob download` or `az storage blob download-batch` command to download blobs. To download an individual blob, call the `az storage blob download` command directly and pass values for the `--container-name`, `--file`, and `--name` parameters. The blob will be downloaded to the shell directory by default, but an alternate location can be specified. The operation will fail with an error if your specified path doesn't exist.
163+
Depending on your use case, you'll use either the `az storage blob download` or `az storage blob download-batch` command to download blobs. To download an individual blob, call the `az storage blob download` command directly and pass values for the `--container-name`, `--file`, and `--name` parameters. The blob is downloaded to the shell directory by default, but an alternate location can be specified. The operation will fail with an error if your specified path doesn't exist.
158164

159165
To recursively download multiple blobs from a storage container, use the `az storage blob download-batch` command. This command supports Unix filename pattern matching with the `--pattern` parameter. The supported patterns are `*`, `?`, `[seq]`, and `[!seq]`. To learn more, refer to the Python documentation on [Unix filename pattern matching](https://docs.python.org/3/library/fnmatch.html).
160166

161-
The following sample code provides an example of both single and multiple download approaches. It also offers a simplified approach to searching all containers for specific files using a wildcard. Because some environments may have many thousands of resources, using the `--num-results` parameter is recommended.
167+
The following sample code provides an example of both single and multiple download approaches. It also offers a simplified approach to searching all containers for specific files using a wildcard. Because some environments can have many thousands of resources, using the `--num-results` parameter is recommended.
162168

163-
For additional information, see the [az storage blob download](/cli/azure/storage/blob#az-storage-blob-download) and [az storage blob download batch](/cli/azure/storage/blob#az-storage-blob-download-batch)reference.
169+
For more information, see the [az storage blob download](/cli/azure/storage/blob#az-storage-blob-download) and [az storage blob download batch](/cli/azure/storage/blob#az-storage-blob-download-batch)reference.
164170

165171
```azurecli-interactive
166172
#!/bin/bash
@@ -226,7 +232,7 @@ User-defined metadata consists of one or more name-value pairs that you specify
226232

227233
To read blob properties or metadata, you must first retrieve the blob from the service. Use the `az storage blob show` command to retrieve a blob's properties and metadata, but not its content. The following example retrieves a blob and lists its properties.
228234

229-
For additional information, see the [az storage blob show](/cli/azure/storage/blob#az-storage-blob-show) reference.
235+
For more information, see the [az storage blob show](/cli/azure/storage/blob#az-storage-blob-show) reference.
230236

231237
```azurecli-interactive
232238
#!/bin/bash
@@ -245,7 +251,7 @@ az storage blob show \
245251

246252
Blob metadata is an optional set of name/value pairs associated with a blob. As shown in the previous example, there's no metadata associated with a blob initially, though it can be added when necessary. To read, use the `az storage blob metadata show` command. To update blob metadata, you'll use `az storage blob metadata update` and supply an array of key-value pairs. For more information, see the [az storage blob metadata](/cli/azure/storage/blob/metadata) reference.
247253

248-
For additional information, see the [az storage blob metadata](/cli/azure/storage/blob#az-storage-blob-metadata) reference.
254+
For more information, see the [az storage blob metadata](/cli/azure/storage/blob#az-storage-blob-metadata) reference.
249255

250256
The example below first updates and then commits a blob's metadata, and then retrieves it.
251257

@@ -278,7 +284,7 @@ az storage blob metadata show \
278284

279285
## Copy operations for blobs
280286

281-
There are many scenarios in which blobs of different types may be copied. Examples in this article are limited to block blobs. Azure CLI offers commands that perform operations on one resource or on multiple resources, depending on your requirements.
287+
There are many scenarios in which blobs of different types can be copied. Examples in this article are limited to block blobs. Azure CLI offers commands that perform operations on one resource or on multiple resources, depending on your requirements.
282288

283289
To copy a specific blob, use the `az storage blob copy start` command and specify values for source and destination containers and blobs. It's also possible to provide a uniform resource identifier (URI), share, or shared access signature (SAS) as the source.
284290

@@ -291,7 +297,7 @@ You can use the `az storage blob copy start-batch` command to recursively copy m
291297
292298
For more information, see the [az storage blob copy](/cli/azure/storage/blob/copy) reference.
293299

294-
The following sample code provides an example of both single and multiple copy operations. Because some environments may have many thousands of resources, using the `--num-results` parameter is recommended. The first example copies the **secret-town-road.png** blob from the **photos** container to the **locations** container. Both containers exist within the same storage account. The result verifies the success of the copy operation.
300+
The following sample code provides an example of both single and multiple copy operations. Because some environments can have many thousands of resources, using the `--num-results` parameter is recommended. The first example copies the **secret-town-road.png** blob from the **photos** container to the **locations** container. Both containers exist within the same storage account. The result verifies the success of the copy operation.
295301

296302
```azurecli-interactive
297303
#!/bin/bash
@@ -333,11 +339,11 @@ az storage blob snapshot \
333339

334340
When you change a blob's tier, you move the blob and all of its data to the target tier. You can change the tier between **hot**, **cool**, and **archive** with the `az storage blob set-tier` command.
335341

336-
Depending on your requirements, you may also utilize the *Copy Blob* operation to copy a blob from one tier to another. The *Copy Blob* operation will create a new blob in the desired tier while leaving the source blob remains in the original tier.
342+
Depending on your requirements, you may also utilize the *Copy Blob* operation to copy a blob from one tier to another. The *Copy Blob* operation creates a new blob in the desired tier while leaving the source blob remains in the original tier.
337343

338344
Changing tiers from **cool** or **hot** to **archive** takes place almost immediately. After a blob is moved to the **archive** tier, it's considered to be offline and can't be read or modified. Before you can read or modify an archived blob's data, you'll need to rehydrate it to an online tier. Read more about [Blob rehydration from the archive tier](archive-rehydrate-overview.md).
339345

340-
For additional information, see the [az storage blob set-tier](/cli/azure/storage/blob#az-storage-blob-set-tier) reference.
346+
For more information, see the [az storage blob set-tier](/cli/azure/storage/blob#az-storage-blob-set-tier) reference.
341347

342348
The following sample code sets the tier to **hot** for a single, named blob within the `archive` container.
343349

@@ -363,7 +369,7 @@ Blob index tags make data management and discovery easier. Blob index tags are u
363369
364370
The following example illustrates how to add blob index tags to a series of blobs. The example reads data from an XML file and uses it to create index tags on several blobs. To use the sample code, create a local *blob-list.xml* file in your *C:\temp* directory. The XML data is provided below.
365371

366-
For additional information, see the [az storage blob set-tier](/cli/azure/storage/blob#az-storage-blob-set-tier) reference.
372+
For more information, see the [az storage blob set-tier](/cli/azure/storage/blob#az-storage-blob-set-tier) reference.
367373

368374
```xml
369375
<Venue Name="House of Prime Rib" Type="Restaurant">
@@ -476,7 +482,7 @@ az storage blob delete-batch \
476482
--auth-mode login
477483
```
478484

479-
In some cases, it's possible to retrieve blobs that have been deleted. If your storage account's soft delete data protection option is enabled, the `--include d` parameter and value will return blobs deleted within the account's retention period. To learn more about soft delete, refer to thee [Soft delete for blobs](soft-delete-blob-overview.md) article.
485+
In some cases, it's possible to retrieve blobs that have been deleted. If your storage account's soft delete data protection option is enabled, passing the `--include d` parameter returns blobs that were deleted within the account's retention period. To learn more about soft delete, refer to thee [Soft delete for blobs](soft-delete-blob-overview.md) article.
480486

481487
Use the following examples to retrieve a list of blobs deleted within container's associated retention period. The first example displays a list of all recently deleted blobs and the dates on which they were deleted. The second example lists all deleted blobs matching a specific prefix.
482488

@@ -510,11 +516,11 @@ az storage blob list \
510516
## Restore a deleted blob
511517
As mentioned in the [List blobs](#list-blobs) section, you can configure the soft delete data protection option on your storage account. When enabled, it's possible to restore containers deleted within the associated retention period. You may also use versioning to maintain previous versions of your blobs for each recovery and restoration.
512518

513-
If blob versioning and blob soft delete are both enabled, then modifying, overwriting, deleting, or restoring a blob automatically creates a new version. The method you'll use to restore a deleted blob will depend upon whether versioning is enabled on your storage account.
519+
If blob versioning and blob soft delete are both enabled, then modifying, overwriting, deleting, or restoring a blob automatically creates a new version. The method you'll use to restore a deleted blob depends upon whether versioning is enabled on your storage account.
514520

515521
The following code sample restores all soft-deleted blobs or, if versioning is enabled, restores the latest version of a blob. It first determines whether versioning is enabled with the `az storage account blob-service-properties show` command.
516522

517-
If versioning is enabled, the `az storage blob list` command retrieves a list of all uniquely-named blob versions. Next, the blob versions on the list are retrieved and ordered by date. If no versions are found with the `isCurrentVersion` attribute value, the `az storage blob copy start` command is used to make an active copy of the blob's latest version.
523+
If versioning is enabled, the `az storage blob list` command retrieves a list of all uniquely named blob versions. Next, the blob versions on the list are retrieved and ordered by date. If no versions are found with the `isCurrentVersion` attribute value, the `az storage blob copy start` command is used to make an active copy of the blob's latest version.
518524

519525
If versioning is disabled, the `az storage blob undelete` command is used to restore each soft-deleted blob in the container.
520526

0 commit comments

Comments
 (0)