Loading, please wait...

A to Z Full Forms and Acronyms

Azure blob storage create and copy data using Azure CLI

Jun 24, 2021 Azure blob Storage, Azure CLI, Azure, 4618 Views
In this article, you will learn how to create an Azure storage account, container and copy data in batch from one container to another container in the same storage account and copy data from one container to another in the different storage account.

How to create a storage account, container and move data between storage accounts or containers using Azure CLI

In this article, you will learn how to create an Azure storage account, container and copy data in batch from one container to another container in the same storage account and copy data from one container to another in the different storage account.


Step1: Login your Azure Portal to type below command in Azure CLI 
PS C:\Users\Viren2302> az login

Output
Note, we have launched a browser for you to login. For old experience with device code, use "az login --use-device-code"
You have logged in. Now let us find all the subscriptions to which you have access...

[
{
"cloudName": "AzureCloud",
"id": "55d900cb-4dec-48b9-bbfa-679afdff919",
"isDefault": true,
"name": "Free Trial",
"state": "Enabled",
"tenantId": "347dfd-4df2-41e8-af80-a7bae1940460",
"user": {
"name": "virendra.gour1124@gmail.com",
"type": "user"
}
}
]

Step2: Create a resource group to type below command

PS C:\Users\Viren2302> az group create --name tutorialslink-rg --location eastus

Output

{
"id": "/subscriptions/55dsgfgdb-4dec-48b9-bbfa-6dfsjdh919/resourceGroups/tutorialslink-rg",
"location": "eastus",
"managedBy": null,
"name": "tutorialslink-rg",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null,
"type": null
}


Step3: Create a storage account

PS C:\Users\Viren2302> az storage account create --location eastus --name tutorialslinkaccount --resource-group tutorialslink-rg --sku Standard_RAGRS --kind BlobStorage --access-tier Hot

Output

{
"accessTier": "Hot",
"azureFilesIdentityBasedAuthentication": null,
"creationTime": "2019-09-15T07:58:18.690690+00:00",
"customDomain": null,
"enableHttpsTrafficOnly": true,
"encryption": {
"keySource": "Microsoft.Storage",
"keyVaultProperties": null,
"services": {
"blob": {
"enabled": true,
"lastEnabledTime": "2019-09-15T07:58:18.768782+00:00"
},
"file": {
"enabled": true,
"lastEnabledTime": "2019-09-15T07:58:18.768782+00:00"
},
"queue": null,
"table": null
}
},
"failoverInProgress": null,
"geoReplicationStats": null,
"id": "/subscriptions/5djdsfsdg0cb-dfdc-dfb9-bbfa-679xc919/resourceGroups/tutorialslink-rg/providers/Microsoft.Storage/storageAccounts/tutorialslinkaccount",
"identity": null,
"isHnsEnabled": null,
"kind": "BlobStorage",
"lastGeoFailoverTime": null,
"location": "eastus",
"name": "tutorialslinkaccount",
"networkRuleSet": {
"bypass": "AzureServices",
"defaultAction": "Allow",
"ipRules": [],
"virtualNetworkRules": []
},
"primaryEndpoints": {
"blob": "https://tutorialslinkaccount.blob.core.windows.net/",
"dfs": "https://tutorialslinkaccount.dfs.core.windows.net/",
"file": null,
"queue": null,
"table": "https://tutorialslinkaccount.table.core.windows.net/",
"web": null
},
"primaryLocation": "eastus",
"provisioningState": "Succeeded",
"resourceGroup": "tutorialslink-rg",
"secondaryEndpoints": {
"blob": "https://tutorialslinkaccount-secondary.blob.core.windows.net/",
"dfs": "https://tutorialslinkaccount-secondary.dfs.core.windows.net/",
"file": null,
"queue": null,
"table": "https://tutorialslinkaccount-secondary.table.core.windows.net/",
"web": null
},
"secondaryLocation": "westus",
"sku": {
"capabilities": null,
"kind": null,
"locations": null,
"name": "Standard_RAGRS",
"resourceType": null,
"restrictions": null,
"tier": "Standard"
},
"statusOfPrimary": "available",
"statusOfSecondary": "available",
"tags": {},
"type": "Microsoft.Storage/storageAccounts"
}

Step5: Get the storage account keys


PS C:\Users\Viren2302> az storage account keys list --resource-group tutorialslink-rg --account-name tutorialslinkaccount --output table

Output
KeyName Permissions Value
--------- ------------- ----------------------------------------------------------------------------------------
key1 Full zKhSwra658aqSXqVkCrnwu7eCsRNzxSjG0Rb6QfdQ8vT28j/DX9LAWfaU7ABzuiaWj3okSXEsLeJm9jv3rFfmcQ==
key2 Full ZbsoxAZX4uzCZJ0KjC5x4cr2cvBuzO5SHhTp1Tbdfnjkq8TdPlTFYFEgKM6x2w1GYRehwY+EALie0T3LFvYJCKNg==

Step6: Create a container
PS C:\Users\Viren2302> az storage container create --name tutorialslink-c --account-name tutorialslinkaccount --account-key zKhSwra658aqSXqVkCrnwu7eCsRNzxSjG0Rb6QQ8vT28nj/DX9LAWfaU7ABzuiaWj3okSXEsLeJm9jv3rFfmcQ==

Output
{
"created": true
}


Step7: Upload blobs in containers from your computer's drive


PS C:\Users\Viren2302> az storage blob upload-batch --destination tutorialslink-c --pattern "*.PNG" --source "E:\Azure Stuff\Articals\Blob Storage\Blob" --account-name tutorialslinkaccount --account-key zKhSwra658aqSXqVkCrnwu7eCsRNzxSjG0Rb6QQ8vT28nj/DX9LAWfaU7ABzuiaWj3okSXEsLeJm9jv3rFfmcQ==

Output
Finished[#############################################################] 100.0000%
[
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob1.PNG",
"Last Modified": "2019-09-15T08:02:18+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B307A5ACD7\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob10.PNG",
"Last Modified": "2019-09-15T08:02:19+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B307E88E71\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob11.PNG",
"Last Modified": "2019-09-15T08:02:19+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B3080E93E9\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob2.PNG",
"Last Modified": "2019-09-15T08:02:19+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B30834241D\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob3.PNG",
"Last Modified": "2019-09-15T08:02:19+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B308571BD0\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob4.PNG",
"Last Modified": "2019-09-15T08:02:20+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B30879C54F\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob5.PNG",
"Last Modified": "2019-09-15T08:02:20+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B3089C6ED6\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob6.PNG",
"Last Modified": "2019-09-15T08:02:20+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B308C38605\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob7.PNG",
"Last Modified": "2019-09-15T08:02:20+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B308E6F300\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob8.PNG",
"Last Modified": "2019-09-15T08:02:20+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B3090A11D0\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/blob9.PNG",
"Last Modified": "2019-09-15T08:02:21+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B30934FA3E\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/cli-copy1.PNG",
"Last Modified": "2019-09-15T08:02:21+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B3095B4DFA\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/cli-copy2.PNG",
"Last Modified": "2019-09-15T08:02:21+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B3098572F4\""
},
{
"Blob": "https://tutorialslinkaccount.blob.core.windows.net/tutorialslink-c/Storage.png",
"Last Modified": "2019-09-15T08:02:22+00:00",
"Type": "image/png",
"eTag": "\"0x8D739B309A75914\""
}
]


Step8: Create a destination container in which we will copy blobs from the source container


PS C:\Users\Viren2302> az storage container create --name desttutorialslink-c --account-name tutorialslinkaccount --account-key zKhSwra658aqSXqVkCrnwu7eCsRNzxSjG0Rb6QQ8vT28nj/DX9LAWfaU7ABzuiaWj3okSXEsLeJm9jv3rFfmcQ==

Output
{
"created": true
}

Step9: Copy blobs in batch from source container to destination container


PS C:\Users\Viren2302> az storage blob copy start-batch --destination-container desttutorialslink-c --account-name tutorialslinkaccount --account-key zKhSwra658aqSXqVkCrnwu7eCsRNfdsSjG0Rb6QQ8vT28nj/DX9dfWfaU7Afdsuidj3okSXEsLeJm9jv3rFfmcQ== --source-container tutorialslink-c --pattern *.PNG

Output

[
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/Storage.png",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob1.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob10.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob11.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob2.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob3.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob4.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob5.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob6.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob7.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob8.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/blob9.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/cli-copy1.PNG",
"https://tutorialslinkaccount.blob.core.windows.net/desttutorialslink-c/cli-copy2.PNG"
]

 

 

 

 

 

Step10: Create one more storage account to move blobs in a different storage account.


PS C:\Users\Viren2302> az storage account create --location eastus --name desttutorialslinkacc --resource-group tutorialslink-rg --sku Standard_RAGRS --kind BlobStorage --access-tier Hot

Output
{
"accessTier": "Hot",
"azureFilesIdentityBasedAuthentication": null,
"creationTime": "2019-09-15T08:10:23.494877+00:00",
"customDomain": null,
"enableHttpsTrafficOnly": true,
"encryption": {
"keySource": "Microsoft.Storage",
"keyVaultProperties": null,
"services": {
"blob": {
"enabled": true,
"lastEnabledTime": "2019-09-15T08:10:23.572999+00:00"
},
"file": {
"enabled": true,
"lastEnabledTime": "2019-09-15T08:10:23.572999+00:00"
},
"queue": null,
"table": null
}
},
"failoverInProgress": null,
"geoReplicationStats": null,
"id": "/subscriptions/55fdsfcb-4dec-4ff9-bbfa-67dfsdf44fd19/resourceGroups/tutorialslink-rg/providers/Microsoft.Storage/storageAccounts/desttutorialslinkacc",
"identity": null,
"isHnsEnabled": null,
"kind": "BlobStorage",
"lastGeoFailoverTime": null,
"location": "eastus",
"name": "desttutorialslinkacc",
"networkRuleSet": {
"bypass": "AzureServices",
"defaultAction": "Allow",
"ipRules": [],
"virtualNetworkRules": []
},
"primaryEndpoints": {
"blob": "https://desttutorialslinkacc.blob.core.windows.net/",
"dfs": "https://desttutorialslinkacc.dfs.core.windows.net/",
"file": null,
"queue": null,
"table": "https://desttutorialslinkacc.table.core.windows.net/",
"web": null
},
"primaryLocation": "eastus",
"provisioningState": "Succeeded",
"resourceGroup": "tutorialslink-rg",
"secondaryEndpoints": {
"blob": "https://desttutorialslinkacc-secondary.blob.core.windows.net/",
"dfs": "https://desttutorialslinkacc-secondary.dfs.core.windows.net/",
"file": null,
"queue": null,
"table": "https://desttutorialslinkacc-secondary.table.core.windows.net/",
"web": null
},
"secondaryLocation": "westus",
"sku": {
"capabilities": null,
"kind": null,
"locations": null,
"name": "Standard_RAGRS",
"resourceType": null,
"restrictions": null,
"tier": "Standard"
},
"statusOfPrimary": "available",
"statusOfSecondary": "available",
"tags": {},
"type": "Microsoft.Storage/storageAccounts"
}


Step11: Again get the keys of the storage account


PS C:\Users\Viren2302> az storage account keys list --account-name desttutorialslinkacc --resource-group tutorialslink-rg --output table

Output
KeyName Permissions Value
--------- ------------- ----------------------------------------------------------------------------------------
key1 Full gU+g4SWrSGu3X3djuTkXRaKGUwaLKDPEN7TgvQqzP68FIWqzNzsYbxxy50PuftKWDioqdd2zwgQC47WCtx+Lzw==
key2 Full 3+4Ww1UJUNpJSLdPbBdLnWIm0+kQAGMFdVOung0iOLptvQia/Tdt4tTpoACYkfw7MYOGCv97JDCvCHlhFgihXg==

 

Step12: Create a container in the new storage account


PS C:\Users\Viren2302> az storage container create --name desttutorialslink-c --account-name desttutorialslinkacc --account-key gU+g4SWrSGu3X3djuTkXRaKGUwaLKDPEN7TgvQqzP68FIWqzNzsYbxxy50PuftKWDioqdd2zwgQC47WCtx+Lzw==

Output
{
"created": true
}

Step13: use below command to copy blobs from one storage account to another

PS C:\Users\Viren2302> az storage blob copy start-batch --destination-container desttutorialslink-c --account-name desttutorialslinkacc --account-key gU+g4SWrSGu3X3djuTkXRaKGUwaLKDPEN7TgvQqfsdfsdfzNzsYbxxy50PuftKWDioqdd2zwgQC47WCtx+Lzw== --source-account-name tutorialslinkaccount --source-account-key zKhSwra658aqSXqVkCrnwu7eCsRNdfsdf0Rb6QQ8vT28nj/DX9LAWfaU7ABzuiaWj3okSXEsLeJm9jv3rFfmcQ== --source-container tutorialslink-c

Output

[
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/Storage.png",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob1.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob10.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob11.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob2.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob3.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob4.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob5.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob6.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob7.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob8.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/blob9.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/cli-copy1.PNG",
"https://desttutorialslinkacc.blob.core.windows.net/desttutorialslink-c/cli-copy2.PNG"
]

 

 

 

I hope this will help you to create a storage account, container, upload blobs and move data around.

Thank You

A to Z Full Forms and Acronyms