Using Snapshots to Migrate Instances

You can use a snapshot to migrate an instance from one hypervisor to another, or from one Metacloud availability zone to another availability zone. The process involves downloading a snapshot as an image from the source project and importing the snapshot to the destination project. Snapshots are also useful for creating a backup of an instance at a particular point in time so you can launch a new, identical instance using the snapshot.

If the instance leverages shared storage (with Ceph or NFS), you can create a snapshot and perform a live migration. In order to migrate an instance with a volume backed by NFS, you must detach the volume, migrate the instance, and then reattach the volume.

To migrate an instance using a snapshot:

  1. You can create an image from a running server instance, but if you want to preserve data, you must shut down the source VM and verify the instance status is SHUTOFF before creating the snapshot.

    $ openstack server stop myInstance
    
    $ openstack server list | grep "myInstance"
    +-----------------+------------+---------+------------------+
    | ID              | Name       | Status  | Networks         |
    +-----------------+------------+---------+------------------+
    | <instance_id>   | myInstance | SHUTOFF | private=10.0.0.3 |
    +-----------------+------------+---------+------------------+
    
  2. Create a snapshot.

    $ openstack server image create --name myInstanceSnapshot myInstance
    +------------------+-------------------------------------+
    | Field            | Value                               |
    +------------------+-------------------------------------+
    | architecture     | x86_64                              |
    | base_image_ref   | <image_id>                          |
    | checksum         | None                                |
    | container_format | None                                |
    | created_at       | 2016-09-28T22:00:17Z                |
    | disk_format      | None                                |
    | file             | /v2/images/63c0ce-4f.../file        |
    | id               | <snap_id>                           |
    | image_type       | snapshot                            |
    | instance_uuid    | <instance_id>                       |
    | min_disk         | 20                                  |
    | min_ram          | 1024                                |
    | name             | myInstanceSnapshot                  |
    | owner            | 00a72b8170214728...                 |
    | protected        | False                               |
    | schema           | /v2/schemas/image                   |
    | size             | 0                                   |
    | status           | queued                              |
    | tags             | []                                  |
    | updated_at       | 2016-09-28T22:00:17Z                |
    | user_id          | 1133e60                             |
    | virtual_size     | None                                |
    | visibility       | private                             |
    +------------------+-------------------------------------+
    
  3. Download the snapshot using the image ID or the image name. Saving the image can take time, depending on the size of the snapshot.

    $ openstack image save <IMAGE_ID> --file snapshot.raw
    

    Make the image available to the new environment, either through HTTP or direct upload to a machine (scp).

  4. Import the snapshot file into the new project or cloud environment.

    $ openstack image create --container-format bare --disk-format qcow2 --file snapshot.raw
    
  5. In the new project or cloud environment, use the snapshot to create and launch the new instance.

    $ openstack server create \
       --flavor <FLAVOR> \
       --image myInstanceSnapshot \
       --key-name <KEY_NAME> \
       --security-group <SEC_GROUP_NAME> \
       --nic net-id=<NET_UUID> \
       myNewInstance
    

    Note
    For more information about launching instances, see Launching an Instance from an Image.