June 9, 2015

Microsoft Azure - copy blob between subscriptions

# Specify storage accounts, containers and blobs.
$SourceStorageAccount = "SOURCE_STORAGE_ACCOUNT_NAME"
$SourceContainer = "SOURCE_CONTAINER_NAME"
$SourceBlob = "SOURCE_BLOB_NAME"
$DestStorageAccount = "DESTINATION_STORAGE_ACCOUNT_NAME"
$DestContainer = "DESTINATION_CONTAINER_NAME"
$DestBlob = "DESTINATION_BLOB_NAME"

# Get Context for source
Select-AzureSubscription "SOURCE_SUBSCRIPTION_NAME"
$SourceStorageAccountKey = (Get-AzureStorageKey -StorageAccountName $SourceStorageAccount).Primary
$SourceContext = New-AzureStorageContext -StorageAccountName $SourceStorageAccount -StorageAccountKey $SourceStorageAccountKey

# Get Context for destionation
Select-AzureSubscription "DESTINATION_SUBSCRIPTION_NAME"
$DestStorageAccountKey = (Get-AzureStorageKey -StorageAccountName $DestStorageAccount).Primary
$DestContext = New-AzureStorageContext -StorageAccountName $DestStorageAccount -StorageAccountKey $DestStorageAccountKey

# Start blob copy from one subscription to another
Start-AzureStorageBlobCopy -SrcBlob $SourceBlob -SrcContainer $SourceContainer -SrcContext $SourceContext -DestContainer $DestContainer -DestBlob $DestBlob -DestContext $DestContext

# Check status of copy
Get-AzureStorageBlobCopyState -Blob $DestBlob -Container $DestContainer -Context $DestContext

Very useful script: Copy a Virtual Machine Between Subscriptions

No comments:

Post a Comment