kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等。
要使用镜像功能,磁盘格式必须为qcow2。下面开始kvm虚拟机快照备份的过程。
1. 查看现有磁盘镜像格式与转换
(1) 查看磁盘格式
# qemu-img info CentOS6.5-01.img
raw格式需要转换成qcow2
(2) 关闭虚拟机并转换磁盘
# virsh shutdown CentOS6.5-01
(3) 转换磁盘格式
# qemu-img convert -f raw -O qcow2 CentOS6.5-01.img CentOS6.5-01.qcow2
-f 源镜像的格式
-O 目标镜像的格式
查看转换后的格式,已经转换成了qcow2, 这里是拷贝一份,并将格式转成qcow2
# qemu-img info CentOS6.5-01.qcow2
2. 修改虚拟机配置文件
修改磁盘格式,与新qcow2格式的磁盘。
3. 对虚拟机进行快照管理
(1) 对CentOS6.5-01虚拟机创建快照
# virsh snapshot-create CentOS6.5-01
也可以virsh snapshot-create as CentOS6.5-01 snap1 创建后个快照别名。
(2) 查看虚拟机镜像快照的版本
# virsh snapshot-list CentOS6.5-01
(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) 查看当前虚拟机镜像文件
又创建了一个,快照的版本也记录在镜像文件中了。
快照配置文件在/var/lib/libvirt/qemu/snapshot/虚拟机名称/下
4. 恢复虚拟机快照
(1) 恢复虚拟机快照必须关闭虚拟机。
确认虚拟机是关机状态
(2) 确认需要恢复的快照时间,这里恢复到1511337772
(3) 执行恢复,并确认恢复版本
# virsh snapshot-revert CentOS6.5-01 1511337772
# virsh snapshot-current CentOS6.5-01
5. 删除虚拟机快照
(1) 查看虚拟机快照
# qemu-img info CentOS6.5-01.qcow2
这里删除第一个快照1511337772
(2) 删除快照
到此kvm虚拟机快照测试完毕。kvm虚拟化学习笔记进行到这里了,感觉到kvm虚拟化的内容真的很多。水是越来越深了。
本文转自 dengaosky 51CTO博客,原文链接:http://blog.51cto.com/dengaosky/1984114,如需转载请自行联系原作者