LoginSignup
1
0

More than 5 years have passed since last update.

Azure Storage アカウント間でアカウント内のすべてのBlobをコピーする

Last updated at Posted at 2017-02-24

Blobをまるごと別アカウントにコピー

移行テスト環境構築のために本番データを新規環境へコピーする必要があります。
数年分のデータを溜め込んでいるのでものすごい量でした。

copy-customallblobcontainer.ps1
    $Context = "Context取得"
    $ContainerList = Get-AzureStorageContainer -Context $Context
    Write-Verbose "iterate over the number of containers"
    Write-Verbose ("copy {0} containers" -f $ContainerList.Count)

    $ContainerCounter = 0
    foreach($ContainerInfo in $ContainerList) {
        Copy-CustomBlobStorage -From $FromSrcEnviroment -ToDestEnviroment $ToDestEnviroment -ContainerName ($ContainerInfo.Name) -ExceptSnapshot -StorageTarget $StorageTarget
        #Write-Verbose ("Copying of {0} Blob is completed" -f $BlobCounter.Count)
        $ContainerCounter = $ContainerCounter + 1
    }
Copy-CustomBlobStorage.ps1
        $Context = "Context取得"   
        #Get a reference to blobs in the source container.
        if($ExceptSnapshot) {
            $ObtainedBlob = Get-AzureStorageBlob -Container $ContainerName -Context $Context | Where-Object  { !($_.ICloudBlob.IsSnapshot)}
        } else {
            $ObtainedBlob = Get-AzureStorageBlob -Container $ContainerName -Context $Context
        }

        #Define the Destination storage account and context.
        $DestContext = "Context取得"

        $DestContainer = $ContainerName
        New-AzureStorageContainer -Context $DestContext -Name $DestContainer -ErrorAction Ignore > $null

    #Copy blobs from one container to another.
    $ObtainedBlob `
    | Start-AzureStorageBlobCopy -DestContainer $DestContainer -DestContext $DestContext -Force `
    | Get-AzureStorageBlobCopyState -WaitForComplete

コンテナコピーするスクリプトはもともと作成していたのでアカウント単位でコピーする大本のスクリプトを作成したんですが、
最初はスナップショットが邪魔をしてエラーになってしまいました。

そこで、1度はBlobを1つずつコピーするよう作り変えたのですが、おそすぎたので実行を断念しました。

そこでGet-AzureStorageBlobで取得したものからIsSnapshotを除外するように変更しました。

かなりのスピードアップはできました。
それでもまだ時間はかかるので、あとは並列化とか非同期を取り入られるか模索中です。

2017-10-26追記

よくよく考えたらコンテナ単位でAzcopyの方が断然速いと気がついたので暇を見つけてAzcopy版で作成します

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0