下面开始进行kvm虚拟机快照备份前的操作以及快照管理过程。
1,查看KVM虚拟机磁盘格式以及进行磁盘格式转换
1.1 查看KVM虚拟机磁盘格式
使用如下方法查看 qemu-img info linux66.img
[root@94ipvps]#qemu-imginfolinuxt66.img
image:linuxt66.img
fileformat:raw
virtualsize:8.0G(8589934592bytes)
disksize:8.0G1
由于快照要使用,磁盘格式必须为qcow2,需要进行磁盘格式转换。
1.2 关闭虚拟机并转换磁盘
[root@94ipvps]#virshdestroylinux66
Domainlinux66destroyed
[root@94ipvps]#virshlist--all
IdNameState
----------------------------------------------------
2winrunning
6linux65running
-linux66shutoff
[root@94ipvps]#ll
total11468860
-rwxr-xr-x1qemuqemu8589934592May1119:22linuxt65.img
-rwxr-xr-x1rootroot8589934592May1119:21linuxt66.img
-rwxr-xr-x1qemuqemu10737418240May1119:23win.img
[root@94ipvps]#qemu-imgconvert-fraw-Oqcow2linuxt66.imglinuxt66.qcow2
[root@94ipvps]#
[root@94ipvps]#ll
total12711880
-rwxr-xr-x1qemuqemu8589934592May1119:25linuxt65.img
-rwxr-xr-x1rootroot8589934592May1119:21linuxt66.img
-rw-r--r--1rootroot1272971264May1119:24linuxt66.qcow2
-rwxr-xr-x1qemuqemu10737418240May1119:25win.img
转换完成。注意,这里的转换时针对源文件拷贝一份,并将格式转成qcow2。
1.3 修改配置文件,启用新格式磁盘。
virsh edit linux 进去搜索img找到以后替换文件格式名:
2,管理快照以及快照恢复
首先我们先查看下该快照命令用到了哪些:
[root@94ip~]#virsh--help|grepsnap
iface-begincreateasnapshotofcurrentinterfacessettings,whichcanbelatercommitted(iface-commit)orrestored(iface-rollback)
Snapshot(helpkeyword'snapshot')
snapshot-createCreateasnapshotfromXML
snapshot-create-asCreateasnapshotfromasetofargs
snapshot-currentGetorsetthecurrentsnapshot
snapshot-deleteDeleteadomainsnapshot
snapshot-dumpxmlDumpXMLforadomainsnapshot
snapshot-editeditXMLforasnapshot
snapshot-infosnapshotinformation
snapshot-listListsnapshotsforadomain
snapshot-parentGetthenameoftheparentofasnapshot
snapshot-revertRevertadomaintoasnapshot
2.1 创建快照
根据上述命令,我们打算使用snapshot-cteate 来对linux66主机创建快照
[root@94ipvps]#virshsnapshot-createlinux66
Domainsnapshot1463020507created
查看快照列表
[root@94ipvps]#virshsnapshot-listlinux66
NameCreationTimeState
------------------------------------------------------------
1463020507-05-1119:35:07-0700shutoff
1463020969-05-1119:42:49-0700shutoff
其中快照配置文件放到了/var/lib/libvirt/qemu/snapshot/
查看 最近的快照
virsh snapshot-currentlinux66
2.2 恢复快照
恢复快照之前必须先关闭虚拟机,我们可以先关闭以后并查看下快照列表,选中要恢复哪个快照。
[root@94ipsnapshot]#virshlist--all
IdNameState
----------------------------------------------------
2winrunning
6linux65running
-linux66shutoff
[root@94ipsnapshot]#virshsnapshot-listlinux66
NameCreationTimeState
------------------------------------------------------------
1463020507-05-1119:35:07-0700shutoff
1463020969-05-1119:42:49-0700shutoff
比如我们这里恢复 1463020969这个快照。操作如下:
[root@94ipsnapshot]#virshsnapshot-revertlinux661463020969
[root@94ipsnapshot]#virshsnapshot-currentlinux66
1463020969
shutoff
1463020507
恢复完成。
2.3快照删除
[root@94ipvps]#virshsnapshot-listlinux66
NameCreationTimeState
------------------------------------------------------------
1463020507-05-1119:35:07-0700shutoff
1463020969-05-1119:42:49-0700shutoff
[root@94ipvps]#virshsnapshot-deletelinux661463020969
Domainsnapshot1463020969deleted
[root@94ipvps]#virshsnapshot-listlinux66
NameCreationTimeState
------------------------------------------------------------
1463020507-05-1119:35:07-0700shutoff