声明:
本博客欢迎转发,但请保留原作者信息!
博客地址:http://blog.csdn.net/halcyonbaby
内容系本人学习、研究和总结,如有雷同,实属荣幸!
磁盘快照
对磁盘数据进行快照。主要用于虚拟机备份等场合。
内存快照
对虚拟机的内存/设备信息进行保存。该机制同时用于休眠恢复,迁移等场景。
主要使用virsh save(qemu migrate to file)实现。
只能对运行态的虚拟机进行。
检查点快照
同时保存虚拟机的磁盘快照和内存快照。用于将虚拟机恢复到某个时间点。可以保证数据的一致性。
qemu-img snapshot -c snapshot01 test.qcow2 //创建
qemu-img snapshot -l test.qcow2 //查看
qemu-img snapshot -a snapshot01 test.qcow2 //revert到快照点
qemu-img snapshot -d snapshot01 test.qcow2 //删除
snapshot.xml
<domainsnapshot>
<name>snapshot01</name>
<description>Snapshot of OS install and updates by boh</description>
<disks>
<disk name='/data/os-multi/controller.qcow2'>
</disk>
</disks>
</domainsnapshot>
virsh snapshot-create controller snapshot.xml //创建快照。快照元信息在/var/lib/libvirt/qemu/snapshot/(destroy后丢失)
virsh snapshot-list controller --tree //树形查看快照。
virsh snapshot-current controller //查看当前快照
virsh snapshot-revert controller snapshot02 //恢复快照
virsh snapshot-delete controller snapshot02 //删除快照
功能参数:
--quiesce quiesce guest's file systems
--atomic require atomic operation
virsh snapshot-create-as --domain f17-base snap1 snap1-desc \
--disk-only --diskspec vda,snapshot=external,file=/export/vmimages/sn1-of-f17-base.qcow2 \
--atomic
# virsh domblklist f17-base
Target Source
----------------------------------------------------
vda /export/vmimages/sn1-of-f17-base.qcow2
virsh blockcommit --domain f17 vda --base /export/vmimages/sn2.qcow2 --top /export/vmimages/sn3.qcow2 --wait --verbose
#只支持pull到最前端
virsh blockpull --domain RootBase --path /var/lib/libvirt/images/active.qcow2 \
--base /var/lib/libvirt/images/RootBase.qcow2 --wait --verbose
virsh snapshot-delete --domain RootBase Snap-3 --metadata #删除无用的快照
利用LVM创建。利用文件系统能力创建。利用存储本身的功能创建。
#libvirt的虚拟机快照实现过程:
optionally - use the guest-agent to tell the guest OS to quiesce I/O
tell qemu to migrate guest memory to file; qemu pauses guest
for each disk:
tell qemu to pause disk image modifications for that disk
libvirt resumes qemu (but I/O is still frozen)
for each disk:
libvirt creates the snapshot
if the snapshot involves updating the backing image used by qemu:
pass qemu the new fd for the disk image
tell qemu to resume disk I/O on that disk
#虚拟机快照恢复实现过程:
for each disk:
revert back to disk snapshot point
tell qemu to do incoming migration from file