Copy files between Containers in Azure Storage Account

There are some requirements sometimes to run a scheduled task to copy files between storage containers in same storage account or different storage account. To address this requirement, we need to run the relevant PowerShell script as a scheduled task. There are several ways available to run a scheduled task in azure. One of the method is based on Azure Function App. Create a Function App based on Runtime Stack as PowerShell Core as I have detailed the steps on how to achieve this with the help of an Azure Function app in my previous post here:

Following PowerShell Script is useful for Copying files between Containers in Azure Storage Account

 $srcRGName = "name here"
 $srcStgAccount = "qrfree"
 $srcContainer = "source"
 $blobName = "source1/test.txt"
 $srcRGName = "name here"
 $destStgAccount = "qrfree"
 $destContainer = "archive"
 $srcStorageKey = Get-AzStorageAccountKey -Name $srcStgAccount -ResourceGroupName $srcRGName 
 $destStorageKey = Get-AzStorageAccountKey -Name $destStgAccount -ResourceGroupName $srcRGName
 $srcContext = New-AzStorageContext -StorageAccountName $srcStgAccount -StorageAccountKey $srcStorageKey.Value[0]
 $destContext = New-AzStorageContext -StorageAccountName $destStgAccount -StorageAccountKey $destStorageKey.Value[0]
 $copyOperation = Start-AzStorageBlobCopy -SrcBlob $blobName -SrcContainer $srcContainer -Context $srcContext -DestBlob $blobName -DestContainer $destContainer -DestContext $destContext -Force


2 Responses

    • Dear Anirban, the solution copies the blob specified and not suitable for a delta copy purpose. For example, $blobName = “source1/test.txt” copies the test.txt only

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Comments