This tip is marked obsolete. More info can be found here (opens new window).
💡 Learn more : AzCopy v10 (opens new window).
# Working with AzCopy and Azure Storage
We've reviewed the following options with Azure Storage so far:
- Working with Azure Storage Blobs and Files through the Portal (opens new window)
- Create an Azure Storage Blob Container through C# (opens new window)
- Uploading and Downloading a Stream into an Azure Storage Blob (opens new window)
- Working with Azure Storage Explorer (opens new window)
- Copy Azure Storage Blobs and Files via C# (opens new window)
- Creating an Azure Blob Hierarchy (opens new window)
- Adding Metadata to a file inside Azure Storage Blob Container (opens new window)
- Working with AzCopy and Azure Storage (opens new window)
Today, we are going to look at working with AzCopy to manipulate our Azure Storage container that we've been using throughout this series. Feel free to walk through other post in the series to get up to speed.
What is AzCopy? AzCopy is a command-line utility designed for copying data to/from Microsoft Azure Blob, File, and Table storage, using simple commands designed for optimal performance. You can copy data between a file system and a storage account, or between storage accounts. (courtesy of docs)
For this example, I'm going to use Windows. After I downloaded and installed the utility, I navigated inside my command prompt to the following folder
%ProgramFiles(x86)%\Microsoft SDKs\Azure\AzCopy and ran the
azcopy.exe command to ensure everything was working properly.
So you may be wondering if you need to do the device login as we did with the Azure CLI (opens new window). The answer is no, we'll be using our Azure Storage Access Key.
# Getting the Azure Storage Access Key
Go ahead and open the Azure Portal and navigate to the Azure Storage account that we worked with earlier (opens new window).
Look under Settings, then Access Keys and copy the key1.
Store the key somewhere that you can retrieve it again.
# Kick the tires with a couple of commands.
We can easily download a file from our Azure Storage Blob Container that we've been working with earlier with the following command:
AzCopy /Source:https://mbcrumpsa.blob.core.windows.net/images-backup /Dest:C:\mytest /SourceKey:thekeyyoucopiedearlier /Pattern:"mikepic.png"
We can do the reverse and upload a file from our hard disk to Azure Storage Blob Container with the following command:
AzCopy /Source:C:\mytest /Dest:https://mbcrumpsa.blob.core.windows.net/images-backup /DestKey:thekeyyoucopiedearlier /Pattern:"mikepicnew.png"
Keep in mind: The main difference between these two commands is the use of SourceKey for downloading and DestKey for uploading. The key that is being used is identical (named key1 from the example above).
Finally, you can copy from one Azure Storage account to another one with the following command:
AzCopy /Source:https://mbcrumpsa.blob.core.windows.net/images-backup /Dest:https://mbcrumpsa.blob.core.windows.net/images /SourceKey:thekeyyoucopiedearlier /DestKey:thekeyyoucopiedearlier /Pattern:"mikepicnew.png"
In this case, I am copying a file named
images and then I'll refresh the container.