0

I am new to powershell. Writting code in azure cloud shell. I want to add files in Azure cloud shell $HOME directory from blob storage. How I can achieve this task?

Really appreciated for help.

To get script to add files into $home directory from azure blob storage in cloud shell

Later Tried azcopy command but getting error as: enter image description here

Code what I tried enter image description here

Chhaya
  • 5
  • 2

1 Answers1

0

To get the script to add files into the $home directory from Azure blob storage in the cloud shell

To get the files from Azure blob storage to the $home directory, you can use the Azcopy tool.

In my environment, Azure blob storage has five files as like below:

enter image description here

Command:

You can use the below command to get the multiple files to your home directory.

 azcopy cp "https://venkat123.blob.core.windows.net/test1/?<Your-sastoken>" "home/" --recursive=true

Output:

INFO: Scanning...
INFO: Any empty folders will not be processed, because the source and/or destination doesn't have full folder support
INFO: azcopy: A newer version 10.19.0 is available to download


Job 3cd8663a-58a1-xx has started
Log file is located at: /home/venkatesan/.azcopy/3cd8663a-xxx.log

0.0 %, 0 Done, 0 Failed, 5 Pending, 0 Skipped, 5 Total, 


Job 3cd8663a-58axxx5931561 summary
Elapsed Time (Minutes): 0.0334
Number of File Transfers: 5
Number of Folder Property Transfers: 0
Total Number of Transfers: 5
Number of Transfers Completed: 5
Number of Transfers Failed: 0
Number of Transfers Skipped: 0
TotalBytesTransferred: 115831
Final Job Status: Completed

enter image description here

Once you execute the above command, you can see the files in your home directory like below:

enter image description here

Reference:

azcopy copy | Microsoft Learn

Venkatesan
  • 3,748
  • 1
  • 3
  • 15
  • Thanks @Venkatesan, I added azcopy cp in my code, got sas token and append it in url, but I am getting error as-- failed to perform copy command due to error: cannot start job due to error: cannot list files due to reason -> github.com/Azure/azure-storage-blob-go/azblob.newStorageError, /usr/src/mariner/BUILD/azure-storage-azcopy-10.15.0/vendor/github.com/Azure/azure-storage-blob-go/azblob/zc_storage_error.go:42 (ServiceCode=AuthenticationFailed) Descr=403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature – Chhaya Jul 18 '23 at 11:33
  • @Chhaya Can you share a snippet of your error? – Venkatesan Jul 18 '23 at 11:34
  • Sure. Added snippet of error in post – Chhaya Jul 18 '23 at 11:42
  • @Chhaya Add command also what you have tried by masking your sas-token. – Venkatesan Jul 18 '23 at 11:48
  • Added code snippet – Chhaya Jul 18 '23 at 12:11
  • @Chhaya I tried with the same format in my environment https://i.imgur.com/XwjPWKF.png and it successfully gets the files from blob storage to the directory, here is my file https://i.imgur.com/Ry8Tk2g.png – Venkatesan Jul 18 '23 at 12:34
  • @Chhaya Check with sas-token once token whether you are getting the correct output. – Venkatesan Jul 18 '23 at 12:40
  • 1
    It worked. I went through your code, added subscriptionID and / in the end of Destination. Thank you so much. – Chhaya Jul 18 '23 at 12:50