How To Copy Files From One Azure Storage Account To Another

|

Published on | Updated on July 25, 2020

3 Min. Read

Introduction

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.

How To Copy Files From One Azure Storage Account To Another 1

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.

Prerequisites

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.

How To Copy Files From One Azure Storage Account To Another 2

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.

How To Copy Files From One Azure Storage Account To Another 3

Target Storage Account

In the target storage account in the second subscription, I don’t have any container yet.

How To Copy Files From One Azure Storage Account To Another 4

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.How To Copy Files From One Azure Storage Account To Another 5

Refresh the Azure Storage Explorer, then check the containers and their content are copied over.

How To Copy Files From One Azure Storage Account To Another 6

There’s more…

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.

How To Copy Files From One Azure Storage Account To Another 7

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.

-Charbel Nemnom-

Previous

Passed AZ-500 Exam: Microsoft Certified Azure Security Engineer #MicrosoftLearn

How To Find The Recovery Services Vault For an Azure VM With PowerShell

Next

Let me know what you think, or ask a question...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Stay in Touch

Never miss out on your favorite posts and our latest announcements!

The content of this website is copyrighted from being plagiarized! You can copy from the 'Code Blocks' in Black.

Please send your feedback to the author using this form for any 'Code' you like.

Thank you for visiting!