Moving an Instance Between Zones

Compute Engine can move your instances between zones by taking a snapshot of your persistent disks, using the snapshots to launch new instances in the desired zone, and deleting your original resources. If a zone is deprecated, you can use this method to move your instances from the deprecated zone.

In detail, Compute Engine will:

  • Take snapshots of persistent disks attached to the source instance.
  • Create copies of the persistent disks in the destination zone.
  • For instances moving within the same region, temporarily promote any ephemeral external IP addresses assigned to the instance to a static external IP address.
  • Create a new instance in the destination zone.
  • Attach the newly created persistent disks to your new instance.
  • Assign an external IP address to the new instance. If necessary, demote the address back to an ephemeral external IP address.
  • Delete the snapshots, original disks, and original instance.

If you want to manually move your instance, you can also perform these steps by hand.

Before you begin

Requirements

Before you can use this feature to move your instance, make sure that:

  • There is enough quota in your project for Compute Engine to create new snapshots and promote any ephemeral external IP addresses, and enough quota for the new instance and disks in the destination zone. For example, if you have three disks attached to the instance you want to move, Compute Engine will need enough quota to create three temporary persistent disk snapshots, which will be removed after the new disks have been successfully created.
  • The persistent disks that are attached to the instance you want to move are not attached to more than one instance.
  • The source instance does not contain a local SSD. Currently, it is not possible to migrate an instance that has a local SSD and the contents of your local SSD is discarded when you move the instance.

Once your instance and disks have been moved, you will still need to update any existing references you have to the original resource, such as any target instances or target pools that are pointing to the old instance. This will not be done for you automatically.

Caution: During the move, do not modify any of the resources being moved or modify any of the temporary resources that are created for the purposes of the move, as this could cause the move to fail. Any temporary resources created for the move will have unique names that are automatically generated from the name of the source persistent disk or the source ephemeral external IP address.

If the move is interrupted, Compute Engine will stop the move and no further action will be taken. At any point during this process, your data is preserved either in snapshots or on the persistent disk itself. However, once a move has begun, Compute Engine cannot roll back any changes already made.

Resource properties

During the move, some server-generated properties of your instance and disks will change.

Properties that change for instances

Property name Changes
Internal IP address A new internal IP address will be assigned.
External IP address
  • If the instance is moving between zones in the same region, the external IP address remains the same.
  • If the instance is moving between zones in different regions, the new instance will be assigned an ephemeral external IP address, regardless of whether the original instance had a static or ephemeral external IP address.
CPU platform Depending on the available CPU platform in your destination zone, your instance might have a different CPU platform after it has been moved. For example, an instance in us-central1-a that is being moved to us-central1-f will see it's CPU platform change from a Sandy Bridge processor to an Ivy Bridge processor.

For a full list of CPU platforms, see Zones.

Properties that change for disks

Property name Changes
Source snapshot The source snapshot of the new disk will be set to the temporary snapshot that is created during the move.
Source snapshot ID The source snapshot ID is set to the temporary snapshot's ID.
Source image The source image field will be empty.
Image ID The image ID will be empty.
Last detached timestamp The last detached timestamp will be empty.
Last attached timestamp The last attached timestamp will update to the timestamp when the newly-moved disk was attached to the newly-moved instance.

Properties changing for both instances and disks

Property name Changes
ID A new resource ID will be generated.
Creation timestamp A new creation timestamp will be generated.
Zone resource URLs All zone resource URLs will change to reflect the destination zone. The following is a list of resource URLs that will change when moving instances:
  • An instance's source disk URL
  • An instance's machine type URL
  • Self-link URLs
  • Zone URLs
  • Disk type URLs
  • Any URLs of instances listed in a disk's users[] list

Move your instance

You can move your instance using the instructions below. You can only move one instance per request but you can make multiple requests in parallel to move several instances at once. Keep in mind that you will need to ensure you have enough quota in your destination zones to move all your desired instances.

Before you move your instance, it is important that you understand the Requirements for using this feature.

gcloud compute


In gcloud, use the gcloud compute instances move sub-command to move your instance:

gcloud compute instances move example-instance \
    --zone us-central1-a --destination-zone us-central1-f

This operation will take three or more minutes to complete. You can monitor the status using gcloud compute instances list, where you can see the original instance being terminated in the source zone and then appearing in the destination zone.

API


In the API, make a POST request to the moveInstance method with a request body that contains the targetInstance and the destinationZone. For example:

{
   "targetInstance": "zones/us-central1-a/instances/example-instance",
   "destinationZone": "zones/europe-west1-d"
}

Manual


You can also choose to manually move your instance between zones.

The following example describes how to move an instance with two persistent disks, myrootdisk and mydatadisk, from the europe-west1-a zone to europe-west1-b. The example instance looks like the following:

gcloud compute instances list

NAME       ZONE           MACHINE_TYPE  INTERNAL_IP    EXTERNAL_IP     STATUS
myinstance europe-west1-a n1-standard-4 10.240.116.177 146.148.112.106 RUNNING

To move the instance to another zone:

  1. First, set the auto-delete state of myrootdisk and mydatadisk to ensure that it is not automatically deleted when the instance is deleted.

    gcloud compute instances set-disk-auto-delete myinstance --zone europe-west1-a \
        --disk myrootdisk --no-auto-delete
    

    If the state was updated, gcloud compute returns the response Updated [...]. If the auto-delete state was already set to false, then gcloud compute returns an empty response.

  2. (Optional) Save your instance metadata.

    When you delete your instance, the instance metadata will also be removed. You can save that information in a separate file so that you can reapply the instance metadata to the new instance.

    gcloud compute instances describe myinstance --zone europe-west1-a | \
        tee myinstance.describe
    
  3. Create backups of your data.

    As a precaution, create backups of your data using persistent disk snapshots. Since the persistent disks are still attached to the instance, you should clear your disk buffers before you take a snapshot to ensure your snapshot is consistent with the state of your persistent disk.

    Once you have cleared your disk buffers, create the snapshots as follows:

    gcloud compute disks snapshot myrootdisk mydatadisk \
        --snapshot-names backup-myrootsnapshot,backup-mydatasnapshot \
        --zone europe-west1-a
    
  4. Delete your instance.

    Deleting your instance will shut it down cleanly and detach any persistent disks.

    gcloud compute instances delete myinstance --zone europe-west1-a
    

    The following instances will be deleted. Attached disks configured to
    be auto-deleted will be deleted unless they are attached to any other
    instances. Deleting a disk is irreversible and any data on the disk
    will be lost.
     - [myinstance] in [europe-west1-a]

    Do you want to continue (Y/n)?

    The warning does not apply in this case because we turned off the auto-delete state for the disks attached to myinstance in step 1. Enter Y to continue, which returns the response:

    Deleted [...].

  5. Next, create another snapshot of both the root disk and the data disk.

    gcloud compute disks snapshot myrootdisk mydatadisk \
        --snapshot-names myrootsnapshot,mydatasnapshot \
        --zone europe-west1-a
    

    Created [.../mydatasnapshot].
    Created [.../myrootsnapshot].

  6. (Optional) Delete your persistent disks.

    If you plan to reuse the same names of the persistent disks for the new disks, you will need to delete the existing disks to release the names. This is because Compute Engine requires unique names for resources within a project. Deleting your disks will also save on persistent disk storage costs as well.

    You can choose to delete your persistent disks later, after you have successfully moved your instance to the new zone, if you do not plan to reuse the same disk names. This gives you the added benefit of keeping your data around to make sure it is successfully migrated.

    gcloud compute disks delete myrootdisk mydatadisk --zone europe-west1-a
    
  7. Create new persistent disks in europe-west1-b from the snapshots you just created. First create the root disk.

    gcloud compute disks create myrootdiskb --source-snapshot myrootsnapshot \
        --zone europe-west1-b
    

    Created [.../myrootdiskb].
    NAME        ZONE           SIZE_GB TYPE        STATUS
    myrootdiskb europe-west1-b 100     pd-standard READY

    Then create the data disk.

    gcloud compute disks create mydatadiskb --source-snapshot mydatasnapshot \
        --zone europe-west1-b
    

    Created [.../mydatadiskb].
    NAME        ZONE           SIZE_GB TYPE        STATUS
    mydatadiskb europe-west1-b 4000    pd-standard READY

  8. Recreate your instance in europe-west1-b.

    If you saved your instance metadata in a myinstances.describe file, you can use it to set the same metadata on your instance.

    If your instance had a reserved IP address, you can also reassign that address to your new instance by specifying the --address ADDRESS option.

    gcloud compute instances create myinstanceb --machine-type n1-standard-4 \
        --zone europe-west1-b \
        --disk name=myrootdiskb,boot=yes,mode=rw \
        --disk name=mydatadiskb,mode=rw
    

    Created [.../myinstanceb].
    NAME        ZONE           MACHINE_TYPE  INTERNAL_IP    EXTERNAL_IP     STATUS
    myinstanceb europe-west1-b n1-standard-4 10.240.173.229 146.148.112.106 RUNNING

  9. (Optional) Delete your persistent disk snapshots.

    Once you have confirmed that your virtual machines were moved over successfully and you no longer need the snapshots for other purposes, you can choose to delete the snapshots you created to save on storage costs.

    gcloud compute snapshots delete myrootsnapshot mydatasnapshot
    

    You can also delete your backup snapshots, but make sure you no longer need these snapshots, since there is no way to retrieve snapshots after they have been deleted:

    gcloud compute snapshots delete backup-myrootsnapshot backup-mydatasnapshot
    

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Compute Engine Documentation