openstack 利用ceph儲存之---備份還原虛擬機器
本次環境為openstack K版本。ceph 版本為
我們的虛擬機器都是建立在ceph中的。
備份虛擬機器:
開啟openstack控制檯,點選要備份的虛擬機器:
獲取虛擬機器的id資訊:
在控制節點獲取,虛擬機器對應的ceph中的volume id
[[email protected] ceph]# nova show 1d77b49b-4263-477e-acc8-4242a3a998b3
[[email protected] ceph]# rbd ls volumes | grep 2ccd04fd-3a28-4d40-b226-cab0af159257
volume-2ccd04fd-3a28-4d40-b226-cab0af159257
匯出虛擬機器到一個位置
[[email protected] ~]# rbd export -p volumes volume-2ccd04fd-3a28-4d40-b226-cab0af159257 /tmp/
Exporting image: 100% .
[[email protected] ~]# ll /tmp/ -h
-rw-r--r--. 1 root root Jun 26 10:39 /tmp/vm1
可以看到虛擬機器已經匯出了,並且大小也是1G
============匯入========
下面我們來做下匯入,我們首先把剛剛備份的虛擬機器刪除
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| 1d77b49b-4263-477e-acc8-4242a3a998b3 | 11 | ACTIVE | - | Running | net= |
| 17e0220e-e9b5-4b6a-8001-6ce84c7b1385 | vm1 | ACTIVE | - | Running | net=, |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
[[email protected] ~]# nova delete 1d77b49b-4263-477e-acc8-4242a3a998b3
Request to delete server 1d77b49b-4263-477e-acc8-4242a3a998b3 has been accepted.
[[email protected] ~]# nova list
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| ID | Name | Status | Task State | Power State | Networks |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
| 17e0220e-e9b5-4b6a-8001-6ce84c7b1385 | vm1 | ACTIVE | - | Running | net=, |
+--------------------------------------+------+--------+------------+-------------+------------------------------+
ok,已經把虛擬機器刪除了。此我們需要建立一個同等規格的虛擬機器。名為‘Erick’
使用同樣的方法,獲取虛擬機器的id、在ceph中的volume對應的id
[[email protected] ~]# 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: |
| OS-SRV-USG:terminated_at | - |
| accessIPv4 | |
| accessIPv6 | |
| config_drive | |
| created | 2016-06-26T14:45:04Z |
| flavor | (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 | |
| 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 |
+--------------------------------------+----------------------------------------------------------+
[[email protected] ~]# rbd ls volumes | grep cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
下面對虛擬機器進行關機(必須關機),並刪除pool中的內容
[[email protected] ~]# rbd rm -p volumes volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
Removing image: 100% .
把剛剛備份的虛擬機器上傳到這個虛擬機器中
[[email protected] ~]# rbd import -p volumes /tmp/ volume-cc9c8141-c70c-4a72-91d5-5fa9e15e21d8
Importing image: 100% complete...
還原完成!
登入虛擬機器檢視有無異常
虛擬機器可以上網!在此還原完成!