快照管理
a. 创建快照
virsh snapshot-create centos6.6_1
会报错:
unsupported configuration: internal snapshot for disk vda unsupported for storage type raw
这是因为raw格式的镜像不能做快照,所以需要先转换一下格式
b. 磁盘镜像转换格式
先查看当前子机磁盘镜像格式
qemu-img info /data/centos6.6_1.img
结果是:
image: /data/centos6.6_1.img
file format: raw
virtual size: 30G (32212254720 bytes)
disk size: 1.6G
把raw格式转换为qcow格式(其实是复制了一份):
qemu-img convert -f raw -O qcow2 /data/centos6.6_1.img /data/centos6.6_1.qcow2
qemu-img info /data/centos6.6_1.qcow2 //再次查看格式,结果如下
image: /data/centos6.6_1.qcow2
file format: qcow2
virtual size: 30G (32212254720 bytes)
disk size: 1.1G
cluster_size: 65536
现在我们还需要编辑子机配置文件,让它使用新格式的虚拟磁盘镜像文件
virsh edit centos6.6_1 //这样就进入了该子机的配置文件(/etc/libvirt/qemu/centos6.6_1.xml),跟用vim编辑这个文件一样的用法
需要修改的地方是:
<driver name=‘qemu‘ type=‘raw‘ cache=‘none‘/>
<source file=‘/data/centos6.6_1.img‘/>
改为:
<driver name=‘qemu‘ type=‘qcow2‘ cache=‘none‘/>
<source file=‘/data/centos6.6_1.qcow2‘/>
c. 继续创建快照
virsh snapshot-create centos6.6_1 //这次成功了,提示如下
Domain snapshot 1437248443 created
列出快照:
virsh snapshot-list centos6.6_1
查看当前子机的快照版本:
virsh snapshot-current centos6.6_1
centos6.6_1子机的快照文件在 /var/lib/libvirt/qemu/snapshot/centos6.6_1/ 目录下
d. 恢复快照
首先需要关闭子机
virsh destroy centos6.6_1
确认子机是否关闭
virsh domstate centos6.6_1
关闭
vish snapshot-list centos6.6_1 //结果是
名称 Creation Time 状态
------------------------------------------------------------
1437248443 2015-07-19 03:40:43 +0800 shutoff
1437248847 2015-07-19 03:47:27 +0800 running
virsh snapshot-revert centos6.6_1 1437248443
e. 删除快照
virsh snapshot-delete centos6.6_1 1437248847
原文地址:http://xiongrunchu.blog.51cto.com/11696174/1788183