使用快照来迁移实例

使用快照来迁移实例

要使用快照从OpenStack工程到云迁移实例,完成如下步骤

在源项目:

  1. 创建一个实例的快照
  2. 下载快照作为镜像

到目标项目:

  1. 将快照导入到新环境中
  2. 从快照中重启云主机

注解

某些云提供商仅允许管理员执行此任务。

创建一个实例的快照

  1. 为了保证所有的数据已经存储到硬盘,创建快照之前需要关闭源虚拟机。如果有必要,列出实例来浏览实例名称。

    $ openstack server list
    +--------------------------------------+------------+--------+------------------------------+------------+
    | ID                                   | Name       | Status | Networks                     | Image Name |
    +--------------------------------------+------------+--------+------------------------------+------------+
    | c41f3074-c82a-4837-8673-fa7e9fea7e11 | myInstance | ACTIVE | private=10.0.0.3             | cirros     |
    +--------------------------------------+------------+--------+------------------------------+------------+
    
  2. Use the openstack server stop command to shut down the instance:

    $ openstack server stop myInstance
    
  3. 使用:command:openstack server list`命令来确保实例状态是``SHUTOFF`

    $ openstack server list
    +--------------------------------------+------------+---------+------------------+------------+
    | ID                                   | Name       | Status  | Networks         | Image Name |
    +--------------------------------------+------------+---------+------------------+------------+
    | c41f3074-c82a-4837-8673-fa7e9fea7e11 | myInstance | SHUTOFF | private=10.0.0.3 | cirros     |
    +--------------------------------------+------------+---------+------------------+------------+
    
  4. Use the openstack server image create command to take a snapshot:

    $ openstack server image create myInstance --name myInstanceSnapshot
    

    The above command creates the image myInstance by taking a snapshot of a running server.

  5. 使用命令`openstack image list`来检查快照状态,直到状态是``active``:

    $ openstack image list
    +--------------------------------------+---------------------------------+--------+
    | ID                                   | Name                            | Status |
    +--------------------------------------+---------------------------------+--------+
    | 657ebb01-6fae-47dc-986a-e49c4dd8c433 | cirros-0.3.5-x86_64-uec         | active |
    | 72074c6d-bf52-4a56-a61c-02a17bf3819b | cirros-0.3.5-x86_64-uec-kernel  | active |
    | 3c5e5f06-637b-413e-90f6-ca7ed015ec9e | cirros-0.3.5-x86_64-uec-ramdisk | active |
    | f30b204e-1ce6-40e7-b8d9-b353d4d84e7d | myInstanceSnapshot              | active |
    +--------------------------------------+---------------------------------+--------+
    

下载快照作为镜像

  1. 获得镜像标识:

    $ openstack image list
    +-------------------+-------------------+--------+
    | ID                | Name              | Status |
    +-------------------+-------------------+--------+
    | f30b204e-1ce6...  | myInstanceSnapshot| active |
    +-------------------+-------------------+--------+
    
  2. 通过使用在上一步中返回的镜像标识下载快照:

    $ openstack image save --file snapshot.raw f30b204e-1ce6-40e7-b8d9-b353d4d84e7d
    

    注解

    The openstack image save command requires the image ID or the image name. Check there is sufficient space on the destination file system for the image file.

  3. 通过HTTP或直接上传至机器(scp)的方式使得镜像在新环境中可用。

将快照导入到新环境中

在新项目或云环境导入快照

$ openstack image create NEW_IMAGE_NAME \
  --container-format bare --disk-format qcow2 --file IMAGE_URL

从快照中重启云主机

在新的项目或环境中,使用快照创建新的云主机:

$ openstack server create --flavor m1.tiny --image myInstanceSnapshot myNewInstance
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.