I try upload file to my Azure storage:
az storage file upload --account-key "KEY" --account-name myaccountname --share-name containername --source .\file.txt
and result has error:
The specified share does not exist.
RequestId:94d9610c-201a-0032-04cb-a736b8000000
Time:2022-08-04T06:26:04.8341637Z
ErrorCode:ShareNotFound
What exactly is "share-name"?
I did think that it is a container name in storage.
Thanks
I think you are confusing between Azure Blob Storage and Azure File Storage. If you want to upload to Azure Blob Storage, you would need to use az storage blob upload.
Your command would be something like:
az storage blob upload --account-key "KEY" --account-name myaccountname --container-name containername --file .\file.txt
Related
Using the az cli within an azvm, I want to be able to list all the files within a specific container blob and then download those files. Let's say I have a container 'top' and then it has several subdirectories such as:
top/sub1/sub2/sub3/
Where in the folder sub3, there are multiple files. I would like to:
List all the files in sub3, and then
Retrieve all of the files in sub3 through the az cli.
I can only list the contents within 'top' with the command:
az storage container list --account-key ${key} --account-name top --query "[].{Name:name}" --output table
az storage container list --> is used to list the containers inside a storage account.
Based on the shared information, we have understood that you are trying to list the blob under the subdirectories(sub1/sub2/sub3) inside a contianer top then you need to use az storage blob directory list cmdlet which is used to List blobs and blob subdirectories in a storage directory.
To test this we have created a storage account with one container (top) and having multiple subdirectories(sub1/sub2/sub3) and we have used the below cmdlet to list the blob inside them.
az storage blob directory list -c top -d sub1/sub2/sub3 --account-name <storageAccountName> --query [].name -o table
Here is the sample output for reference:
Reference documentation for more information about az storage blob directory list cmdlet.
I generated SAS token in Azure Portal and trying to use it to upload files to blob storage:
az storage blob upload-batch --source ./test --destination '$web' --account-name 'myaccountname' --sas-token '"sp=racwl&st=2022-02-22T17:04:19Z&se=2022-12-23T01:04:19Z&spr=https&sv=2020-08-04&sr=c&sig=mXXXXXXXXXXXXXXXXXXXXXXXXXXONfAA%3D"'
But above command gives me following error in PowerShell:
<AuthenticationErrorDetail>Signature fields not well formed.</AuthenticationErrorDetail>
I am literally copying the SAS Token from Azure Portal so how on earth can it be malformed?
We have ran the same az storage blob upload-batch cmdlet in our local environment( which is running with powershell v5.1) & we are able to upload the files from local machine to the storage account as shown in below.
Here is the cmdlet we have used :
az storage blob upload-batch --account-name <strgAccountName> -s <sourcefilepath> -d 'https://xxxxxx.blob.core.windows.net/cont1' --sas-token '<generatedSAStoken from portal>'
Here is the sample Output for reference:
Note:
To the above cmdlet, We have tried passing the SAS token with appending(single quote+ question mark) '?' & without passing in single quote's to the --sas-token flag in both the cases we are able to upload the files from local machine to Azure storage container.
I don't know what was wrong, but suddenly it started to work with '"sastoken"' format. Thanks for your responses.
I would like to export an azure vm disk directly to an azure blob storage? I have checked on the internet but i couldn't find a way.
I can download the disk to my local PC and then upload to blob storage. But it takes long time and manual work. So i am checking a more direct way. Maybe with Azure Storage Explorer? The disk and blob storage are in the same region.
Because there is a SAS download link of vm disk, i can paraphrase my question as:
Is there a way to transfer a file directly to blob storage by using a
url?
Do you have any suggestions?
If you know the Azure disk's SAS download link, we can use Azure CLI command az storage blob copy start or command-line utility AzCopy to upload the disk as vhs file to Azure blob storage.
For example
az login
#Provide the name of your resource group where managed disk is created
resourceGroupName=myResourceGroupName
#Provide the managed disk name
diskName=myDiskName
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
sasExpiryDuration=3600
#Provide storage account name where you want to copy the underlying VHD file of the managed disk.
storageAccountName=mystorageaccountname
#Name of the storage container where the downloaded VHD will be stored
storageContainerName=mystoragecontainername
#Provide the key of the storage account where you want to copy the VHD
storageAccountKey=mystorageaccountkey
#Provide the name of the destination VHD file to which the VHD of the managed disk will be copied.
destinationVHDFileName=myvhdfilename.vhd
#Generate the SAS for the managed disk
sas=$(az disk grant-access --resource-group $resourceGroupName --name $diskName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)
#Copy the VHD of the managed disk to the storage account
az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas
# check copy status
az storage blob show -n $destinationVHDFileName -c $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey
I want to list (programmatically) the url of my blob storage. The url I am looking for is https://my_storageaccount_name.blob.core.windows.net/my_container_name/my_file_name
I tried az storage account list and az storage blob show but neither of them display the url.
There is a az storage blob url but that creates a url. I am interested in listing the url.
Does anyone know how to obtain this ?
If the url for the blobs is always
https://my_storageaccount_name.blob.core.windows.net/my_container_name/my_file_name
without any custom domains configured, just list all containers with blobs, take the container name and blob name, and put it in the URL.
Ref: https://my_storageaccount_name.blob.core.windows.net/my_container_name/my_file_name
You can get Storage account URL Using
az storage account show --name $storage_account_name --resource-group $ResourceGroup --query "primaryEndpoints.blob")
or all the properties without using query from which you can pick whichever property you want
az storage account show --name $storage_account_name --resource-group $ResourceGroup
I am trying to copy a managed disk snapshot to different region using the Azure command line and it fails with the following error - "The entity was not found"
Here is the command I am using
az snapshot create --resource-group test-azstdsouthcentral --name testcopy3 --location WestUS2 --source /subscriptions/xxx/resourceG
roups/test-azstdsouthcentral/providers/Microsoft.Compute/snapshots/testcopy
Is it supported to copy a managed disk snapshot to a separate region?
Is it supported to copy a managed disk snapshot to a separate region?
You can't create snapshot to different region.
But you can create snapshot to the same region, then copy the snapshot as VHD to a storage account in different region, then create a managed disk from a VHD.
Sample script:
#Provide the subscription Id where snapshot is created
subscriptionId=dd80b94e-0463-4a65-8d04-c94f403879dc
#Provide the name of your resource group where snapshot is created
resourceGroupName=myResourceGroupName
#Provide the snapshot name
snapshotName=mySnapshotName
#Provide Shared Access Signature (SAS) expiry duration in seconds e.g. 3600.
#Know more about SAS here: https://learn.microsoft.com/en-us/azure/storage/storage-dotnet-shared-access-signature-part-1
sasExpiryDuration=3600
#Provide storage account name where you want to copy the snapshot.
storageAccountName=mystorageaccountname
#Name of the storage container where the downloaded snapshot will be stored
storageContainerName=mystoragecontainername
#Provide the key of the storage account where you want to copy snapshot.
storageAccountKey=mystorageaccountkey
#Provide the name of the VHD file to which snapshot will be copied.
destinationVHDFileName=myvhdfilename
az account set --subscription $subscriptionId
sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)
az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $storageAccountName --account-key $storageAccountKey --source-uri $sas
More information about export/copy managed snapshots as VHD to a storage account in different region, please refer to this link.
More information about create a managed disk from a VHD, please refer to this link.