Skip to content

Instantly share code, notes, and snippets.

@one-harsh
Created December 5, 2015 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save one-harsh/a1f4bb52f8c3749c4c55 to your computer and use it in GitHub Desktop.
Save one-harsh/a1f4bb52f8c3749c4c55 to your computer and use it in GitHub Desktop.
Copy blobs asynchronously
$destStorageAccount = "<DestinationAccountName>"
$destStorageAccountKey = "<DestinationAccountKey>"
$targetContainer = "<DestinationContainer>"
$srcStorageAccount = "<SourceAccountName>"
$srcStorageAccountKey = "<SourceAccountKey>"
$srcContainerName = "<SourceContainer>"
$srcContext = New-AzureStorageContext –StorageAccountName $srcStorageAccount -StorageAccountKey $srcStorageAccountKey
$destContext = New-AzureStorageContext -StorageAccountName $destStorageAccount -StorageAccountKey $destStorageAccountKey
$tempStorageContainerAccounts = @{}
$tempCopyStates = @()
$allBlobs = Get-AzureStorageBlob -Container $srcContainerName -Context $srcContext
Add-Type -AssemblyName System.Web
# Copy asynchronously
foreach ($blob in $allBlobs)
{
$fileName = [System.Web.HttpUtility]::UrlEncode($blob.Name)
$mediaLink = "https://$srcStorageAccount.blob.core.windows.net/$srcContainerName/$fileName"
$targetUri = $destContext.BlobEndPoint + $targetContainer + "/" + $fileName
$tempCopyState = Start-AzureStorageBlobCopy -Context $srcContext -SrcUri $mediaLink -DestContext $destContext -DestContainer $targetContainer -DestBlob $fileName
$tempCopyStates += $tempCopyState
write-host "copied: $mediaLink -> $targetUri"
}
Start-Sleep -Seconds 2
$input = "y"
# Copy status check
while ($input -eq "y")
{
foreach ($copyState in $tempCopyStates)
{
$now = get-date
Write-host "Timestamp: $now"
$copyState | Get-AzureStorageBlobCopyState | Format-Table -AutoSize -Property Status,BytesCopied,TotalBytes,Source
write-host $copyState.ICloudBlob.Container.Uri.AbsoluteUri"/"$fileName
}
$input = Read-Host "Enter Refresh (y/n)?"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment