本次环境为openstack K版本。ceph 版本为0.94.5
我们的虚拟机都是建立在ceph中的。
备份虚拟机:
打开openstack控制台,点击要备份的虚拟机:
获取虚拟机的id信息:
在控制节点获取,虚拟机对应的ceph中的volume id
[root@contorller ceph]# nova show 1d77b49b-4263-477e-acc8-4242a3a998b3
[root@contorller ceph]# rbd ls volumes | grep 2ccd04fd-3a28-4d40-b226-cab0af159257
volume-2ccd04fd-3a28-4d40-b226-cab0af159257
导出虚拟机到一个位置
[root@contorller ~]# rbd export -p volumes volume-2ccd04fd-3a28-4d40-b226-cab0af159257 /tmp/vm1.bk
Exporting image: 100% complete...done.
[root@contorller ~]# ll /tmp/vm1.bk -h
-rw-r--r--. 1 root root 1.0G Jun 26 10:39 /tmp/vm1
可以看到虚拟机已经导出了,并且大小也是1G
============导入========
下面我们来做下导入,我们首先把刚刚备份的虚拟机删除
[root@contorller ~]# nova list
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| 1d77b49b-4263-477e-acc8-4242a3a998b3 | 11 | ACTIVE | - | Running | net=10.0.0.7 |
| 17e0220e-e9b5-4b6a-8001-6ce84c7b1385 | vm1 | ACTIVE | - | Running | net=10.0.0.3, 192.168.253.43 |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
[root@contorller ~]# nova delete 1d77b49b-4263-477e-acc8-4242a3a998b3
Request to delete server 1d77b49b-4263-477e-acc8-4242a3a998b3 has been accepted.
[root@contorller ~]# nova list
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| 17e0220e-e9b5-4b6a-8001-6ce84c7b1385 | vm1 | ACTIVE | - | Running | net=10.0.0.3, 192.168.253.43 |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
ok,已经把虚拟机删除了。此我们需要创建一个同等规格的虚拟机。名为‘Erick’
使用同样的方法,获取虚拟机的id、在ceph中的volume对应的id
[root@contorller ~]# nova show 362151d7-84f7-4043-a723-a852e48922a7
+--------------------------------------+----------------------------------------------------------+
| Property | Value |
+--------------------------------------+----------------------------------------------------------+
| OS-DCF:diskConfig | AUTO |
| OS-EXT-AZ:availability_zone | nova |
| OS-EXT-SRV-ATTR:host | compute |
| OS-EXT-SRV-ATTR:hypervisor_hostname | compute |
| OS-EXT-SRV-ATTR:instance_name | instance-0000000c |
| OS-EXT-STS:power_state | 1 |
| OS-EXT-STS:task_state | - |
| OS-EXT-STS:vm_state | active |
| OS-SRV-USG:launched_at | 2016-06-26T14:45:35.000000 |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2016-06-26T14:45:04Z |
| flavor | m1.tiny (1) |
| hostId | e111131d0ba1d28eaf1195847c1538b8e7b791cbdd6f7666083ab383 |
| id | 362151d7-84f7-4043-a723-a852e48922a7 |
| image | Attempt to boot from volume - no image supplied |
| key_name | - |
| metadata | {} |
| name | Erick |
| net network | 10.0.0.9 |
| os-extended-volumes:volumes_attached | [{"id": "cc9c8141-c70c-4a72-91d5-5fa9e15e21d8"}] |
| progress | 0 |
| security_groups | default |
| status | ACTIVE |
| tenant_id | dce7915317f14e6aacad0b6ef84c4483 |
| updated | 2016-06-26T14:45:29Z |
| user_id | 9d20f58520ad43658dceda03cf4e266c |
+--------------------------------------+----------------------------------------------------------+
[root@contorller ~]# rbd ls volumes | grep cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
下面对虚拟机进行关机(必须关机),并删除pool中的内容
[root@contorller ~]# rbd rm -p volumes volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
Removing image: 100% complete...done.
把刚刚备份的虚拟机上传到这个虚拟机中
[root@contorller ~]# rbd --image-format 2 import -p volumes /tmp/vm1.bk volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
Importing image: 100% complete...
##--image-format 2 此选项必须加,否则无法对虚拟机进行克隆!
还原完成!
登入虚拟机查看有无异常
虚拟机可以上网!在此还原完成!
Openstack 技术交流群:580078423
希望大家入群多多交流