SAS URI gets broken when trying to upload the vhd to blob container in a storage account

368 Views Asked by At

I am using a bash script ot upload a vhd to blob container in a storage account.

Steps:

  • I created a VM, Storage account, container with blob acces, and snapshot. From the VM created, I'm generating one SAS URI by taking a snapshot of the VM Disk.

  • After SAS URI is generated I'm trying to upload it to the storage account container using below CLI Command:

$sas=$(az snapshot grant-access --resource-group $resourceGroupName --name $snapshotName --duration-in-seconds $sasExpiryDuration --query [accessSas] -o tsv)

I verified the value of $sas in the terminal it's printing the correct value. But when try the below command.

az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $accountname --account-key $key --source-uri $sas

The SAS URI is a very large string. Wherever I see '&' in SAS URL the string after it gets separated.

Let's say the string is like `abc&sr63663&si74883&sig74848`

I'm getting the error:

sr is not recognized as internal or external command. Si is not recognized as internal or external command. Sig is not recognized as internal or external command.

Please help me with how I can pass the SAS URI properly in the last command mentioned through the bash script. 
1

There are 1 best solutions below

0
Sridevi On

I tried to reproduce the same in my environment and got the same error as below:

enter image description here

To resolve the error, try wrapping the SAS token separately with single quotes followed by double quotes like below:

$sastoken=' " your_sas_token" '

az storage blob copy start --destination-blob $destinationVHDFileName --destination-container $storageContainerName --account-name $accountname --account-key $key --source-uri $sastoken

After executing the above script, vhd file uploaded to blob container successfully like below:

enter image description here

To confirm the above, Go to the Azure Portal and check the blob container like below:

enter image description here

Reference:

How to provide a SAS token to Azure CLI by Jon Tirjan