4

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 
Julian
  • 57
  • 3
  • 6
  • You should try azcopy copy "C:\local\vacation\*" That should achieve what they're trying to do with that operation-- It'll just strip the parent directory from the destination – SumanthMarigowda-MSFT Jul 12 '21 at 17:27
  • Ok, I tried it. Unfortunately it still creates the folder. I hoped that it directly uploads all the images flat into the destionation folder. But it always creates the folder name of the origin :( Any other idea @sumanthMarigodwa-MFST – Julian Jul 16 '21 at 08:38
  • 1
    I also tried "C:\local\vacation\*" and "C:\local\vacation\" Didnt work either :/ – Julian Jul 16 '21 at 08:42

4 Answers4

1

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.

enter image description here

enter image description here

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

Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27
  • 2
    Azure Pipelines don't have a sync option. – Erik Philips Sep 15 '21 at 17:56
  • Hello @ErikPhilips,yes you are correct but the ask is not for azure pipelines. – Ansuman Bal Sep 15 '21 at 18:19
  • 1
    Correct, that's why I made a comment and still upvoted. – Erik Philips Sep 15 '21 at 18:25
  • 1
    I think this is not working. Here again the problem. I have a folder that looks like this C:\photos\2021 and C:\photos\2021 . Within those folders i have some sub folders with images (JPG). I want to upload ALL JPGs to a destination folder in cloud without all the subfolders. So the new structure is like xxx.blob.core.windows.net/files/images/jpg/image1.jpg and so on. But azcopy sync always copies also the folder structure :( – Julian Nov 02 '21 at 13:31
0

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 
Erik Philips
  • 53,428
  • 11
  • 128
  • 150
  • I receive in both cases: Cannot perform sync due to error: sync must happen between source and destination of the same type, e.g. either file <-> file, or directory/container <-> directory/container – Julian Nov 02 '21 at 13:25
0

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 :/

Julian
  • 57
  • 3
  • 6
-1
azcopy copy './*' 'https://xxx.blob.core.windows.net/path/to/dir' --recursive
n0099
  • 520
  • 1
  • 4
  • 12