KVM默认的文件格式是raw,也就是使用文件来模拟实际的硬盘(当然也可以使用一块真实的硬盘或一个分区),不过raw格式只支持内存快照(就是启动的 时候加-snapshot,所有更改都写到内存),重启之后就没了。
raw格式不支持磁盘快照,因此要使用qcow或qcow2文件格式。
1、kvm创建快照
创建快照有两个命令都能实现
a、snapshot-create
# virsh snapshot-create rhel6.3
Domain snapshot 1420722577 created
# virsh snapshot-list rhel6.3
Name Creation Time State
------------------------------------------------------------
1420722577 2015-01-08 21:09:37 +0800 running
b、 snapshot-create-as
# virsh snapshot-create-as rhel6.3 before-install-vnc
Domain snapshot before-install-vnc created
# virsh snapshot-list rhel6.3
Name Creation Time State
------------------------------------------------------------
before-install-vnc 2015-01-08 21:16:05 +0800 running
Name Creation Time State
------------------------------------------------------------
before-install-vnc 2015-01-08 21:16:05 +0800 running
可以看出使用snapshot-create-as可以自定义快照名
2、kvm删除快照
# virsh snapshot-delete rhel6.3 1420722577
Domain snapshot 1420722577 deleted
Domain snapshot 1420722577 deleted
3、kvm恢复快照
# virsh snapshot-revert rhel6.3 before-install-vnc
error: revert requires force: Target controller type ide does not match source usb
error: revert requires force: Target controller type ide does not match source usb
注意:
恢复虚拟机状态之前,我们必须要把虚拟机关闭
# virsh shutdown rhel6.3
Domain rhel6.3 is being shutdown
# virsh snapshot-revert rhel6.3 before-install-vnc(//快照名)
# virsh list --all
Domain rhel6.3 is being shutdown
# virsh snapshot-revert rhel6.3 before-install-vnc(//快照名)
# virsh list --all
Id Name State
----------------------------------------------------
3 xp running
7 rhel6.3 running //快照恢复完成后自动打开了电源
4、kvm快照相关命令
# virsh --help | grep snapshot
iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
Snapshot (help keyword 'snapshot')
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-info snapshot information
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
Snapshot (help keyword 'snapshot')
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-info snapshot information
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot