How To Use AzCopy For Storage

Introduction 

In this blog, we are discussing how to use AzCopy for transferring the data from one container to another container step by step.

AzCopy Installation  

First, we need to download the AzCopy executable file from Microsoft's official page. Please use the following link to download the package.

Next, add the executable file location to environment variables [I mean path should be added]

Next, we have to install the Azure packages, which help to execute az commands. Using powershell, run the following command to install AzModule.

Install-Module -Name Az

Now run powershell with administrator mode and confirm AzCopy is running on the local machine.

AzCopy -h

Commands to transfer the blob from one container to another

Connect-AzAccount
Get-AzSubscription
$subscriptionId = ""
$storageAccountRG = ""
$storageAccountName = ""
$srcstorageAccountName=""
$storageContainerName = ""
 
Select-AzSubscription -SubscriptionId $SubscriptionId

$storageAccountKey = (Get-AzStorageAccountKey -ResourceGroupName $storageAccountRG -AccountName $storageAccountName).Value[0]
$destinationContext = New-AzStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey
$containerSASURI = New-AzStorageContainerSASToken -Context $destinationContext -ExpiryTime(get-date).AddSeconds(3600) -FullUri -Name     $storageContainerName -Permission rw

$storageAccountKeyForSrc=(Get-AzStorageAccountKey -ResourceGroupName $storageAccountRG -AccountName $srcstorageAccountName).Value[0]
$sourceContext = New-AzStorageContext -StorageAccountName $srcstorageAccountName -StorageAccountKey $storageAccountKeyForSrc
$srccontainerSASURI = New-AzStorageContainerSASToken -Context $sourceContext -ExpiryTime(get-date).AddSeconds(3600) -FullUri -Name     $storageContainerName -Permission rwl
azcopy copy $srccontainerSASURI $containerSASURI --recursive

That's it. Once we execute the above commands via powershell scripts, blobs will be copied from one container to another.

Summary 

In this blog, we learned about how to use AzCopy.

I hope that you find it helpful. Eat->Code->Sleep->Repeat.