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.

Before you begin

Requirements

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

  • There must be 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.
  • If your instance includes GPUs, verify that the GPUs you want to use are available in your target zone. For a list of GPUs and the zones that they are available in, see GPUs on Compute Engine.

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 is usually assigned, but it is possible that the instance keeps the original internal IP address.
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

You can either automatically move an instance by using the gcloud tool or the Compute Engine API, or you can perform a manual move.

Moving an instance requires the following steps:

  • Create 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.

Choosing between a manual and automatic move

  • If you want to move your instance between regions, such as between us-west1-a and asia-south1-b, you must perform the move manually. You must also perform the move manually if your instance includes GPUs or local SSDs.
  • If you are moving an instance within a region, you can use gcloud or the Compute Engine API.

Before you move an instance, ensure that you review the requirements.

gcloud


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

For example, to move an instance called example-instance-1 with all its attached persistent disks, that is currently running in us-central1-b, to us-central1-f, run the following command:

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 myinstance 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. Identify the disks that are associated with the instance that you want to move.

    Go to the disks page

    In this example, you would find the following 2 associated disks for the myinstance instance:

    • A boot disk called myrootdisk
    • A data disk called mydatadisk
  2. 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.

  3. (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
    
  4. 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
    

    To verify that the snapshot is created, run gcloud compute snapshots list.

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

  6. 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].

  7. (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
    
  8. 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

  9. Recreate your instance in us-west1-b.

    • If you had opted to save your instance metadata in a file, for example myinstance.describe , 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.

    • If your instance included GPUs, add GPUs to the instance using the --accelerator option.

    • If the instance uses a specific subnet, add the --subnet [SUBNET_NAME] flag before the --zone [ZONE_NAME] flag.

    For a complete list of additional flags, see gcloud compute instances create.

    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

  10. (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
    
Was this page helpful? Let us know how we did:

Send feedback about...

Compute Engine Documentation