将Azure快照复制到其他区域

时间:2020-09-23 21:58:19

标签: azure azure-disk

我正在尝试使用Azure中的快照创建灾难恢复解决方案。群集中有很多磁盘,目前可以制作磁盘快照以进行本地还原。可行

我现在想将现有快照复制到其他区域,或者为磁盘创建新快照,但将其存储在其他区域。

参考:https://docs.microsoft.com/en-us/cli/azure/snapshot?view=azure-cli-latest#az_snapshot_create

我已经尝试过了。在此示例中,$ disk_location位于eastus中,而$ target_location位于eastus2中。

az snapshot create --name $snapshot_name \
--resource-group $resource_group \
--location $target_location \
--source "$disk_location" \
--no-wait

失败,并显示“找不到资源mdw_data1”。它存在,但不在$ target_location中。

我还尝试创建一个快照,将源作为另一个快照。我遇到了两个问题。首先,它指出快照已经存在,因为我使用的是相同的snapshot_name,并且当我更改为其他名称时,它给了我同样的“未找到”错误。

快照可以是本地冗余的(在单个物理位置3个副本),也可以是区域冗余的(区域内3个可用区域中的3个副本)。在区域脱机的情况下,这都没有帮助。

参考:https://docs.microsoft.com/en-us/azure/storage/common/storage-redundancy

Microsoft还说:“对于要求高可用性的应用程序,Microsoft建议在主要区域中使用ZRS,并且还复制到辅助区域中。”但是我无法按照他们的建议将快照复制到辅助区域。

1 个答案:

答案 0 :(得分:0)

AWS提供了一个命令来将快照从一个区域复制到另一个区域,但是Azure并不直接从其CLI中提供此功能。

参考:https://docs.aws.amazon.com/cli/latest/reference/ec2/copy-snapshot.html

示例:

aws ec2 copy-snapshot \
--region us-east-1 \
--source-region us-west-2 \
--source-snapshot-id snap-066877671789bd71b \
--description "This is my copied snapshot."

天蓝色解决方案:

第1步-在目标位置创建存储帐户

az storage account create --name $account_name \
--resource-group $resource_group \
--location $target_location

第2步-从第1步存储帐户中获取存储密钥

注意:请注意Azure如何将“ storage_account”更改为“ account_account”。

az storage account keys list --resource-group $resource_group \
--account-name $account_name \
--query '[].value' \
--output tsv

第3步-在位于目标位置的新创建的存储帐户中创建容器

az storage container create --name $container_name 
--resource-group $resource_group \
--account-key $account_key \
--account-name $account_name

第4步-授予对您自己的快照的访问权限

这对我来说很奇怪。您必须授予自己访问自己的快照的权限。您还必须设置对自己的补助有多长时间。

duration="7200"

az snapshot grant-access --resource-group $resource_group \
--name $snapshot_id \
--duration-in-seconds $duration \
--query [accessSas] \
--output tsv

第5步-使用SAS将快照复制到存储帐户中的容器

“ destination_blob”是快照的名称,该快照的末尾附加了“ .vhd”。

destination_blob="$snapshot_id"".vhd"

az storage blob copy start --destination-blob "$destination_blob" \
--destination-container "$container_name" \
--account-key "$account_key" \
--account-name "$account_name" \
--source-uri "$sas"

第6步-等待

继续运行直到输出显示“成功”。

az storage blob show --name "$destination_blob" \
--container-name "$container_name" \
--account-key "$account_key" \
--account-name "$account_name" \
--query '[properties.copy.status]' \
--output tsv

第7步-获取您的订阅ID

az account show --query 'id' --output tsv

第8步-创建快照 Azure不允许您使用名称相同但位于不同区域的快照。因此,很遗憾,您必须更新名称。

target_snapshot_id="$snapshot_id""_copy"

az snapshot create --name $target_snapshot_id \
--resource-group $resource_group \
--location $target_location \
--source "https://${account_name}.blob.core.windows.net/${container_name}/${destination_blob}" \
--source-storage-account-id "/subscriptions/${subscription_id}/resourceGroups/${resource_group}/providers/Microsoft.Storage/storageAccounts/${account_name}"

第9步-清理

az storage account delete --resource-group $resource_group \
--name $account_name \
--yes