I was working on a large lab for testing Disaster Recovery scenarios.  Then I had to fun task of breaking things in fun and interesting ways (when was the last time you tried to take a edb file from and exchange server and replace it with a single word file’s binaries).  Before I did any of this, I did not want the last 40 hours of work setting up this lab to go to waste.  So I did a quick little script that copies data from one location to another in Azure:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
$blob = @{}
#Get source information for the container you want to copy
$srcUriroot = "https://dalabbos.blob.core.windows.net/vhds/" 
$srcStorageAccount = "dalabbos"
$srcStorageKey = "srcstoragekeyAAAAAAAAAAAABBBBBBBBBBBBBBBBBB"
$srcContainerName = "vhds"
 
#Get the destination information for where you want to copy to.  Note that if this is in the same storage account it is almost instantaniouse
$destStorageAccount = "dalabbos"
$destStorageKey = "deststoragekeyYYYYYYYYYYYYYYYYYYYYYZZZZZZZZZZZZZZZZZZZZ"
$destContainerName = "vhdorig"
 
 
#Build context information
$srcContext = New-AzureStorageContext  –StorageAccountName $srcStorageAccount `
                                        -StorageAccountKey $srcStorageKey  
$destContext = New-AzureStorageContext  –StorageAccountName $destStorageAccount `
                                        -StorageAccountKey $destStorageKey
 
#Get source files
$srcContainer = Get-AzureStorageContainer -Context $srcContext -Name $srcContainerName
$Files = Get-AzureStorageBlob -Container $srcContainer.Name -Context $srcContext
$Files | Export-Csv -NoTypeInformation C:\trash\files.csv
 
#Copy the files
$i=0
Foreach ($file in $Files)
{
    $srcUri = $srcUriroot + $file.Name
    write-host $i $srcUri $destContainerName
	#Builds an array in the event you need to inspect the copy
    $blob[$i] = Start-AzureStorageBlobCopy -srcUri $srcUri -SrcContext $srcContext -DestContainer $destContainerName -DestBlob $file.Name -DestContext $destContext
    $i++
}

Leave a Reply

Your email address will not be published. Required fields are marked *