简体   繁体   中英

Azure Powershell to copy azure storage account to another azure storage account

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM