Azure Runbook replacement for AzCopy

1.6k Views Asked by At

How do I translate this AzCopy command:

azcopy.exe sync "https://xxxxxx.blob.core.windows.net/xxxxx/...." "https://xxxxxx.blob.core.windows.net/xxxxx/...." --recursive

To an Azure Runbook command?

I played around with Start-AzureStorageBlobCopy but can't get it to work with 2 URI's

R. Kim

1

There are 1 best solutions below

6
On

The Powershell Cmdlet Start-AzureStorageBlobCopy is part of Azure RM module as we know that AzureRM module is going to be retried on 29 February 2024.

  • If you use the Azure RM module related cmdlets in you run book the Job will be Suspended automatically.
  • It is recommended to use Az Module Cmdlets in your runbook scripts.

You can use Start-AzStorageBlobCopy cmdlet to copy the blobs from one storage account to another storage account.

To test this i have created a PowerShell run book with the script below (copying all the blobs from source storage account container to destination storage account container) and connected it to azure account by enabling managed identity on the automation account.

connect-azaccount -identity
$src=New-AzStorageContext -StorageAccountName <sourceStorageAccountName> -StorageAccountKey <sourcestorageaccountKey>
$dest=New-AzStorageContext -StorageAccountName <destinationstrgaccountName> -StorageAccountKey <destinationStorageAccountKey>
Get-AzStorageBlob -Container "<containerName>" -Context $src | Start-AzStorageBlobCopy -DestContainer "destcont" -DestContext $dest

Refer to this documentation for more information about the Start-AzStorageBlobCopy cmdlet and the list of support parameters.

Alternatively, if you want to AZ copy in your run book i would suggest you to use the Hybrid run book worker which would allow you to pre-install AzCopy and then execute any runbook on that worker.

For more information on Azcopy in Automation Account you can refer to this similar MSDN thread.