19

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]'?

Evert
  • 1,355
  • 3
  • 11
  • 14

4 Answers4

19

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
Varun Nair
  • 103
  • 4
  • 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 01 '20 at 04:45
2

Have you tried AZcopy?

AzCopy /Source:https://myaccount.file.core.windows.net/myfileshare/ /Dest:C:\myfolder /SourceKey:key /S
Worthwelle
  • 4,538
  • 11
  • 21
  • 32
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

stej
  • 221
  • 1
  • 5
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
Saca
  • 119
  • 4