从 Azure 文件复制到 BLOB
Copying from Azure file to BLOB
Azure 是否有办法在存储容器之间移动文件而无需将文件下载回笔记本电脑?我尝试了 AzCopy,但似乎是在下载然后重新上传文件。
您可以使用 Runbook 来完成此操作。这是 link Microsoft 网站上完成此操作的文章;
这里是相关代码,稍作修改,使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
}
}
}
Azcopy 确实提供了 server-side copy 的功能。这实际上是默认行为。
您可以找到 here 的示例:
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 并使用所谓的同步复制(向下和上传复制,使用 azcopy 中的 /SyncCopy
参数)慢得多。
所以:如果有时间又省钱的话,就用服务器端文案吧。如果您希望快速完成复制,请使用 /SyncCopy
Azure 是否有办法在存储容器之间移动文件而无需将文件下载回笔记本电脑?我尝试了 AzCopy,但似乎是在下载然后重新上传文件。
您可以使用 Runbook 来完成此操作。这是 link Microsoft 网站上完成此操作的文章;
这里是相关代码,稍作修改,使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
}
}
}
Azcopy 确实提供了 server-side copy 的功能。这实际上是默认行为。
您可以找到 here 的示例:
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 并使用所谓的同步复制(向下和上传复制,使用 azcopy 中的 /SyncCopy
参数)慢得多。
所以:如果有时间又省钱的话,就用服务器端文案吧。如果您希望快速完成复制,请使用 /SyncCopy