Copy, Download or Upload from-to any combination of Windows, Linux, OS X, or the cloud
Data is and will always be our primary concern. Whether shaped as text files, images, VM VHDs or any other ways, at some point in time, our data will need to be moved. I already wrote about it previously, and the content of this post is still valuable today, but I wanted to share new options and convert all ground (meaning Linux, Windows and OS X).
Here few scenarios why you would want to move data.
- Your Microsoft Azure trial is ending, and you wish to keep all the data.
- You are creating a new web application, and all those images need to be moved to the Azure subscription.
- You have a Virtual Machine that you would like to move to the cloud or to a different subscription.
AzCopy is a fantastic command-line tool for copying data to and from Microsoft Azure Blob, File, and Table storage.
AzCopy on Windows
In his simplest expression, an AzCopy command looks like this:
If you earlier have installed an Azure SDK on your machine, you already have it. By default, AzCopy is installed to
AzCopy /Source:<source> /Dest:<destination> [Options]
%ProgramFiles(x86)%\Microsoft SDKs\Azure\AzCopy (64-bit Windows) or
%ProgramFiles%\Microsoft SDKs\Azure\AzCopy (32-bit Windows).
If you need only AzCopy for a server, you can download the latest version of AzCopy.
Let's see some frequent usage. First let's say you need do move all those images from your server to an Azure blob storage.
AzCopy /Source:C:\MyWebApp\images /Dest:https://frankysnotes.blob.core.windows.net/blog /DestKey:4YvvYDTg3UUpky8Rj5bDG4KO/R1FdtssxVnunsEd/4rAS04V2LkO0F8mXbddAv39WtCo5LW6JyvfhA== /S
Then to copy those images to another subscription very easy.
AzCopy /Source:https://frankysnotes.blob.core.windows.net/blog /Dest:https://frankshare.blob.core.windows.net/imagesbackup /SourceKey:4YvvYDTg3UUpky8Rj5bDG4KO/R1FdtssxVnunsEd/4rAS04V2LkO0F8mXbddAv39WtCo5LW6JyvfhA== /DestKey:EwXpZ2uZ3zrjEbpBGDfsefWkj3G2QY5fJcb6kMqV2A0+2TsGno+mk9vEXc5Uw1XiouvAiTS7Kr5OGzA== /S
These examples were simple, but AzCopy is a very powerful tool. I invite you to type one of the following commands to discover more about using AzCopy:
- For detailed command-line help for AzCopy:
- For command-line examples:
AzCopy on Linux
Before you could install AzCopy you will need to install .Net Core. This is done very simply with few commands.
Then to install it, you just need to get it with a wget command, unzip it, and execute the install script.
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.2
In his simplest expression, the .Net Core version of AzCopy command looks like this:
wget -O azcopy.tar.gz https://aka.ms/downloadazcopyprlinux
tar -xf azcopy.tar.gz
It is very similar to the original version, but parameters are using
azcopy --source <source> --destination <destination> [Options]
- instead of the
/ and where a
: was required, it's now a simple space.
Uploading to Azure
Here an example, to copy a single file
GlobalDevopsBootcamp.jpg to an Azure Blob Storage. We pass the full local path to the file into
--source, the destination is the full URI, and finally the destination blob storage key. Of course, you could also use SAS token if you prefer.
--source /home/frank/demo/GlobalDevopsBootcamp.jpg \
--destination https://frankysnotes.blob.core.windows.net/blog/GlobalDevopsBootcamp.jpg \
Copying Between Azure Subscriptions
To copy the image to a second Azure subscription, we use the command the source is now an Azure Storage URI, and we pass the source and the destination keys:
--source https://frankysnotes.blob.core.windows.net/blog/GlobalDevopsBootcamp.jpg \
--destination https://frankshare.blob.core.windows.net/imagesbackup/GlobalDevopsBootcamp.jpg \
--source-key 4YvvYDTg3UUpky8Rj5bDG4KO/R1FdtssxVnunsEd/4rAS04V2LkO0F8mXbddAv39WtCo5LW6JyvfhA== \
Azure CLI is a set of cross-platform commands for the Azure Platform. It gives tools to manipulate all Azure components, but this post will focus on
azure storage features.
There are two versions of the Azure Command-Line Interface (CLI) currently available:
- Azure CLI 2.0: written in Python, conpatible only with the Resource Manager deployment model.
- Azure CLI 1.0: written in Node.js, compatible with both the classic and Resource Manager deployment models.
Azure CLI 1.0 is deprecated and should only be used for support with the Azure Service Management (ASM) model with "classic" resources.
Installing Azure CLI
Let's start by installing Azure CLI. Of course, you can download an installer but since everything is evolving very fast with not getting it from Node Package Manager (npm). The install will be the same, you just need to specify the version if you absolutely need Azure CLI 1.0.
sudo npm install azure-cli -g
To keep the previous scenario, let's try to copy all images to a blob storage. Unfortunately, Azure CLI doesn't offer the same flexibility as AzCopy,and you must upload the file one by one. However, to upload all images from a folder, we can easily put the command in a loop.
for f in Documents/images/*.jpg
azure storage blob upload -a frankysnotes -k YoMjXMDe+694FGgOaN0oaRdOF6s1ktMgkB6pBx2vnAr8AOXm3HTF7tT0NQWvGrWnWj5m4X1U0HIPUIAA== $f blogimages
In the previous command
-a was the account name, and
-k was the Access key. This two information can easily be found in the Azure portal. From the portal (https://portal.azure.com), select the storage account. In the right band click-on Access keys.
To copy a file (ex: a VM disk aka VHD) from one storage to another one in a different subscription or region, it's really easy. This time we will use the command
azure storage blob copy start and the
-k are related to our destination.
azure storage blob copy start 'https://frankysnotes.blob.core.windows.net/blogimages/20151011_151451.MOV' imagesbackup -k EwXpZ2uZ3zrjEbpBGDfsefWkj3GnuFdPCt2QY5fJcb6kMqV2A0+2TsGno+mk9vEXc5Uw1XiouvAiTS7Kr5OGzA== -a frankshare
The nice thing about this command is that it's asynchronous. To see the status of your copy just execute the command
azure storage blob copy show
azure storage blob copy show -a frankshare -k YoMjXMDe+694FGgOaN0oPaRdOF6s1ktMgkB6pBx2vnAr8AOXm3HTF7tT0NQVxsqhWvGrWnWj5m4X1U0HIPUIAA== imagesbackup 20151011_151451.MOV
Azure CLI 2.0 (Windows, Linux, OS X, Docker, Cloud Shell)
The Azure CLI 2.0 is Azure's new command-line optimized for managing and administering Azure resources that work against the Azure Resource Manager. Like the previous version, it will work perfectly on Windows, Linux, OS X, Docker but also from the Cloud Shell!
Cloud Shell is available right from the Azure Portal, without any plugging.
Uploading to Azure
The command if the same as the previous version except that now the command is named
az. Here an example to upload a single file into an Azure Blob Storage.
az storage blob upload --file /home/frank/demo/CloudIsStrong.jpg \
--account-name frankysnotes \
--container-name blogimages --name CloudIsStrong.jpg \
Copying Between Subscriptions
Let's now copy the file to another Azure subscription. A think to be aware is that
--account-key are for the destination, even if it's not specified.
az storage blob copy start \
--source-account-name frankysnotes --source-account-key 4YvvYDTg3UUpky8Rj5bDG4KO/R1FdtssxVnunsEd/4rAS04V2LkO0F8mXbddAv39WtCo5LW6JyvfhA== \
--source-container blogimages --source-blob CloudIsStrong.jpg \
--account-name frankshare --account-key EwXpZ2uZ3zrjEbpBGDfsefWkj3G2QY5fJcb6kMqV2A0+2TsGno+mk9vEXc5Uw1XiouvAiTS7Kr5OGzA== \
--destination-container imagesbackup \
In Video Please!
If you prefer, I also have a video version of that post.
One More Thing
Sometimes, we don't need to script things, and a graphic interface is much better. For this kind of situation, the must is the Azure Storage Explorer. It does a lot! Upload, download, and manage blobs, files, queues, tables, and Cosmos DB entities. And it works on Windows, macOS, and Linux!
It's just the beginning
This post was just an introduction to two very powerful tools. I strongly suggest to go read in the official documentation to learn more. Use the comment to share all your questions and suggestion.