POSTS

The two Azure azcopy command tips that ...

… I really had to search for!

The AzCopy is a command line application used to mass copy files to Microsoft Azure Storage Account.

But there are two quirks related with the specific storage container $web used for hosting static websites.

This is the command I use to copy files is:

PS:> azcopy /source:c:\wrk\blog\public\ /dest:https://eduardoramalho.blob.core.windows.net/`$web /SetContentType /V /destkey:*** /S 

The first tip is to use grave accent character (`) just before $web, when running command inside powershell. Not using it, you will see the following kind of errors while copying files:

PS C:\wrk\blog> azcopy /source:c:\wrk\blog\public\ /dest:https://eduardoramalho.blob.core.windows.net/$web ...

[2018/11/03 11:39:03][ERROR] c:\wrk\blog\public\about\index.html: The transfer failed.
The requested URI does not represent any resource on the server.
HttpStatusMessage:The requested URI does not represent any resource on the server.
RequestId:8892c91b-101e-0041-3e69-73b5c2000000
Time:Sat, 03 Nov 2018 11:39:03 GMT

...

[2018/11/03 11:39:03] Transfer summary:
-----------------
Total files transferred: 38
Transfer successfully:   4
Transfer skipped:        0
Transfer failed:         34
Elapsed time:            00.00:00:01
[2018/11/03 11:39:03][WARNING] Error happened in several transferring, refer to C:\Users\Eduardo\AppData\Local\Microsoft\Azure\AzCopy\AzCopyVerbose.log for detailed information.

If you check the azcopy generated log file there is a clue for what is going on:

[2018/11/03 11:39:02.356+00:00][VERBOSE] 8.1.0 : AzCopy /source:c:\wrk\blog\public\ /dest:https://eduardoramalho.blob.core.windows.net/ /destkey:*** /S /SetContentType /V
...
[2018/11/03 11:39:03.600+00:00][VERBOSE] Finished transfer: c:\wrk\blog\public\404.html => https://eduardoramalho.blob.core.windows.net/$root/404.html
[2018/11/03 11:39:03.600+00:00][VERBOSE] Finished transfer: c:\wrk\blog\public\index.xml => https://eduardoramalho.blob.core.windows.net/$root/index.xml
[2018/11/03 11:39:03.600+00:00][VERBOSE] Finished transfer: c:\wrk\blog\public\index.html => https://eduardoramalho.blob.core.windows.net/$root/index.html
[2018/11/03 11:39:03.600+00:00][VERBOSE] Finished transfer: c:\wrk\blog\public\sitemap.xml => https://eduardoramalho.blob.core.windows.net/$root/sitemap.xml
[2018/11/03 11:39:03.616+00:00] Transfer summary:
-----------------
Total files transferred: 38
Transfer successfully:   4
Transfer skipped:        0
Transfer failed:         34
Elapsed time:            00.00:00:01

If you look closely, azcopy is trying to copy files to “https://eduardoramalho.blob.core.windows.net/$root". It was expected to be “/$web”.

The explanation is that powershell interprets $web as a variable that will be translated to some value, before executing the command. Because there is no value defined then is translated to empty. So, the real azcopy comand that is executed behind the scenes is “azcopy /source:c:\wrk\blog\public\ /dest:https://eduardoramalho.blob.core.windows.net/ …” (with no $web visible).

To not allow powershell to interpret $web as variable, but use it literally, we must prefix it the grave accent character (`). So is “`$web”.

The second tip is to use parameter “/SetContentType”.

If you did not use it, when trying to check your azure static web page, the browser will reply with a download of a file. It does that because most of HTML files is identified on azure storage container as binary (and not as text). The web server, then whould delivery the web page, as a file download.

The download page situation

If we check the Azure Storage Static Web Page account, we can see that all files are of type “application/octet-stream” (aka binary).

The azure stoage octet-stream type

comments powered by Disqus