Contents of this Article
A while ago, I wrote about how to move VHD images from one Azure subscription to another. In this blog post, I will outline how to copy data from one Azure storage account in one subscription to another storage account in another Azure subscription.
The scenario is the following:
You need to copy large files across many directories from one storage account in one subscription to another storage account in another Azure subscription, and both are in the same region. This could be in another Azure region as well, but the performance won’t be the same.
For this scenario, we will make use of AzCopy tool which is a command-line utility that you can use to copy blobs or files to or from a storage account. If you are new to this tool, then make sure to check the get started document from Microsoft here.
The prerequisites are very simple as follows:
- Download AzCopy V10 from here, or jump into Azure Cloud Shell session, AzCopy is included as part of cloud shell.
- Download Microsoft Azure Storage Explorer from here if you don’t have it yet, we will use it to create the Shared Access Signature (SAS) tokens. You can also generate SAS tokens using the Azure Portal, as well as using PowerShell. Personally, I prefer to use Azure Storage Explorer to generate SAS tokens. As a side note, SAS is more secure than the storage account key. One of the main reasons is with SAS, you can ACL the IPs that can access the account, you can control the permissions on the account in a more granular fashion, and when the token will expire, as well as which service you want to have access to (Blobs, Files, Queues, Tables). Please note that SAS tokens are signed with your key, so invalidating your storage account key should invalidate the SAS token as well, so keep that in mind.
Copy data from blob account with SAS
Once you have everything in place, you are ready to go.
Before start copying data, let’s check the content of the blob in the source and the target storage account.
Source Storage Account
In the source storage account, I have two containers and one file in each.
Target Storage Account
In the target storage account in the second subscription, I don’t have any container yet.
To copy an entire account data from one blob account with SAS to another blob account with SAS, you can use the following syntax. This command will go through all containers from one blob in recursive mode and copy all the contents to the second storage account.
azcopy copy "https://[sourceaccount].blob.core.windows.net?[SAS]" "https://[targetaccount].blob.core.windows.net?[SAS]" --recursive=true
The output will show the total number of Transfers, Completed, Failed as well as the time in Minutes.
Refresh the Azure Storage Explorer, then check the containers and their content are copied over.
You can also use AzCopy in Azure Storage Explorer to copy data between storage accounts, if you want to leverage the performance advantages of AzCopy in Storage Explorer, then make sure to enable it under the Preview tab as shown in the following screenshot.
This great to copy a small number of directories and files between storage accounts, but for a large number of files, the AzCopy command-line tool is the fastest option. You can also use the same approach described above to copy and transfer Azure file shares between accounts.
That’s it there you have it.
Thank you for reading my blog.
If you have any questions or feedback, please leave a comment.