Reputation: 465
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
Upvotes: 1
Views: 1981
Reputation: 465
Solution is to ensure you have the right storage account key with the storage account. Silly mistake.
Upvotes: 2