AZ Cheat Sheet: Difference between revisions

From Coolscript
Jump to navigation Jump to search
Line 10: Line 10:


=Storage-Account=
=Storage-Account=
*List Storage Account
az storage account list --query [*].name --output tsv
az storage account list --query [*].primaryLocation --output tsv
az storage account list --query [*].resourceGroup --query [*].name
*Create Storage Account
*Create Storage Account
  az storage account create --location eastus --name ContainerName --resource-group RG --sku Standard_RAGRS --kind BlobStorage --access-tier Hot
  az storage account create --location eastus --name ContainerName --resource-group RG --sku Standard_RAGRS --kind BlobStorage --access-tier Hot
Line 49: Line 55:
   az storage blob download -n $BLOB -f /mnt/d/test/$BLOB -c ContainerName --account-name StorageAccountName --account-key xyz==
   az storage blob download -n $BLOB -f /mnt/d/test/$BLOB -c ContainerName --account-name StorageAccountName --account-key xyz==
  done
  done


=Links=
=Links=
*https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/storage/files/storage-how-to-use-files-cli.md
*https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/storage/files/storage-how-to-use-files-cli.md
*https://github.com/Azure/azure-cli-samples/blob/master/storage/blobs.md
*https://github.com/Azure/azure-cli-samples/blob/master/storage/blobs.md

Revision as of 16:57, 15 January 2021

Login and Subscription

az login --use-device-code
az account show
  • Set Subscription
az account set --subscription SubscriptionName


Storage-Account

  • List Storage Account
az storage account list --query [*].name --output tsv
az storage account list --query [*].primaryLocation --output tsv
az storage account list --query [*].resourceGroup --query [*].name
  • Create Storage Account
az storage account create --location eastus --name ContainerName --resource-group RG --sku Standard_RAGRS --kind BlobStorage --access-tier Hot
  • Get Keys
az storage account keys list --resource-group RG --account-name ContainerName --output table
  • Create Container
az storage container create --name Container-Name --account-name Storage-Account-Name --account-key xyz==
  • Copy Data from local to Container
az storage blob upload-batch --destination Container-Name --pattern "*.exe" --source "c:\Users\admin\Downloads" --account-name Storage-Account-Name --account-key xyz==
  • Copy data between two container within the same Storage-Account
az storage blob copy start-batch --destination-container Container-Name --account-name Storage-Account-Name --account-key xyz== --source-account-name Storage-Account-Name --source-account-key xyz== --source-container Container-Name
  • Copy data between two storage accounts
az storage blob copy start-batch --destination-container Container-Name --account-name Storage-Account-Name --account-key xyz== --source-account-name Storage-Account-Name --source-account-key xyz== --source-container ContainerName
  • List Blob data (BASH)
az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz==
  • List Blob data (BASH), Filenames only
az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz== --query [*].name --output tsv
  • List Blob data and put it into an Array (BASH), watch the query and output
BLOBS=$(az storage blob list -c Container-Name --account-name Storage-Account-Name --account-key xyz== --query [*].name --output tsv)
  • List Array data
for BLOB in $BLOBS
do
 echo "$BLOB"
done
  • List Array data and download to /mnt/d/test/
for BLOB in $BLOBS
do
 echo "Download: $BLOB"
 az storage blob download -n $BLOB -f /mnt/d/test/$BLOB -c ContainerName --account-name StorageAccountName --account-key xyz==
done

Links