Created
December 5, 2015 07:56
-
-
Save one-harsh/a1f4bb52f8c3749c4c55 to your computer and use it in GitHub Desktop.
Copy blobs asynchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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