Copy private blobs across storage accounts

Last month Microsoft released two updates to Windows Azure PowerShell cmdlets.

Read Michael Washam’s excellent post to get an overview of the April 15th updates.

Read Scott Guthrie’s blog post to learn about PowerShell updates from April 29th.

The following script shows how you can use Start-AzureStorageBlobCopy cmdlets to copy a blob from on storage account to another. These storage accounts may be located in different subscriptions and/or data centers. The cmdlets uses Server Side copy so the blobs will be directly copied from one data center to another data center.

This script may be use when you are migrating blobs from one subscription to another.

# Source Storage Account (North Central)            
$sourceStorageAccount = "source_storage_account_name"            
$sourceStorageKey = "source_storage_account_key"            

$sourceContext = New-AzureStorageContext  –StorageAccountName $sourceStorageAccount `
                                        -StorageAccountKey $sourceStorageKey              
# Target Storage Account (East US)            
$destStorageAccount = "dest_storage_account_name"            
$destStorageKey = "dest_storage_account_key"            

$destContext = New-AzureStorageContext  –StorageAccountName $destStorageAccount `
                                        -StorageAccountKey $destStorageKey              

$blob = Start-AzureStorageBlobCopy -SrcContainer "private" `
                                   -DestContainer "myprivate" `
                                   -SrcBlob "Azure Overview.pptx" `
                                   -SrcContext $sourceContext `
                                   -DestContext $destContext               

$blob | Get-AzureStorageBlobCopyState -WaitForComplete
This entry was posted in IAAS, PowerShell. Bookmark the permalink.