13

I've installed azure-cli in the hope to use it to download an entire container from Azure storage. The info on the page gives clear examples on how to get a single blob, but not on how one downloads an entire container.

There is a 'azure storage blob download [parameters]'. Where is 'azure storage container download [parameters]'?

9

First, login with:

az login

Then download the files you need:

az storage blob download-batch -d . \
  --pattern *.* \
  -s MyContainer \
  --account-name storageAccountName
  --account-key storageAccountKey
1
  • In case the storage account is in a different subscription from your default, you'll also need to change subscription after the az login and before the az storage commands. You can do that with: az account set -s {Subscription GUID goes here without braces}. Also, in case you get a "Permission Denied" error - make sure your current local directory is one that you have full rights to. In my case the root of C:\ failed for me as it is a protected location.
    – Mike
    Sep 1 '20 at 4:45
2

They added download-batch option. This is exactly what you need. See https://docs.microsoft.com/en-us/cli/azure/storage/blob?view=azure-cli-latest#az-storage-blob-download-batch

2

Have you tried AZcopy?

AzCopy /Source:https://myaccount.file.core.windows.net/myfileshare/ /Dest:C:\myfolder /SourceKey:key /S
0
1

There is no single command in the Azure CLI that allows you to download all blobs from a container. You can achieve this via your own code as follows:

# Create a directory to store all the blobs
mkdir /downloaded-container && cd /downloaded-container

# Get all the blobs
BLOBS=$(az storage blob list -c $CONTAINER \
    --account-name $ACCOUNT_NAME --sas-token "$SAS_TOKEN" \
    --query [*].name --output tsv)

# Download each one
for BLOB in $BLOBS
do
  echo "********Downloading $BLOB"
  az storage blob download -n $BLOB -f $BLOB -c $CONTAINER --account-name $ACCOUNT_NAME --sas-token "$SAS_TOKEN"
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.