Copying Azure Blob content from one storage account to another

Azure Storage is cool, we use it over here on our .com to server all wp uploads using Azure Storage Plugin for WordPress and we use it almost everywhere else as well for storing our MongoDB collections, for storing images, generated documents et al. We recently had to deal with having to copy few hundred Gigs of data from one storage account to another – basically we are doing a major tech overhaul for one of our customers and wanted to quickly replicate the production environment for testing. Copying/moving blobs from one container to another can be done using Azure’s Azcopy tool but unfortunately, it doesn’t support copying over the containers itself. You could create containers by hand but if you have a lot of containers to copy over a bit of Powershell scripting along with Azure Powershell Tools can be really handy and a big time saver:


PS C:\>$sourceContext=New-AzureStorageContext -StorageAccountName "sourceAccountName" -StorageAccountKey "source-key"
PS C:\>$destinationContext=New-AzureStorageContext -StorageAccountName "destAccountName" -StorageAccountKey "dest-key"
PS C:\>foreach($item in Get-AzureStorageContainer -Context $sourceContext){
New-AzureStorageContainer -Name $item.Name -Permission $item.PublicAccess -Context $destinationContext;
}

With the containers created on destination, copying over blobs is just a matter of firing the azcopy command with right parameters:

C:\> AzCopy /Source:https://source.blob.core.windows.net/<container> /Dest:https://dest.blob.core.windows.net/<container> /SourceKey:key1 /DestKey:key2 /XO /XN

XO, XN switches will ensure that only the files which don’t exist on destination are copied over.

Top