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         |
    +--------------------------------------+------------+---------+------------------+
    | c41f3074-c82a-4837-8673-fa7e9fea7e11 | myInstance | SHUTOFF | private=10.0.0.3 |
    +--------------------------------------+------------+---------+------------------+
    
  2. Create a snapshot using the openstack server image command.

    $ openstack server image create --name myInstanceSnapshot myInstance
    +------------------+------------------------------------------------------+
    | Field            | Value                                                |
    +------------------+------------------------------------------------------+
    | architecture     | x86_64                                               |
    | base_image_ref   | 30590fd9-5ffc-43e8-98ef-2c71844dfc07                 |
    | checksum         | None                                                 |
    | container_format | None                                                 |
    | created_at       | 2016-09-28T22:00:17Z                                 |
    | disk_format      | None                                                 |
    | file             | /v2/images/63c0ce43-173f-4f63-9f2b-90731a439ebf/file |
    | id               | f30b204e-1ce6-40e7-b8d9-b353d4d84e7d                 |
    | image_type       | snapshot                                             |
    | instance_uuid    | 8fe8577d-5c03-4507-af61-db0ad1c6e867                 |
    | min_disk         | 20                                                   |
    | min_ram          | 1024                                                 |
    | name             | myInstanceSnapshot                                   |
    | owner            | 00a72b81702147289bfe3a5bf0848972                     |
    | 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 --file snapshot.raw f30b204e-1ce6-40e7-b8d9-b353d4d84e7d
    

    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.