下面开始进行kvm虚拟机快照备份前的操作以及快照管理过程。
1,查看KVM虚拟机磁盘格式以及进行磁盘格式转换
1.1 查看KVM虚拟机磁盘格式
使用如下方法查看 qemu-img info linux66.img
[root@94ip vps]# qemu-img info linuxt66.img
image: linuxt66.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 8.0G1
由于快照要使用,磁盘格式必须为qcow2,需要进行磁盘格式转换。
1.2 关闭虚拟机并转换磁盘
[root@94ip vps]# virsh destroy linux66
Domain linux66 destroyed
[root@94ip vps]# virsh list --all
Id Name State
----------------------------------------------------
2 win2003 running
6 linux65 running
- linux66 shut off
[root@94ip vps]# ll
total 11468860
-rwxr-xr-x 1 qemu qemu 8589934592 May 11 19:22 linuxt65.img
-rwxr-xr-x 1 root root 8589934592 May 11 19:21 linuxt66.img
-rwxr-xr-x 1 qemu qemu 10737418240 May 11 19:23 win2003.img
[root@94ip vps]# qemu-img convert -f raw -O qcow2 linuxt66.img linuxt66.qcow2
[root@94ip vps]#
[root@94ip vps]# ll
total 12711880
-rwxr-xr-x 1 qemu qemu 8589934592 May 11 19:25 linuxt65.img
-rwxr-xr-x 1 root root 8589934592 May 11 19:21 linuxt66.img
-rw-r--r-- 1 root root 1272971264 May 11 19:24 linuxt66.qcow2
-rwxr-xr-x 1 qemu qemu 10737418240 May 11 19:25 win2003.img
转换完成。注意,这里的转换时针对源文件拷贝一份,并将格式转成qcow2。
1.3 修改配置文件,启用新格式磁盘。
virsh edit linux 进去搜索img找到以后替换文件格式名:
2,管理快照以及快照恢复
首先我们先查看下该快照命令用到了哪些:
[root@94ip ~]# virsh --help | grep snap
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
2.1 创建快照
根据上述命令,我们打算使用snapshot-cteate 来对linux66主机创建快照
[root@94ip vps]# virsh snapshot-create linux66
Domain snapshot 1463020507 created
查看快照列表
[root@94ip vps]# virsh snapshot-list linux66
Name Creation Time State
------------------------------------------------------------
1463020507 2016-05-11 19:35:07 -0700 shutoff
1463020969 2016-05-11 19:42:49 -0700 shutoff
其中快照配置文件放到了/var/lib/libvirt/qemu/snapshot/
查看 最近的快照
virsh snapshot-currentlinux66
2.2 恢复快照
恢复快照之前必须先关闭虚拟机,我们可以先关闭以后并查看下快照列表,选中要恢复哪个快照。
[root@94ip snapshot]# virsh list --all
Id Name State
----------------------------------------------------
2 win2003 running
6 linux65 running
- linux66 shut off
[root@94ip snapshot]# virsh snapshot-list linux66
Name Creation Time State
------------------------------------------------------------
1463020507 2016-05-11 19:35:07 -0700 shutoff
1463020969 2016-05-11 19:42:49 -0700 shutoff
比如我们这里恢复 1463020969这个快照。操作如下:
[root@94ip snapshot]# virsh snapshot-revert linux66 1463020969
[root@94ip snapshot]# virsh snapshot-current linux66
1463020969
shutoff
1463020507
恢复完成。
2.3快照删除
[root@94ip vps]# virsh snapshot-list linux66
Name Creation Time State
------------------------------------------------------------
1463020507 2016-05-11 19:35:07 -0700 shutoff
1463020969 2016-05-11 19:42:49 -0700 shutoff
[root@94ip vps]# virsh snapshot-delete linux66 1463020969
Domain snapshot 1463020969 deleted
[root@94ip vps]# virsh snapshot-list linux66
Name Creation Time State
------------------------------------------------------------
1463020507 2016-05-11 19:35:07 -0700 shutoff