設定區域性快照的建立和還原位置


根據預設,快照會以全域範圍建立。全域範圍快照會儲存在特定儲存位置,並可在任何區域或可用區還原 (用於建立新磁碟)。如要進一步控管位置隔離,可以建立區域範圍快照。區域範圍快照會將所有快照資料和中繼資料儲存在範圍區域中。您也可以使用區域範圍快照,限制可建立及還原快照的區域。

本文說明如何設定允許的地區,以建立及還原地區快照。

事前準備

  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列其中一個選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

      1. After installing the Google Cloud CLI, initialize it by running the following command:

        gcloud init

        If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

      2. Set a default region and zone.
      3. REST

        如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

          After installing the Google Cloud CLI, initialize it by running the following command:

          gcloud init

          If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

        詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。

限制

  • 設定區域範圍會覆寫專案的所有預設儲存空間位置設定
  • 設定區域範圍只會套用至新的區域快照。
  • 您無法將全域範圍的快照轉換為區域範圍的快照。 您必須建立範圍適當的新快照。

必要角色和權限

如要取得設定區域範圍快照儲存和還原位置所需的權限,請要求管理員在專案中授予您下列 IAM 角色:

  • Compute 執行個體管理員 (v1) (roles/compute.instanceAdmin.v1)
  • 如要連線至可做為服務帳戶執行的 VM,請使用「服務帳戶使用者 (v1)」(roles/iam.serviceAccountUser)。

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」一文。

這些預先定義的角色具備設定快照建立和還原位置所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:

設定允許建立快照的位置

根據預設,您可以在所有區域建立快照。如要限制可建立區域範圍快照的位置,請在專案層級設定允許的存取位置。設定存取位置後,您只能在這些位置為專案建立區域範圍快照。

gcloud

如要允許區域 A 中的區域磁碟在任何區域建立快照,請使用 gcloud beta compute disk-settings update 指令

  gcloud beta compute disk-settings update \
      --zone=ZONE_A \
      --access-location-policy=all-regions \

如要允許 A 地區的地區磁碟在任何地區建立快照,請使用 gcloud beta compute disk-settings update 指令

  gcloud beta compute disk-settings update \
      --region=REGION_A \
      --access-location-policy=all-regions

如要讓 A 地區的磁碟僅在 B 地區建立快照,請使用 gcloud beta compute disk-settings update 指令

  gcloud beta compute disk-settings update \
      --access-location-policy=specific-regions \
      --region=REGION_A \
      --add-access-locations=REGION_B

更改下列內容:

  • ZONE_A:磁碟所在的可用區,可在任何區域建立快照。
  • REGION_A:所有磁碟 (位於專案中) 的區域,需要區域範圍快照建立限制。
  • REGION_B:允許建立區域範圍快照的區域。您可以將多個區域設為允許存取的位置。您必須將來源磁碟儲存所在的區域納入允許的區域。

REST

如要允許區域 A 中的區域磁碟在任何區域建立快照,請向 diskSettings.patch 方法發出 PATCH 要求:

  PATCH https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE_A/diskSettings?updateMask=accessLocation

  {
    "accessLocation":
    {
      "policy":"ALL_REGIONS"
    }
  }

如要允許區域 A 中的區域磁碟僅在區域 B 中建立快照,請對 regionDiskSettings.patch 方法發出 PATCH 要求:

  PATCH https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/regions/REGION_A/diskSettings?updateMask=accessLocation

  {
    "accessLocation":
    {
      "policy":"SPECIFIC_REGIONS",
      "locations":
      {
        "REGION_B":{"region":"REGION_B"}
      }
    }
  }

更改下列內容:

  • PROJECT_ID:專案 ID。
  • ZONE_A:磁碟的可用區。
  • REGION_A:磁碟所在的區域。
  • REGION_B:允許建立快照的區域。 您可以將多個區域設為允許存取位置。您必須將來源磁碟儲存所在的區域納入允許的區域。

設定允許的快照還原位置

根據預設,您可以將區域和全域範圍的快照還原至任何區域。如要為區域範圍快照設定還原位置,請在專案層級設定允許的存取位置。您必須為每個專案分別設定允許的存取位置。設定存取位置後,您只能在這些位置還原專案的區域範圍快照。

gcloud

如要允許在所有區域還原 A 區域中專案的快照,請使用 gcloud beta compute snapshot-settings update 指令

  gcloud beta compute snapshot-settings update \
      --project=PROJECT_ID \
      --region=REGION_A \
      --access-location-policy=all-regions

如要讓區域 A 中專案的快照只能在區域 B 中還原,請使用 gcloud beta compute snapshot-settings update 指令

  gcloud beta compute snapshot-settings update \
      --project=PROJECT_ID \
      --access-location-policy=specific-regions \
      --region=REGION_A \
      --add-access-locations=REGION_B

更改下列內容:

  • PROJECT_ID:專案 ID。
  • REGION_A:儲存區域範圍快照的區域。
  • REGION_B:允許還原區域範圍快照的地區。您可以將多個區域設為允許還原的位置。

REST

如要讓區域 A 中專案的快照在所有區域還原,請對 regionSnapshotSettings.patch 方法發出 PATCH 要求:

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_A/snapshotSettings?updateMask=accessLocation

  {
    "accessLocation":
    {
      "policy":"ALL_REGIONS"
    }
  }

如要讓區域 A 中專案的快照只能在區域 B 中還原,請對 regionSnapshotSettings.patch 方法發出 PATCH 要求

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_A/snapshotSettings?updateMask=accessLocation

  {
    "accessLocation":
    {
      "policy":"SPECIFIC_REGIONS",
      "locations":
        {"REGION_B":
          {"region":"REGION_B"}
        }
    }
  }

更改下列內容:

  • PROJECT_ID:專案 ID。
  • REGION_A:儲存區域範圍快照的區域。
  • REGION_B:允許還原區域範圍快照的地區。您可以將多個區域設為允許還原的位置。

編輯允許的快照還原位置

gcloud

如要查看儲存在 A 區域的專案快照允許還原位置,請使用 gcloud beta compute snapshot-settings describe 指令

  gcloud beta compute snapshot-settings describe \
      --project=PROJECT_ID \
      --region=REGION_A

如要從儲存在 A 區域的專案快照允許還原位置清單中移除 B 區域,請使用 gcloud beta compute snapshot-settings update 指令

  gcloud beta compute snapshot-settings update \
      --project=PROJECT_ID \
      --access-location-policy=specific-regions \
      --remove-access-locations=REGION_B \
      --region=REGION_A

更改下列內容:

  • PROJECT_ID:專案 ID。
  • REGION_A:儲存區域範圍快照的區域。
  • REGION_B:要移除/還原區域範圍快照存取權的區域。

REST

如要查看儲存在 A 區域的專案快照允許還原位置,請對 regionSnapshotSettings.get 方法發出 GET 要求:

  GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_A/snapshotSettings

如要從專案的快照允許還原位置清單中移除區域 B,請向 regionSnapshotSettings.patch 方法發出 PATCH 要求

  PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_A/snapshotSettings?updateMask=accessLocation

  {
    "accessLocation":
    {
      "policy":"SPECIFIC_REGIONS",
      "locations":
        {"REGION_B":{}}
    }
  }

更改下列內容:

  • PROJECT_ID:專案 ID。
  • REGION_A:儲存區域範圍快照的區域。
  • REGION_B:要移除/還原區域範圍快照存取權的區域。