kvm虚拟化学习笔记(十)之kvm虚拟机快照备份

kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等。   
要使用镜像功能,磁盘格式必须为qcow2。下面开始kvm虚拟机快照备份的过程。

1.  查看现有磁盘镜像格式与转换

(1) 查看磁盘格式

# qemu-img info CentOS6.5-01.img

raw格式需要转换成qcow2

a2a2c732c3afdb4ceab9f5ee84ede195.png-wh_

(2) 关闭虚拟机并转换磁盘

# virsh shutdown CentOS6.5-01

08e89169163ec79311a2d5b2fd8e2eea.png-wh_

(3) 转换磁盘格式

# qemu-img convert -f raw -O qcow2 CentOS6.5-01.img CentOS6.5-01.qcow2 

-f  源镜像的格式   
-O 目标镜像的格式

601d1574ea9049f115e0a61fb2cfd413.png-wh_

查看转换后的格式,已经转换成了qcow2, 这里是拷贝一份,并将格式转成qcow2

# qemu-img info CentOS6.5-01.qcow2

1f59521f64ac1708c69e2bf6d1d04e34.png-wh_

2. 修改虚拟机配置文件

修改磁盘格式,与新qcow2格式的磁盘。

dd11282dc85802cb8efb41d5f3d71122.png-wh_

3. 对虚拟机进行快照管理 

(1) 对CentOS6.5-01虚拟机创建快照

# virsh snapshot-create CentOS6.5-01 

也可以virsh snapshot-create as CentOS6.5-01 snap1 创建后个快照别名。

4ff3bd3f3b5b41c45faab15946013752.png-wh_


(2) 查看虚拟机镜像快照的版本

# virsh snapshot-list CentOS6.5-01

67ad803a5122fdb3b53f813f4c9e2f85.png-wh_



(3) 查看当前虚拟机镜像快照的版本

可以看到为当前最新的快照版本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
[root@node1 kvm] # virsh snapshot-current CentOS6.5-01
<domainsnapshot>
   <name>1511337772< /name >
   <state>shutoff< /state >
   <creationTime>1511337772< /creationTime >
   <memory snapshot= 'no' />
   <disks>
     <disk name= 'vda'  snapshot= 'internal' />
     <disk name= 'hdc'  snapshot= 'no' />
   < /disks >
   <domain  type = 'kvm' >
     <name>CentOS6.5-01< /name >
     <uuid>7d48f7b5-2fbf-91a9-2c3f-e52ba6079c8e< /uuid >
     <memory unit= 'KiB' >1048576< /memory >
     <currentMemory unit= 'KiB' >1048576< /currentMemory >
     <vcpu placement= 'static' >1< /vcpu >
     <os>
       < type  arch= 'x86_64'  machine= 'rhel6.6.0' >hvm< /type >
       <boot dev= 'hd' />
     < /os >
     <features>
       <acpi/>
       <apic/>
       <pae/>
     < /features >
     <clock offset= 'localtime' />
     <on_poweroff>destroy< /on_poweroff >
     <on_reboot>restart< /on_reboot >
     <on_crash>restart< /on_crash >
     <devices>
       <emulator> /usr/libexec/qemu-kvm < /emulator >
       <disk  type = 'file'  device= 'disk' >
         <driver name= 'qemu'  type = 'qcow2'  cache= 'none' />
         < source  file = '/data/kvm/CentOS6.5-01.qcow2' />
         <target dev= 'vda'  bus= 'virtio' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x05'  function = '0x0' />
       < /disk >
       <disk  type = 'block'  device= 'cdrom' >
         <driver name= 'qemu'  type = 'raw' />
         <target dev= 'hdc'  bus= 'ide' />
         < readonly />
         <address  type = 'drive'  controller= '0'  bus= '1'  target= '0'  unit= '0' />
       < /disk >
       <controller  type = 'usb'  index= '0'  model= 'ich9-ehci1' >
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x7' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci1' >
         <master startport= '0' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x0'  multifunction= 'on' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci2' >
         <master startport= '2' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x1' />
       < /controller >
       <controller  type = 'usb'  index= '0'  model= 'ich9-uhci3' >
         <master startport= '4' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x04'  function = '0x2' />
       < /controller >
       <controller  type = 'ide'  index= '0' >
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x01'  function = '0x1' />
       < /controller >
       <interface  type = 'bridge' >
         <mac address= '52:54:00:56:9a:7f' />
         < source  bridge= 'br0' />
         <model  type = 'virtio' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x03'  function = '0x0' />
       < /interface >
       <serial  type = 'pty' >
         <target port= '0' />
       < /serial >
       <console  type = 'pty' >
         <target  type = 'serial'  port= '0' />
       < /console >
       <input  type = 'mouse'  bus= 'ps2' />
       <graphics  type = 'vnc'  port= '5910'  autoport= 'no'  listen= '0.0.0.0' >
         <listen  type = 'address'  address= '0.0.0.0' />
       < /graphics >
       <video>
         <model  type = 'cirrus'  vram= '9216'  heads= '1' />
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x02'  function = '0x0' />
       < /video >
       <memballoon model= 'virtio' >
         <address  type = 'pci'  domain= '0x0000'  bus= '0x00'  slot= '0x06'  function = '0x0' />
       < /memballoon >
     < /devices >
   < /domain >
< /domainsnapshot >
 
[root@node1 kvm] #

(4) 查看当前虚拟机镜像文件

又创建了一个,快照的版本也记录在镜像文件中了。

f21888feb500745ed7b4a2c4fab58166.png-wh_


快照配置文件在/var/lib/libvirt/qemu/snapshot/虚拟机名称/下

8eebc489bc345e7a8de1daa1f2e5a07b.png-wh_


4. 恢复虚拟机快照

(1) 恢复虚拟机快照必须关闭虚拟机。

f41ff38a6a9b18b5c1a716ca96fe15ce.png-wh_

确认虚拟机是关机状态

d576f5fec37fedad0b2603a4d849d1e6.png-wh_


(2) 确认需要恢复的快照时间,这里恢复到1511337772

ac6044ce2502cc97f68d98df71b9b06e.png-wh_


(3) 执行恢复,并确认恢复版本

# virsh snapshot-revert CentOS6.5-01 1511337772

# virsh snapshot-current CentOS6.5-01

4d21adf8852584d9d8fbf1e5fe132450.png-wh_

5. 删除虚拟机快照

(1) 查看虚拟机快照

# qemu-img info CentOS6.5-01.qcow2

fa6cd424dc8ef0febde5618123433983.png-wh_

这里删除第一个快照1511337772

(2) 删除快照

e00c128ac3a4a457448b77efa88d7fe0.png-wh_

到此kvm虚拟机快照测试完毕。kvm虚拟化学习笔记进行到这里了,感觉到kvm虚拟化的内容真的很多。水是越来越深了。


本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/1984114,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值