Moving an Instance Between Zones

You 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.

To move your instance, use the following process:

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

If you want to move your instance within a region, you can automate the steps using the gcloud command-line tool, or the Compute Engine API.

If you want to move your instance between regions, such as between us-west1-a and asia-south1-b, you must perform these steps manually.

Before you begin

Requirements

Before you move your instance, you must meet the following requirements:

  • The source instance must not contain a local SSD. If you need to move an instance with a local SSD, you must delete and recreate the instance in the new location.
  • There is enough quota in your project for new snapshots and to promote any ephemeral external IP addresses.
  • In your destination region, there is enough quota for the new instance and disks. For example, if you have three disks attached to the instance you want to move, you need enough quota to create three temporary persistent disk snapshots and three new disks. After you have created your new disks, you can delete your temporary snapshots.
  • The persistent disks that are attached to the instance you want to move are not attached to more than one instance.

After you move your instance, you must update any existing references that you have to the original resource, such as any target instances or target pools that are pointing to the old instance.

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 you move the instance between zones in different regions, the new instance will be assigned an ephemeral external IP address. If the instance had a reserved IP address, you can reassign the address when you recreate the instance in the new zone.
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 a full list of CPU platforms in each zone, see Available regions and 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 is empty.
Image ID The image ID is empty.
Last detached timestamp The last detached timestamp is empty.
Last attached timestamp The last attached timestamp changes to the timestamp when the new disk was attached to the new instance.

Properties changing for both instances and disks

Property name Changes
ID A new resource ID is generated.
Creation timestamp A new creation timestamp is generated.
Zone resource URLs All zone resource URLs change to reflect the destination zone. The following is a list of resource URLs that change:
  • 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

Before you move your instance, read the Requirements for moving instances.

If you are moving an instance within a region, you can use gcloud or the Compute Engine API. If you are moving an instance between regions, you must move the instance manually.

gcloud


Make sure that your instance is running. Then, in gcloud, use the compute instances move subcommand to move your instance:

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

This operation might take several minutes to complete.

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/us-central1-b"
}

Manual


The following example describes how to move an instance with two persistent disks, myrootdisk and mydatadisk, from europe-west1-a to us-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 the disks are 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 is also removed. You can save that information in a separate file, then 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, to ensure that your snapshot is consistent with the state of the persistent disk, clear your disk buffers before you take a snapshot.

    After 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)?

    Because you turned off the auto-delete state for the disks earlier in this process, enter Y to continue and ignore the warning.

  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 names of the persistent disks for the new disks, you must delete the existing disks to release the names. Deleting your disks also saves on persistent disk storage costs.

    If you do not plan to reuse the same disk names, you can delete the persistent disks later.

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

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

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

    Then create the data disk.

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

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

  8. Recreate your instance in us-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 reassign that address to your new instance by specifying the --address ADDRESS option.

    gcloud compute instances create myinstanceb --machine-type n1-standard-4 \
        --zone us-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 us-west1-b     n1-standard-4 10.240.173.229 146.148.112.106 RUNNING

  9. (Optional) Delete your persistent disk snapshots.

    After you confirm that your virtual machines are moved, save on storage costs by deleting the temporary snapshots that you created.

    gcloud compute snapshots delete myrootsnapshot mydatasnapshot
    

    If you no longer need your backup snapshots, delete those snapshots as well:

    gcloud compute snapshots delete backup-myrootsnapshot backup-mydatasnapshot
    

Send feedback about...

Compute Engine Documentation