azcopy always creates a folder structure when uploading files - azure

I have a local directory what needs to be synced to a specific folder to my Azure Blob Storage.
Unfortunately azcopy always creates a subfolder in the target directory.
local folder:
C:/local/vacation
Uploadfolder:
xxx.blob.core.windows.net/files/images/jpg
I want all JPGs that are within the local folder into the upload folder.
But azcopy always creates the folder "vacation" in my upload folder :(
This is the code:
$localFolder = "C:/local/vacation"
$targetFolder= "xxx.blob.core.windows.net/files/images/jpg" (# here is the actual SAS URI)
azcopy copy $localfolder $targetfolder --include-pattern "*.jpg" --recursive=true

You can use Sync operation to perform the copy without the directory being created.
azcopy sync "C:\local\vacation" "https://*****.blob.core.windows.net/files/images/jpg/?SAStoken" --include-pattern "*.jpg" --recursive=true
Example:
For the first command as you can see below I ran to sync the jpg files to the destination for the first time , then I added another jpg file in my local machine folder and ran the command for second time it synced the 1 new file to the destination.
The Above highlighted files are present on my local machine directory and when I performed sync they were only copied from local machine to azure and the directory was not created as subfolder.
Reference:
Synchronize with Azure Blob storage by using AzCopy v10

You should be able to use one of the following:
$localFolder = "C:/local/vacation/**"
$targetFolder= "xxx.blob.core.windows.net/files/images/jpg"
azcopy copy $localfolder $targetfolder --include-pattern "*.jpg" --recursive=true
or
$localFolder = "C:/local/vacation/**/*.jpg"
$targetFolder= "xxx.blob.core.windows.net/files/images/jpg"
azcopy copy $localfolder $targetfolder --recursive=true

azcopy copy './*' 'https://xxx.blob.core.windows.net/path/to/dir' --recursive

After trying plenty of stuff. It seems that within the azcopy sync it is not possible.
Only with azcopy copy this works. What a pitty :/

Related

Azure blob storage "az storage copy" fails when having file with same name as folder inside the same directory

I have azure blob container contains a folder with name (data_source), now i'm trying to copy file with the same name to the same container, so i have both the file and the folder together with the same name.
I use this command:
az storage copy -s "$SRC" -d "$DEST" --recursive
Note that i use --recursive because i have other folders to copy as well.
The problem is, everything get copied successfully except the file with the same name as the folder in the container. I tried several ways even with the --recursive flag and didn't work.
May be the az storage copy is confusing files with directories, but i have no clue.
Note: I cannot change the file name, they must be the same.
I created two folders with same name and same blob file name with same contents. I changed one value inside one of my blob file keeping the blob file and folder name same as the other folder and blob file present in another storage account and performed copy operation like below:-
Storage account venkat123 with same folder and file, but file has one extra value test added, Refer below: -
Portal:
Storage Account venkat326 has the same folder data_source and file data_source.json but does not contain test value, refer below:-
Portal:
Now, I used the az storage copy command to copy the folders with same names and the content with value test was added from venkat123 storage account to venkat326 storage account like below:-
Command:-
az storage copy -s "https://venkat123.blob.core.windows.net/test/data_source/data_source.json<SAS-token>" -d "https://venkat326.blob.core.windows.net/demo/data_source/data_source.json<SAS-token>" --recursive
Output:-
Portal:

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

AzCopy Copy from fileshare to blob with file path included in the blob name

Can I copy a directory from a share with subdirectories so that blob name would have the path name?
\\testshare\July\File1.txt
\\testshare\May\File1.txt
\\testshare\June\File3.txt
\\testshare\June\Week3\File3.txt
In the blob container, I want to have
July/File1.text
May/File1.text
June/File3.txt
June/Week3/File3.txt
Never mind, AZCopy does that by default.
AzCopy /Dest:https://myblob.blob.core.windows.net/files /Source:C:\myfolder /DestKey:xzxzxzxzzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxzxz== /S

Resources