Using AZCopy with an Azure WebApp
How to copy data from a Azure Linux Web App using Microsoft’s AZCopy utility.
There’s probably many reasons why you might want to do this. I was faced with a WebApp where the FTPS and Kudu file explorer were both misbehaving but the SSH console was fine. I wanted to extract the contents of the site to a storage account just-in-case before proceeding with any troubleshooting. The method below could also easily be adapted to upload files to a WebApp from a storage account if that was required.
For this to work we need an Azure Linux-based WebApp and a Storage Account with a Blob container ready for use.
Open an SSH session on the WebApp using the Azure Portal.
It’s possible to move all the individual files, but you can also create a single tar archive of the site as follows
1tar -cvf myarchive.tar /home/site
- Download and extract the AZCopy utility. This requires
wgetwhich (oddly) isn’t present in apps using the PHP 7.0 framework, but is on those using PHP 7.4.
1wget https://aka.ms/downloadazcopy-v10-linux -O azcopy.tar 2tar -xvf azcopy.tar
- Use the Azure Portal to obtain a Shared Access Signature (SAS) for the container in the storage account. To do this navigate to the Container in the portal,
select the “Shared access tokens” blade. You need to set at least the “Permissions” section to allow writes, but the defaults elsewhere should work unless you
need to restrict access further. Click on the
Generate SAS token and URLand then copy the
Blob SAS URLfield from the bottom of the page for use in the next step.
- Use the downloaded
azcopycommand to copy the archive of your site to the container on the storage account (be aware the folder name may be different in your download if the current version is different, so replace the
10.13.0bit as appropriate). Replace the URL in this command with the URL SAS copied from the Portal in the previous step.
1azcopy_linux_amd64_10.13.0/azcopy copy "./myarchive.tar" "https://mystorageaccount.blob.core.windows.net/mycontainer?THE-REST-OF-THE-SAS"
- Check the file is in the storage account as expected and you’re done.
If you would like to build a demo environment for testing this out, check out this Gist on Github which contains some sample code that can be run from CloudShell.