Notice: Only variables should be assigned by reference in G:\Web\AzureTechGuy\plugins\content\jhimagepopup\jhimagepopup.php on line 90 Notice: Undefined property: stdClass::$introtext in G:\Web\AzureTechGuy\plugins\content\jhimagepopup\jhimagepopup.php on line 108

Notice: Only variables should be assigned by reference in G:\Web\AzureTechGuy\plugins\content\jhimagepopup\jhimagepopup.php on line 90

Here is how you can copy files from one Azure Storage account to another. Simple scenario for this is if you want to move entirely from one Storage account to another. In my case I was running for quite some time on a Gen1 Blob-only storage account and now i want to be on the new modern Gen2 general purpose storage account.

Requirements

  • Acces to source and destination storage accounts

Preparations

We want to move the data securely and quickly so the best choice is just by using Azure CLI, the AzCopy commands and SAS tokens to authenticate the requests.

Go to your source Azure Storage account and go to Shared access signature blade

shared access signature blade

Then create a SAS token. Basically what we aim for is to create a token which will allow access for only a limited period of time. By default we are offered one for 8 hours and with read/write access to all possible objects within the Storage account. Feel free to tweak any of the parameters or just leave them default, just like I do in the below screenshot.

When ready click on the "Generate SAS and connection string button" and copy the SAS Token somewhere, preferrably in Notepad so we can build the AzCopy command later.

generate SAS token

Now repeat this for the same for your destination Azure Storage account.

You have the two SAS tokens. Let's build the command that we are going to use.

The command itself is in this format

azcopy copy "https://NAMEOFSOURCESTORAGEACCOUNT.blob.core.windows.net?SASTOKEN" "https://NAMEOFDESTINATIONSTORAGEACCOUNT.blob.core.windows.net?SASTOKEN" --recursive

replace the values with your own. Beware of double (??) quotation marks after the windows.net??sv= in the URL. You should only have one. Here is how the full command should look like

azcopy copy "https://source.blob.core.windows.net?sv=2019-02-02&ss=b&srt=sco&sp=rwdlac&se=2020-01-15T17:39:31Z&st=2020-01-15T09:39:31Z&spr=https&sig=HwZ6zPz%2FuDsBWsnwoxVl8P1DQEVP1FlQ6Ke2DXL5jqk%3D" "https://destination.blob.core.windows.net?sv=2019-02-02&ss=bfqt&srt=sco&sp=rwdlacup&se=2020-01-15T17:35:44Z&st=2020-01-15T09:35:44Z&spr=https&sig=iLfQbUAAION9ZVSRSP5dBqGtiz32wUEPUAbIYv9iD%2Bk%3D" --recursive

With the command ready and copied to your clipboard, open a Bash session in your Azure Portal.

Azure bash portal

After loading, paste your command and hit enter

AzCopy command

You should see a progress of the ongoing transfer

AzCopy details

and it should run successfully and complete

AzCopy command success

That's it! Congrats. Check your destination storage account if the data is present. For me it is and it's quite a relief to do it so easy.

If you want to have a more specific copy (not just the entire storage account) read the official docs on AzCopy.

In general it should be as easy as specifying your container name in your URL. Such as https://<storage-account-name>.blob.core.windows.net/<container-name>. You can go as deep as /<container-name>/<blobdirectory>.

This also works for uploading files from local storage to Azure Storage account

azcopy copy 'C:\myDirectory' 'https://mystorageaccount.blob.core.windows.net/mycontainer/myBlobDirectory' --recursive