Azure Copy All Content from StorageAccount-Container to another Storage Account-Container

Hallo @all

 [Update: translate to English]

die besten Skripte teilte man mit Freunden. In Trainings und ITCamps nutze ich die Möglichkeit ganze Multi-Server-Umgebungen von meiner Azure-Storage-Umgebung auf die Teilnehmer-Storage-Umgebung zu kopieren. 

Man kopiert innerhalb des Azure DataCenter super schnell und wenn Source und Destination auf dem gleichen Stamp sitzen, dann sind TB in Sekunden kopiert. Das ist dann ein WoW.

Mit nslookup kann man sehen, ob es der gleiche Stamp ist oder ein anderer. Ein Stamp hat immer eine eindeutige IP-Adresse:

image

 

Insgesamt gibt es 3 Kopier-Geschwindigkeiten:

Inner-Stamp-Copy Source und Destination Ip-Adresse sind gleich. Dann sind TBs an Dateien in Sekunden kopiert.
Inner-DataCenter-Copy Source und Destination Ip-Adresse sind ungleich. Beide Azure-Storage-Accounts liegen jedoch im gleichen DataCenter. Dann sind GB an Daten in Sekunden bis Minuten kopiert.
Cross-DataCenter-Copy Man kopiert von einem Storage Account zu einem anderen Storage Account. Beide Storage Account sind in unterschiedlichen DataCenter untergebracht. (letztens hatte ich 2 TB in 4,5 h kopiert von WestEurope nach EastAsia)

Notiz: das DataCenter kopiert für mich die Dateien in einem Copy-Job-Task. Mein Client erzeugt den Copy-Job-Task und schickt diesen ins Azure DataCenter. Danach ruft man nur noch den Copy-Job-Status ab. Ich kann somit beim kopieren einfach meinen Rechner herunterfahren und es kopiert noch fleißig weiter. Schaltet man den Rechner wieder an, dann holt man sich einfach ein update vom Copy-Job-Status. :-)

 

Und so sieht das Copy-Skript aus:

 # Description
# The script copy all Blobs of StorageAccount1/Container1 
# to StorageAccount2/Container2

# requirement:
# 1. you have access to both storage accounts + keys
# 2. create a target location container in the target storage Account

Import-Module Azure

# ToDo - Enter your SubscriptionName into Line 3
# e.g. get your Name with: 
#           Get-AzureSubscription | Select SubscriptionName
Select-AzureSubscription "My Azure MSDN Subscription"

# Source Storage Account
# Enter your Storage Account Name und your Key to get access
$storageAccount = "itcampstoragesource"
$storageAccountKey = "jd7ewEQ.....rgFc9A=="
$srcContainerName = "vhds"

# Destination Storage Account
# Enter your Storage Account Name und your Key to get access
$targetStorageAccount = "itcampattendeestorage1"
$targetStorageAccountKey = "jd7ew.....s2rgFc9A=="
$targetContainer = "base"


# loading Source
$srcStorageAccount =  $storageAccount
$srcStorageAccountKey = $storageAccountKey 

# Source Context
$srcContext = New-AzureStorageContext –StorageAccountName $srcStorageAccount ´
       -StorageAccountKey $srcStorageAccountKey

#destination context
$destContext = New-AzureStorageContext ´
               -StorageAccountName $targetStorageAccount ´
               -StorageAccountKey $targetStorageAccountKey 

# temp var for Copy Status 
$tempStorageContainerAccounts = @{}   
$tempCopyStates = @()
 # receive a list of blobs you want to copy
$allBlobs = Get-AzureStorageBlob ´
        -Container $srcContainerName -Context $srcContext

foreach ($blob in $allBlobs)
{
    $fileName = $blob.Name
$mediaLink = ´
"https://$storageAccount.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"
 # in Case you will copy TB of data from continent to continent, 
# a little update is nice for the hours it will take
while ($input -eq "y")
{
    # Wait for all copy operations to New container to complete
    # These copies should be instantaneous since they are in the same 
    # data center.
    foreach ($copyState in $tempCopyStates)
    {
        $now = get-date
        Write-host "Timestamp: $now"

        # Show copy status.    # -WaitForComplete
        $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)?" 
}
  
 

Liebe Grüße

Patrick