Azure Storage 複製
網路上目前看到的寫法都是container間的複製
一直沒找到可用的可以在Storage間互相複製全部container
所以參考網路寫法,自己寫一個
不過實際跑完測試好像還是Azcopy比較快@@
就當作練習嗎XD
一直沒找到可用的可以在Storage間互相複製全部container
所以參考網路寫法,自己寫一個
不過實際跑完測試好像還是Azcopy比較快@@
就當作練習嗎XD
#Server side storage copy
$SourceStorageAccount = ""
$SourceStorageKey = ""
$DestStorageAccount = ""
$DestStorageKey = ""
$SourceStorageContext = New-AzureStorageContext –StorageAccountName $SourceStorageAccount -StorageAccountKey $SourceStorageKey
$DestStorageContext = New-AzureStorageContext –StorageAccountName $DestStorageAccount -StorageAccountKey $DestStorageKey
$SourceStorageContainer = Get-AzureStorageContainer -Context $SourceStorageContext;
foreach ($Container in $SourceStorageContainer)
{
$Blobs = Get-AzureStorageBlob -Context $SourceStorageContext -Container $Container.Name
$BlobCpyAry = @() #Create array of objects
$DestStorageContainer = New-AzureStorageContainer $Container.Name -Permission Off -Context $DestStorageContext
#Do the copy of everything
foreach ($Blob in $Blobs)
{
Write-Output "Moving $Blob.Name"
$BlobCopy = Start-CopyAzureStorageBlob -Context $SourceStorageContext -SrcContainer $Container.Name -SrcBlob $Blob.Name `
-DestContext $DestStorageContext -DestContainer $DestStorageContainer.Name -DestBlob $Blob.Name
$BlobCpyAry += $BlobCopy
}
#Check Status
foreach ($BlobCopy in $BlobCpyAry)
{
#Could ignore all rest and just run $BlobCopy | Get-AzureStorageBlobCopyState but I prefer output with % copied
$CopyState = $BlobCopy | Get-AzureStorageBlobCopyState
$Message = $CopyState.Source.AbsolutePath + " " + $CopyState.Status + " {0:N2}%" -f (($CopyState.BytesCopied/$CopyState.TotalBytes)*100)
Write-Output $Message
}
}
留言
張貼留言