1
votes

I'm trying to copy all of the containers and files from one account to another using an automation powershell script. The script runs fine but I see no output and no files at the destination.

How can I correct this script so it will copy all of the containers and files on one azure storage account onto another storage account, creating the containers as needed?

#Define the source storage account and context.
$SourceStorageAccountName = "importantthings"
$SourceStorageAccountKey = "[mysourcekeyhere]"
$SourceContext = New-AzureStorageContext -StorageAccountName     
$SourceStorageAccountName -StorageAccountKey $SourceStorageAccountKey

#Define the destination storage account and context.
$DestStorageAccountName = "dailybackup"
$DestStorageAccountKey = "[mydestkeyhere]"
$DestContext = New-AzureStorageContext -StorageAccountName $DestStorageAccountName -StorageAccountKey $DestStorageAccountKey
$Containers = Get-AzureStorageContainer -Prefix group -Context $SourceContext
foreach ($Container in $Containers) {
        $DestContainer = New-AzureStorageContainer -Name $Container.Name -Context $DestContext -Force #-Permission Off 
        #Get a reference to blobs in the source container.
        $blob = Get-AzureStorageBlob -Container $Container.Name -Context $SourceContext | Start-CopyAzureStorageBlob -destcontainer $DestContainer.Name #–destblob $blob.name #-srccontainer $Container.Name 
        $blob | Get-AzureStorageBlobCopyState –WaitForComplete  

}

The first error is this:

New-AzureStorageContainer : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error 
Message: Server failed to authenticate the request. Make sure the value of     Authorization header is formed correctly 
including the signature.
At line:19 char:21
+ ... Container = New-AzureStorageContainer -Name $Container.Name -Context  ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [New-AzureStorageContainer], StorageException
+ FullyQualifiedErrorId : 

StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.NewAzureStorageContainerCommand

1
My guess is you're getting some exceptions but you're simply eating those exceptions in your code. Can you please try catching the exceptions and outputting them in the catch block of your code? - Gaurav Mantri
I don't see him "eating" any exception in his code. Please verify that your account key is correct. ALSO check your computer clock is correct! - Martin Brandl
@jisaak The question was edited 7 minutes before your comment :). Please see the question revision history. - Gaurav Mantri
lol I was eating it. Now I'm not. - General Chad

1 Answers

2
votes

Solution is to ensure you have the right storage account key with the storage account. Silly mistake.