1

Azure 是否有办法在存储容器之间移动文件而无需将其下载回您的笔记本电脑?我尝试了 AzCopy,但似乎正在下载然后重新上传文件。

4

2 回答 2

3

Azcopy 确实提供了server-side copy的功能。这实际上是默认行为。你可以在这里找到一个例子: AzCopy /Source:https://myaccount.blob.core.windows.net/mycontainer1 /Dest:https://myaccount.blob.core.windows.net/mycontainer2 /SourceKey:key /DestKey:key /Pattern:abc.txt

但是,请注意:由于您基本上免费从 Azure 获得所需的计算作为备用容量,因此您不会获得任何性能 SLA。因此,在大多数情况下,这比在同一 Azure 区域中使用快速 VM 并使用所谓的同步复制(使用/SyncCopyazcopy 中的参数下载并上传到复制)要慢得多。

所以:如果您有时间和什么可以省钱,请使用服务器端副本。如果您希望快速完成复制,请使用 /SyncCopy

于 2018-10-15T08:06:08.197 回答
0

您可以使用Runbook来完成此操作。这是微软网站上实现此目的的文章的链接;

https://blogs.msdn.microsoft.com/cloud_solution_architect/2016/05/09/azure-storage-account-backup-azure-automation-runbook-azure-functions/

这是相关代码,稍作修改以使 ResourceGroup 成为变量。

$primary = Get-AutomationVariable -Name 'Log-Storage-Primary'
$secondary = Get-AutomationVariable -Name 'Log-Storage-Secondary'
$ResourceGroupName = Get-AutomatioNVariable -Name 'LogStorageResourceGroup'

$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint

$primarykey = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $primary
$secondarykey = Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $secondary

$primaryctx = New-AzureStorageContext -StorageAccountName $primary -StorageAccountKey $primarykey.Key1
$secondaryctx = New-AzureStorageContext -StorageAccountName $secondary -StorageAccountKey $secondarykey.Key1

$primarycontainers = Get-AzureStorageContainer -Context $primaryctx

# Loop through each of the containers
foreach($container in $primarycontainers) {
    # Do a quick check to see if the secondary container exists, if not, create it.
    $secContainer = Get-AzureStorageContainer -Name $container.Name -Context $secondaryctx -ErrorAction SilentlyContinue

    if (!$secContainer) {
        $secContainer = New-AzureStorageContainer -Context $secondaryctx -Name $container.Name
        Write-Host "Successfully created Container" $secContainer.Name "in Account" $secondary
    }

    # Loop through all of the objects within the container and copy them to the same container on the secondary account
    $primaryblobs = Get-AzureStorageBlob -Container $container.Name -Context $primaryctx
    foreach($blob in $primaryblobs) {
        $copyblob = Get-AzureStorageBlob -Context $secondaryctx -Blob $blob.Name -Container $container.Name -ErrorAction SilentlyContinue

        # Check to see if the blob exists in the secondary account or if it has been updated since the last runtime.
        if (!$copyblob -or $blob.LastModified -gt $copyblob.LastModified) {
            $copyblob = Start-AzureStorageBlobCopy -SrcBlob $blob.Name -SrcContainer $container.Name -Context $primaryctx -DestContainer $secContainer.Name -DestContext $secondaryctx -DestBlob $blob.Name
            $status = $copyblob | Get-AzureStorageBlobCopyState

            while ($status.Status -eq "Pending") {
                $status = $copyblob | Get-AzureStorageBlobCopyState
                Start-Sleep 10
            }
            Write-Host "Successfully copied blob" $copyblob.Name "to Account" $secondary "in container" $container.Name
        }
    }
}
于 2018-10-14T23:09:10.967 回答