Configure Persistent Disk Asynchronous Replication


This document describes how to configure Persistent Disk Asynchronous Replication (PD Async Replication). PD Async Replication is useful for low-RPO, low-RTO disaster recovery.

Before you can start replication, you must configure PD Async Replication by setting up a disk replication pair. A disk replication pair consists of a primary and secondary disk.

After you create a disk replication pair, you must start replication to begin replicating data between the primary and secondary disk.

Limitations

Secondary disks must be blank when created. They can't be created from images, snapshots, or other disks.

Before you begin

  • Choose a region pair .
  • Optionally create a consistency group.
  • If you haven't already, set up authentication. Authentication is the process by which your identity is verified for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine as follows.

    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. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. Set a default region and zone.

    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.

      Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init

Set up a disk replication pair

Before you can replicate data between disks, you need to configure replication by completing the following tasks:

  1. Choose a region pair and your primary and secondary regions.
  2. Optional: If you need to coordinate replication across a group of disks, create a consistency group in the primary region. You must add primary disks to a consistency group before you start replication.
  3. Create or select the primary disks. You can optionally add these disks to the consistency group.
  4. Create new, blank secondary disks.

Disk requirements

Disks must meet the following requirements to be used as primary or secondary disks for PD Async Replication:

Create or select a primary disk

The primary disk is the boot or data disk that is attached to the VM where the workload runs. You can use any pre-existing disk that meets the disk requirements as a primary disk, or you can create a new disk. If you want to use an existing disk as a primary disk, you don't need to perform any additional configuration on the disk. Proceed to create a secondary disk to complete PD Async Replication configuration.

Create a primary disk

Create a primary disk using the methods described in one of the following documents.

  • Create a primary boot disk while creating a VM. Optionally add the disk to a consistency group by creating the VM using the gcloud CLI or REST and specifying one of the following:

    • If you create the VM using the gcloud CLI, specify the --create-disk flag:

      --create-disk=disk-resource-policy=projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
      
    • If you create the VM using REST, specify the resourcePolicies property:

      "disks":
      {
      …
      "resourcePolicies": "projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME"
      }
      
  • Create a primary data disk while creating a VM. Optionally add the disk to a consistency group by creating the VM using the gcloud CLI or REST and specifying one of the following:

    • If you create the VM using the gcloud CLI, specify the --create-disk flag:

      --create-disk=disk-resource-policy=projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
      
    • If you create the VM using REST, specify the resourcePolicies property:

      "disks":
      {
      …
      "resourcePolicies": "projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME"
      }
      
  • Create a primary data disk without creating a VM. Optionally add the disk to a consistency group by creating the VM using the Google Cloud console, gcloud CLI, or REST and specifying one of the following:

    • If you create the disk using the Google Cloud console, select the consistency group from the Consistency group dropdown.

    • If you create the disk using the gcloud CLI, specify the --resource-policies flag:

      --resource-policies=projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME
      
    • If you create the disk using REST, specify the resourcePolicies property:

      "disks":
      {
      …
      "resourcePolicies": "projects/PROJECT/regions/REGION/resourcePolicies/CONSISTENCY_GROUP_NAME"
      }
      

    Replace the following:

    • PROJECT: the project that contains the consistency group
    • REGION: the region that the consistency group is location in
    • CONSISTENCY_GROUP_NAME: the name of the consistency group to add the disk to

Create a secondary disk

The secondary disk is a data disk in a separate region from the primary disk, that receives and writes replicated data from the primary disk. When configuring PD Async Replication, you must create a new, blank secondary disk that references the primary disk.

To create a secondary disk with the same properties as the primary disk, follow the steps in Create a secondary disk identical to the primary disk. The secondary disk inherits the primary disk's properties, such as its boot configuration and labels.

To create a secondary disk that differs from the primary disk, see Create a custom secondary disk.

Create a secondary disk identical to the primary disk

This section describes how to create a secondary disk identical to the primary disk.

You can create a secondary disk with the Google Cloud console, the gcloud CLI, or REST.

Console

Create a secondary disk and start replication by doing the following:

  1. In the Google Cloud console, go to the Disks page.

    Go to Disks

  2. Click the name of the primary disk. The Manage disk page opens.

  3. Click Create secondary disk.

  4. In the Name field, enter a name for the disk.

  5. In the Location section, do one of the following:

  6. Click Create. Compute Engine creates the disk and starts replication.

gcloud

Create a secondary disk using the gcloud compute disks create command:

gcloud compute disks create SECONDARY_DISK_NAME \
    --SECONDARY_LOCATION_FLAG=SECONDARY_LOCATION \
    --size=SIZE \
    --primary-disk=PRIMARY_DISK_NAME \
    --PRIMARY_DISK_LOCATION_FLAG=PRIMARY_LOCATION \
    --primary-disk-project=PRIMARY_DISK_PROJECT

To create a regional secondary disk, additionally specify the --replica-zones flag:

--replica-zones=ZONE_1,ZONE_2

Replace the following:

  • SECONDARY_DISK_NAME: the name for the secondary disk.
  • SECONDARY_LOCATION_FLAG: the location flag for the secondary disk. To create a regional secondary disk, use --region. To create a zonal secondary disk, use --zone.
  • SECONDARY_LOCATION: the region or zone for the secondary disk.
  • SIZE: the size, in GB, of the new disk. The size must be the same as the size of the primary disk. Acceptable sizes range, in 1 GB increments, from 10 GB to 2000 GB.
  • PRIMARY_DISK_NAME: the name of the primary disk that the secondary disk receives data from.
  • PRIMARY_LOCATION_FLAG: the location flag for the primary disk.
    • For a regional primary disk, use --primary-disk-region.
    • For a zonal primary disk, use --primary-disk-zone.
  • PRIMARY_LOCATION: the primary disk's region or zone.
    • For a regional disk, use the region.
    • For a zonal disks use the zone.
  • PRIMARY_PROJECT: the project that contains the primary disk.
  • ZONE_1: one of the zones that the regional disk is replicated to. Must be a zone within the specified region and must be different than ZONE_2.
  • ZONE_2: one of the zones that the regional disk is replicated to. Must be a zone within the specified region and must be different than ZONE_1.

REST

Create a zonal or regional secondary disk using one of the following methods:

  • To create a zonal secondary disk, use the disks.insert method:

    POST https://compute.googleapis.com/compute/v1/projects/SECONDARY_DISK_LOCATION/zones/SECONDARY_DISK_ZONE/disks
    
    {
    "name": "SECONDARY_DISK_NAME",
    "sizeGb": "DISK_SIZE",
    "type": "DISK_TYPE"
    "asyncPrimaryDisk": {
      "disk": "projects/PRIMARY_DISK_PROJECT/PRIMARY_DISK_LOCATION_PARAMETER/PRIMARY_DISK_LOCATION/disks/PRIMARY_DISK_NAME"
      }
    }
    
  • To create a regional secondary disk, use the regionDisks.insert method:

    POST https://compute.googleapis.com/compute/v1/projects/SECONDARY_DISK_PROJECT/regions/SECONDARY_DISK_LOCATION/disks
    
    {
    "name": "SECONDARY_DISK_NAME",
    "sizeGb": "DISK_SIZE",
    "type": "DISK_TYPE"
    "asyncPrimaryDisk": {
      "disk": "projects/PRIMARY_DISK_PROJECT/PRIMARY_DISK_LOCATION_PARAMETER/PRIMARY_DISK_LOCATION/disks/PRIMARY_DISK_NAME"
      }
    }
    

Replace the following:

  • SECONDARY_DISK_PROJECT: the project for the secondary disk.
  • SECONDARY_DISK_LOCATION: the region or zone for the secondary disk.
    • For a regional disk, use the region.
    • For a zonal disk, use the zone.
  • SECONDARY_DISK_NAME: the name for the secondary disk.
  • DISK_SIZE: the size of the secondary disk. Must be the same as the size of the primary disk.
  • SECONDARY_DISK_TYPE: the disk type. Must be one of pd-ssd or pd-balanced.
  • PRIMARY_DISK_PROJECT: the project that contains the primary disk.
  • PRIMARY_DISK_LOCATION_PARAMETER: the location parameter for the primary disk.
    • For a regional primary disk, use regions.
    • For a zonal primary disk, use zones.
  • PRIMARY_DISK_LOCATION: the primary disk's region or zone. For regional disks, use the region. For zonal disks, use the zone.
  • PRIMARY_DISK_NAME: the name of the primary disk that the secondary disk receives data from.

Create a custom secondary disk

This section discusses how to create a custom secondary disk, that is, a secondary disk whose properties differ from the primary disk.

If the primary disk is a boot disk, you can't change or remove any of the primary disk's guest OS features. You can only add more guest OS features. For more information, see Secondary disk customization.

You can create a custom secondary disk with the gcloud CLI or REST. You can't customize the secondary disk from the Google Cloud console.

gcloud

To create a custom secondary disk, use the gcloud compute disks create command as described in Create a secondary disk identical to the primary disk. Use additional flags to customize the secondary disk's properties.

The following are examples of how to customize the secondary disk:

  • To specify additional guest OS features, use the --guest-os-features parameter. You don't have to include the guest OS features of the primary disk. The secondary disk automatically inherits the guest OS features of the primary disk.

     --guest-os-features=UEFI_COMPATIBLE,GVNIC,MULTI_IP_SUBNET
     

  • To assign additional labels to the secondary disk, use the --labels parameter. You don't have to include the labels of the primary disk. The secondary disk automatically inherits the labels of the primary disk.
      --labels=secondary-disk-for-replication=yes
      

REST

To create a custom secondary disk, use the same method described in Create a secondary disk identical to the primary disk. Specify additional fields to customize the secondary disk's properties.

The following are examples of how to customize the secondary disk:

  • To specify additional guest OS features, use the guestOsFeatures field. You don't need to include the guest OS features of the primary disk. The secondary disk automatically inherits the guest OS features of the primary disk.
    "guestOsFeatures": [
      {
        "type": "NEW_FEATURE_ID_1"
      },
      {
        "type": "NEW_FEATURE_ID_1"
      }
    ]
    
  • To assign additional labels to the secondary disk, use the labels field. You don't need to include the labels of the primary disk. The secondary disk automatically inherits the labels from the primary disk.
      "labels": [
        {
          "key": "value"
        },
      ]
    

Start replication

After you create a primary and secondary disk, you must start replication to begin replicating data from the primary disk to the secondary disk.

What's next