本文件說明如何啟動及停止非同步複製。
非同步複製功能可用於低 RPO 和低 RTO 的災難復原作業。如要進一步瞭解非同步複製,請參閱「關於非同步複製」。
限制
- 主要磁碟一次只能複製至一個次要磁碟。
- 複製作業停止後,您就無法繼續將資料複製到相同磁碟。您必須建立新的次要磁碟,才能重新開始複製作業。
- 次要磁碟在複製期間,無法附加、刪除或快照。
- 如果您使用地區磁碟做為次要磁碟,且其中一個次要磁碟區域發生區域停機,則從主要磁碟複製到次要磁碟的作業會失敗。
事前準備
- 如果需要在多個磁碟之間對齊複製作業,請建立一致性群組。
- 建立主要磁碟。
- 建立次要磁碟。
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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
-
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.
- Set a default region and zone.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the 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.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
開始複製
使用 Google Cloud 控制台、Google Cloud CLI、REST 或 Terraform 開始複製。
主控台
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下要開始複製的次要磁碟名稱。
按一下「開始複製」。「開始複製」視窗會隨即開啟。
按一下「開始複製」。
gcloud
使用 gcloud compute disks start-async-replication
指令開始複製:
gcloud compute disks start-async-replication PRIMARY_DISK_NAME \ --PRIMARY_LOCATION_FLAG=PRIMARY_LOCATION \ --secondary-disk=SECONDARY_DISK_NAME \ --SECONDARY_LOCATION_FLAG=SECONDARY_LOCATION \ --secondary-disk-project=SECONDARY_PROJECT
更改下列內容:
PRIMARY_DISK_NAME
:主要磁碟的名稱。PRIMARY_LOCATION_FLAG
:主要磁碟的位置標記。如為地區磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。PRIMARY_LOCATION
:主要磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。SECONDARY_DISK_NAME
:次要磁碟的名稱。SECONDARY_LOCATION_FLAG
:次要磁碟的位置標記。如為地區磁碟,請使用--secondary-disk-region
。如為區域磁碟,請使用--secondary-disk-zone
。SECONDARY_LOCATION
:次要磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。SECONDARY_PROJECT
:含有次要磁碟的專案。
Go
Java
Node.js
Python
REST
請使用下列任一方法啟動複製作業:
使用
disks.startAsyncReplication
方法,開始區域磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PRIMARY_DISK_PROJECT/zones/PRIMARY_LOCATION/disks/PRIMARY_DISK_NAME/startAsyncReplication { "asyncSecondaryDisk": "projects/SECONDARY_DISK_PROJECT/SECONDARY_LOCATION_PARAMETER/SECONDARY_LOCATION/disks/SECONDARY_DISK_NAME" }
使用
regionDisks.startAsyncReplication
方法啟動地區磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PRIMARY_DISK_PROJECT/regions/PRIMARY_LOCATION/regionDisks/PRIMARY_DISK_NAME/startAsyncReplication { "asyncSecondaryDisk": "projects/SECONDARY_DISK_PROJECT/SECONDARY_LOCATION_PARAMETER/SECONDARY_LOCATION/disks/SECONDARY_DISK_NAME" }
更改下列內容:
PRIMARY_DISK_PROJECT
:包含主要磁碟的專案。PRIMARY_LOCATION
:主要磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。PRIMARY_DISK_NAME
:主要磁碟的名稱。SECONDARY_DISK_PROJECT
:包含次要磁碟的專案。SECONDARY_LOCATION_PARAMETER
:次要磁碟的位置參數。如為地區磁碟,請使用regions
。如為區域磁碟,請使用zones
。SECONDARY_LOCATION
:次要磁碟的區域或可用區。如為區域性磁碟,請使用區域。如果是區域磁碟,請使用區域。SECONDARY_DISK_NAME
:次要磁碟的名稱。
Terraform
如要開始在主要磁碟和次要磁碟之間複製資料,請使用 compute_disk_async_replication
資源。
如要瞭解如何套用或移除 Terraform 設定,請參閱「基本 Terraform 指令」。
停止複製
您可以停止單一主要或次要磁碟的複製作業,也可以停止一致性群組中的所有磁碟。如果您停止一致性群組中單一磁碟的複製作業,該磁碟的複製時間就會與一致性群組中的其他磁碟不同步。
系統會在容錯移轉和容錯回復情況下執行停止複製作業。如果停止複製作業,就無法重新開始複製到相同的次要磁碟。如要重新啟動複製作業,您必須建立新的次要磁碟並重新開始。
停止磁碟的複製作業後,磁碟的複製作業狀態會變更為 STOPPED
。磁碟複製作對中另一個磁碟 (對應的主要或次要磁碟) 的複製狀態會在稍後更新為 STOPPED
。如要避免時間差,並立即將其他磁碟的複寫狀態更新為 STOPPED
,您必須手動停止其他磁碟的複寫作業。停止兩部磁碟的複製作業不會影響複製作業的停止時間,只會影響磁碟的複製狀態。
停止單一磁碟的複製作業
使用 Google Cloud 控制台、Google Cloud CLI 或 REST 停止單一磁碟的複寫作業。
主控台
請按照下列步驟停止複製:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下要停止複製的主磁碟或次要磁碟名稱。系統會開啟「Manage disk」(管理磁碟) 頁面。
按一下「終止複製作業」。「Terminate replication」視窗隨即開啟。
按一下「終止複製作業」。
gcloud
使用 gcloud compute disks stop-async-replication
指令停止複製:
gcloud compute disks stop-async-replication DISK_NAME \ --LOCATION_FLAG=LOCATION
更改下列內容:
DISK_NAME
:磁碟名稱。LOCATION_FLAG
:磁碟的位置標記。如為地區磁碟,請使用--region
。如果是區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。如要使用區域磁碟,請使用區域。如果是區域磁碟,請使用區域。
Go
Java
Node.js
Python
REST
請使用下列任一方法停止複製作業:
使用
disks.stopAsyncReplication
方法停止區域磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/LOCATION/disks/DISK_NAME/stopAsyncReplication { }
使用
regionDisks.stopAsyncReplication
方法停止區域磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/LOCATION/regionDisks/DISK_NAME/stopAsyncReplication { }
更改下列內容:
PROJECT
:包含磁碟的專案。DISK_NAME
:磁碟名稱。LOCATION
:磁碟的可用區或區域。如為區域磁碟,請使用區域。如果是區域性磁碟,請使用區域。
Terraform
如要停止主要和次要磁碟上的複製作業,請移除 compute_disk_async_replication
資源。
停止一致性群組的複製作業
使用 Google Cloud 控制台、Google Cloud CLI 或 REST,停止一致性群組中所有磁碟的複製作業。
主控台
如要停止一致性群組中所有磁碟的複製作業,請執行下列操作:
前往 Google Cloud 控制台中的「非同步複製」頁面。
按一下「一致性群組」分頁標籤。
按一下要停止複製的一致性群組名稱。系統隨即會開啟「Manage consistency group」(管理一致性群組) 頁面。
按一下「終止複製作業」。「Terminate replication」視窗隨即開啟。
按一下「終止複製作業」。
gcloud
使用 gcloud compute disks stop-group-async-replication
指令,停止複製一致性群組中的所有磁碟:
gcloud compute disks stop-group-async-replication CONSISTENCY_GROUP \ --LOCATION_FLAG=LOCATION
更改下列內容:
CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。LOCATION_FLAG
:一致性群組中磁碟的位置標記。如為地區磁碟,請使用--region
。如為區域磁碟,請使用--zone
。LOCATION
:磁碟的區域或可用區。如果是地區磁碟,請使用區域。如果是區域磁碟,請使用區域。
Go
Java
Node.js
Python
REST
請使用下列任一方法,停止一致性群組中所有磁碟的複寫作業:
使用
disks.stopGroupAsyncReplication
方法停止區域磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/zones/LOCATION/disks/stopGroupAsyncReplication { "resourcePolicy": "CONSISTENCY_GROUP" }
使用
regionDisks.stopGroupAsyncReplication
方法停止區域磁碟的複製作業:POST https://compute.googleapis.com/compute/v1/projects/PROJECT/regions/LOCATION/regionDisks/DISK_NAME/stopAsyncReplication { "resourcePolicy": "CONSISTENCY_GROUP" }
更改下列內容:
DISK_NAME
:磁碟名稱LOCATION
:磁碟的可用區或區域。如為區域磁碟,請使用區域。如果是區域性磁碟,請使用區域。CONSISTENCY_GROUP
:一致性群組的網址。例如:projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
。
後續步驟
- 瞭解如何容錯移轉和復原。
- 瞭解如何監控非同步複製作業效能。