1、VMware的快照

wKioL1YhEijRaYAyAAMnipJhKeg282.jpg

wKiom1YhEhjx9xHuAADYCitq8HU119.jpg

还原快照:

wKioL1YhElLSDnVLAANlDiioxLw681.jpg

快照管理
a. 创建快照

1、[root@localhost caimz]# virsh snapshot-create caimz1
Domain snapshot 1444908044 created
若是:

virsh snapshot-create centos6.6
会报错:
unsupported configuration: internal snapshot for disk vda unsupported for storage type raw
这是因为raw格式的镜像不能做快照,所以需要先转换一下格式 

格式转换

 qemu-img convert -f raw -O qcow2  /caimz/caimz2.img  /caimz/caimz.qcow2


查看系统的格式

[root@localhost caimz]# qemu-img info /caimz/caimz1.qcow2
p_w_picpath: /caimz/caimz1.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 10G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK            
 #这个是刚才做的快照
1         1444908044             435M 2015-10-15 19:20:44   00:16:59.500
[root@localhost caimz]# qemu-img info /caimz/caimz
caimz1.qcow2  caimz2.img   
[root@localhost caimz]# qemu-img info /caimz/caimz2.img
p_w_picpath: /caimz/caimz2.img
file format: raw
virtual size: 30G (32212254720 bytes)
disk size: 30G


列举快照信息

[root@localhost caimz]# virsh snapshot-list caimz1
Name                 Creation Time             State
------------------------------------------------------------
1444908044           2015-10-15 19:20:44 +0800 running
2、编辑配置文件

[root@localhost caimz]# virsh edit caimz1

wKiom1YhEknBdPhoAABvY-3CmAc780.jpg


b. 磁盘镜像转换格式
先查看当前子机磁盘镜像格式
qemu-img info /data/centos6.6_1.img  
结果是:
p_w_picpath: /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   //再次查看格式,结果如下
p_w_picpath: /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