Step-By-Step: Using AzCopy to Transfer Files to Azure
A few weeks ago, I posted an article on configuring SMB file shares in Azure to leverage shared drives from within Azure or from on-premise. But what if you are unable to access these SMB file shares due to port restrictions? Or if you only need to copy files to and from Azure storage, and do not require SMB file shares? AzCopy is a simple yet powerful command line interface that allows you to copy files to and from Azure storage and between Azure storage accounts. The latest version, 5.0, now supports File and Table storage, and became generally available December 2nd, 2015. With this release you can:
- Upload, download, and copy Azure Storage Blob containers, block blobs, page blobs and append blobs
- Upload, download, and copy Azure Storage File shares and files
- Import and export Azure Storage Table entities
- Concurrent, recursive, and conditional copying
- Resume interrupted operations
For those of you already familiar with Robocopy, AzCopy will feel very similar. It is a command line with a simple, yet powerful, list of commands.
In this article you will learn the basic command line structures to:
Copy files to and from your local system to Azure storage
Copy files between storage accounts and regions
The first step is to download and launch the latest version of the Microsoft Azure Storage Tools application.
Next, I created a public container in the blob storage account, called canitproblobcontainer.
Locally, I have created a folder called AzCopy with two subfolders, called Pics and Docs.
Next, we will copy the entire directory structure to the public container using the recursive option. I will need the URL for the container. The URL can be located in the container properties blade.
I will also need the access key for this blob container. This can be located in the blob storage account under All settings and Access keys.
Next from the Microsoft Azure Storage Tools application, we enter the following command:
AzCopy /source:C:\Azcopy_data /dest: https://canitproblob.blob.core.windows.net/canitprocontainer /destkey:”container access key” /s.
Lets break down the command.
- Azcopy = the action
- /Source = the local folder
- /Dest = the blob container
- /Destkey = the blob access key
- /s = copies the directory structure
In this example, the files and folders in AzCopy_data will be copied to the container.
We can also copy files and folders from Azure storage to our local system using the following command:
Azcopy /source: https://canitproblob.blob.core.windows.net/canitprocontainer /dest:c:\azcopy_data2 /sourcekey:accesskey /s.
In this example, I had not previously created the folder AzCopy_data2; this was created automatically by the command.
You can also use AzCopy to:
Copy blobs within storage accounts,
AzCopy /Source:https://myaccount.blob.core.windows.net/mycontainer1 /Dest:https://myaccount.blob.core.windows.net/mycontainer2 /SourceKey:key /DestKey:key /Pattern:abc.txt
Across storage accounts,
AzCopy /Source:https://sourceaccount.blob.core.windows.net/mycontainer1 /Dest:https://destaccount.blob.core.windows.net/mycontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt
And even across regions.
AzCopy /Source:https://myaccount1-secondary.blob.core.windows.net/mynewcontainer1 /Dest:https://myaccount2.blob.core.windows.net/mynewcontainer2 /SourceKey:key1 /DestKey:key2 /Pattern:abc.txt
Other parameters include copying files with wildcards such as *.txt or by pattern using the parameter /Pattern:s, for example, to only copy files that start with the letter s.
These are some common uses and parameters for AzCopy; for a more detailed list of parameters and examples, see Azure article Transfer data with the AzCopy Command-Line Utility.
From this brief overview alone, you can see the power of this simple yet easy and familiar command line utility to copy your Azure storage data. For a detailed description of AzCopy and a full list of parameters, see article Transfer data with the AzCopy CL Utility.