【问题标题】:Copy Azure snapshots to different Region将 Azure 快照复制到不同的区域
【发布时间】:2021-01-10 04:18:17
【问题描述】:

我正在尝试使用 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 中。

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

快照可以是本地冗余(单个物理位置中的 3 个副本)或区域冗余(跨区域内 3 个可用区的 3 个副本)。在区域离线的情况下,两者都没有帮助。

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

此外,微软表示:“对于需要高可用性的应用程序,微软建议在主要区域使用 ZRS,并复制到次要区域。”但是我无法按照他们的建议将我的快照复制到次要区域。

【问题讨论】:

    标签: azure azure-disk


    【解决方案1】:

    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
    

    第 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
    

    【讨论】:

      猜你喜欢
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-18
      • 2018-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多