In this guide, we will show you how to copy files from one Azure storage account to another storage account.
In This Article
A while ago, we wrote about how to move VHD images from one Azure subscription to another. In this article, we 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 the 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:
2) Download Microsoft Azure Storage Explorer 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 Files Between Azure Storage Accounts
Once you have everything in place, you are ready to go.
Before starting to copy 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 containers 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, and 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.
It 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.
In this article, we showed you how to copy files from one Azure Storage account to another storage account using the AzCopy command-line tool.
To learn more about syncing between Azure File share(s) and Azure Blob Container, check the following article.
To learn more about syncing between two Azure File share(s) for disaster recovery, check the following article.
Thank you for reading my blog.
If you have any questions or feedback, please leave a comment.