How to download a folder in a private container of Azure Storage - azure

I can download all files inside a folder in my storage, if the container is set as annonymous access, using azcopy and the following command:
AzCopy cp https://.blob.core.windows.net/files/modules/ C:\Users\AppData\Roaming\modules --recursive --log-level NONE & azcopy jobs clean
But when I set the container back to private access, it says:
failed to perform copy command due to error: Login Credentials missing. No SAS token or OAuth token is present and the resource is not public
INFO: Removed 0 files.
I know how to generate the SAS for a unique specific file but in this case that I'm downloading a folder, how to proceed?

Please use this command:
AzCopy cp 'https://<your-storage-name>.blob.core.windows.net/container/<folder>?<your-sas-token>' 'C:\Users\AppData\Roaming\modules' --recursive
You can generate SAS token there:

Related

azcopy of directory failing when copying between blob storage and file share - cannot transfer to the root of a service

I am trying to copy an existing directory from a blob storage to a directory already existing in an azure file share via the Azure CLI in the Azure portal
I get the following error
failed to perform copy command due to error: cannot transfer
individual files/folders to the root of a service. Add a container or
directory to the destination URL
What I have tried
azcopy copy ' https://myazurename.blob.core.windows.net/subdirectory' 'https://myazurename.file.core.windows.net/blob-mirror/subdirectory' --recursive
azcopy copy ' https://myazurename.blob.core.windows.net/subdirectory/*' 'https://myazurename.file.core.windows.net/blob-mirror/subdirectory' --recursive
azcopy copy ' https://myazurename.blob.core.windows.net/subdirectory/*' 'https://myazurename.file.core.windows.net/blob-mirror/subdirectory/*' --recursive
Yet everything gives the same error
I tried in my environment and got below results:
Initially I have tried the same commands and got same error:
command:
azcopy copy "https://<storage account name>.blob.core.windows.net/<c ontainer name>/directory1/?[SAS]" "https://<storage account name>.file.core.windows.net/fileshare1/directory1/" --recursive
Console:
Portal:
Blob container:
File share:
After I added SAS in both blob and file url copied files successfully from blobstorage to fileshare:
command:
azcopy copy "https://<storage account name>.blob.core.windows.net/<c ontainer name>/directory1/?[SAS]" "https://<storage account name>.file.core.windows.net/fileshare1/directory1/?[SAS]" --recursive=true
Console:
Portal:
Fileshare:
Update
You can get SAS for both blob and file
Home -> storageaccount -> shared access signature -> check the allowed resource group -> click the generate SAS and Connection string.

azcopy failed to perform copy command due to error: cannot use directory as source without --recursive or a trailing wildcard (/*)

Trying to copy a .vhd between two different storage accounts using SAS. Getting error. Can someone give me a hand please? thank you much
azcopy cp 'https://mystorage.blob.core.windows.net/images/MyDisk.vhd?sv=2019-12-12&ss=bfqt&srt=c&sp=rlx&se=2021-03-12T12:49:12Z&st=2021-02-14T04:49:12Z&spr=https&sig=oahRM1xDHkjgtEo5OjUv64vSPIjI%2BvyqVmdGN9demJc%3D' 'https://1sddq9uificcrb0t.blob.core.windows.net/vhds/MyDisk.vhd?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-03-13T01:02:49Z&st=2021-02-14T17:02:49Z&spr=https&sig=BXBocHkS%2FofwkhgdsvYccPEh0EA6Fpcu0LZd19%2FGwqw%3D'
Returning this error:
INFO: Scanning...
failed to perform copy command due to error: cannot use directory as source without --recursive or a trailing wildcard (/*)
It seems that you copy the VHD file of the disk to another storage account. You could try the command like this without .vhd suffix.
azcopy cp 'https://mystorage.blob.core.windows.net/images/abcd?sv=2019-12-12&ss=bfqt&srt=c&sp=rlx&se=2021-03-12T12:49:12Z&st=2021-02-14T04:49:12Z&spr=https&sig=oahRM1xDHkjgtEo5OjUv64vSPIjI%2BvyqVmdGN9demJc%3D' 'https://1sddq9uificcrb0t.blob.core.windows.net/vhds/abcd?sv=2019-12-12&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-03-13T01:02:49Z&st=2021-02-14T17:02:49Z&spr=https&sig=BXBocHkS%2FofwkhgdsvYccPEh0EA6Fpcu0LZd19%2FGwqw%3D'
Or you can append the --recursive at the end of your command.

Trying to use azcopy for copying file from storage account

Uploaded a .sh file into storage account and trying to get that into rhel vm. I have azcopy version 10.6.1. Command i am using azcopy copy ā€¯https://.blob.core.windows.net/container/test.sh>[SAS token]" . When i run this, it is moving to next line and giving this ">" output. Tried to do in many ways but no luck.
How can we troubleshoot this issue?
The syntax to use "azcopy copy" command is
azcopy copy [source] [destination] [flags]
To download a single file by using a SAS token:
azcopy cp "https://[account].blob.core.windows.net/[container]/[path/to/blob]?[SAS]" "/path/to/file.txt"
To download a single file by using a SAS token and then piping the output to a file (block blobs only):
azcopy cp "https://[account].blob.core.windows.net/[container]/[path/to/blob]?[SAS]" > "/path/to/file.txt"
This is the source of above information.
Related references:
Download blobs from Azure Blob storage by using AzCopy v10
Troubleshoot Azcopy related issues

Download the files in azure using azcopy

I am trying to download the files from the blod container in azure...But its showing Error: Unknowncommand
Cmd:
AzCopy https://forecast.blob.core.windows.net/test C:\Users\Shwettha\Downloads\azcopyfiles /sourceKey:sp=rl&st=2020-07-17T12:17:25Z&se=2020-12-31T21:30:00Z&sv=2019-10-10&sr=c&sig=z9b0X4vT6DGy6zOGNffM5FVaK5jNGOTeFFWD /S /V:C:\temp\logs\azcopy.log
error:
Error: unknown command "https://forecast.blob.core.windows.net/test" for "azcopy"
I also tried
azcopy cp "https://forecast.blob.core.windows.net/test/apollo?si=Utopus&sv=2019-12-12&sr=c&sig=qHv1ojyG2hrjrq7ZQ%2BMAVZhkpCwrXs1" "utopus/apollo/forecast/dayahead" --recursive
Error: is not recognized as an internal or external command,
operable program or batch file.
Can anyone pls help me...to downlaod or list the files in the blob.
iam new to azcopy
Have tried below command
azcopy cp "https://forecast.blob.core.windows.net/test/apollo?si=Utopus&sv=2019-12-12&sr=c&sig=qHv1ojyG2BMAVZhkpCwrXsD" "c:/Users/Shwettha/Downloads/azcopyfiles" --recursive
It seems that you're trying to copy the contents of directory to local.
Here's something you need to check:
1.the version of your azcopy
2.Open your cmd in your computer, and navigate to the location where the azcopy.exe is.
3.the sastoken you're using, please follow the screenshot below to generate the sastoken(In azure portal):
4.suppose you have a blob container named test8, and the container has a directory named ccc. now if you want to download all the blobs inside the directory ccc, please use the command below:
azcopy cp "https://yy1.blob.core.windows.net/test8/ccc?your_sastoken" "d:\bbb" --recursive
Here is the screenshot:

Azcopy: Copying files to an Azure Fileshare using Azcopy 10

I'm trying to copy files to and from an Azure Fileshare using AZCopy v10. I have had this successfully working using v8.1 but I keep getting errors using v10.
From the command line I'm using this to copy a file from the local drive to the fileshare;
c:\Temp\azcopy.exe copy "c:\temp\sample.txt" "https://myfiles.file.core.windows.net/dbfiles/sample.txt?SASKeyText"
This generates the error message;
failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL
I have tried adding a directory to the fileshare and adding that to the command string but I get the same error.
If I reverse the copy from the fileshare to the local drive I get the error;
failed to perform copy command due to error: account copies are an inherently recursive operation, and thus --recursive is required
I have followed the guide at https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-files but haven't been able to see what's wrong.
Thanks in advance for any help.
The error here was with the SAS token and not the form of the command.
I suppose this should be marked up amongst examples of unhelpful error messages.
Thanks to everyone who took the time to have a look.
I had this same issue when trying to do a copy from my local machine to Azure Blob storage.
This was the command I was running:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web" --recursive
But I got the error below:
failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL
Here's how I solved it:
I was missing the ?[SAS] argument at the end of the Blob storage location. So instead of this:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web" --recursive
I had this:
azcopy copy --from-to=LocalBlob "C:\AzureStorageTest\my-app\*" "https://myapptest.blob.core.windows.net/%24web?[SAS]" --recursive
Note:
The format is azcopy copy "/path/to/dir" "https://[account].blob.core.windows.net/[container]/[path/to/directory]?[SAS]" --recursive. You only need to modify the "/path/to/dir", [account] and [container]/[path/to/directory]. Every other thing remains the way they are.
Specify the source-destination routing using the --from-to=LocalBlob (if you're copying from local to blob storage) argument to be explicit about the copy operation.
My actual Blob storage location is https://myapptest.blob.core.windows.net/$24web but I used https://myapptest.blob.core.windows.net/%24web, since $ will throw some error when used, so %24 was used.
That's all.
I hope this helps
Here is a sample azcopy script which worked for me
az storage azcopy blob upload
-c'https://$AZURE_STORAGE_ACCOUNT_NAME.blob.core.windows.net/\\\$web' \
--account-name $AZURE_STORAGE_ACCOUNT_NAME \
-s "build/*" \
--account-key $AZURE_STORAGE_ACCOUNT_ACCESS_KEY \
--recursive
If you get this error while trying to copy to $web container:
"failed to perform copy command due to error: cannot transfer individual files/folders to the root of a service. Add a container or directory to the destination URL"
Per a solution listed here, we need to add an escape character (\) before $web. Following command (to copy all files and subfolders to web container) worked for me:
azcopy copy "<local_folder>/*" "https://******.blob.core.windows.net/\$web/?<SAS token>" --recursive
Without the escape character, the following command fails with the above error.
azcopy copy "<local_folder>/*" "https://******.blob.core.windows.net/$web/?<SAS token>" --recursive

Resources