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."
Azure解决方案:
步骤1-在目标位置创建存储帐户
az storage account create --name $account_name \
--resource-group $resource_group \
--location $target_location
注意:请注意Azure如何将“存储帐户”更改为“帐户帐户”。
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="$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
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}"
az storage account delete --resource-group $resource_group \
--name $account_name \
--yes