黑猴子的家:KVM 快照

kvm快照

1、查看磁盘格式

[root@node1 opt]# qemu-img info CentOS-7-x86_64.raw 
image: CentOS-7-x86_64.raw
file format: raw
virtual size: 10G (10737418240 bytes)
disk size: 4.8G

2、关闭虚拟机

[root@node1 ~]# virsh shutdown CentOS-7-x86_64

3、转换磁盘

[root@node1 opt]# qemu-img convert -p -f raw -O qcow2 CentOS-7-x86_64.raw kvm133.qcow2
尖叫提示:-O必须大写 –p显示转换进度

4、查看磁盘信息

[root@node1 opt]# qemu-img info kvm133.qcow2 
image: kvm133.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 4.8G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false

5、修改虚拟机配置文件

[root@node1 opt]# virsh edit CentOS-7-x86_64
image.png

6、创建快照

[root@node1 ~]# virsh snapshot-create CentOS-7-x86_64
Domain snapshot 1527036985 created

直接在磁盘上做快照

[root@node1 opt]# qemu-img snapshot kvm133.qcow2 -c snap1

7、查看虚拟机快照版本

[root@node1 ~]# virsh snapshot-list CentOS-7-x86_64
 Name                 Creation Time             State
------------------------------------------------------------
 1526980621           2018-05-22 17:17:01 +0800 shutoff
 1527036985           2018-05-23 08:56:25 +0800 shutoff

qemu-img方式查看磁盘的快照版本

[root@node1 opt]# qemu-img snapshot kvm33.qcow2 -l

8、查看虚拟机最新快照

[root@node1 ~]# virsh snapshot-current CentOS-7-x86_64

9、查看虚拟机磁盘镜像

[root@node1 ~]# qemu-img info /opt/kvm133.qcow2 
image: /opt/kvm133.qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 4.9G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         1526980621                0 2018-05-22 17:17:02   00:00:00.000
2         1527036985                0 2018-05-23 08:56:25   00:00:00.000
Format specific information:
    compat: 1.1
    lazy refcounts: false

10、查看快照配置文件

[root@node1 ~]# cd /var/lib/libvirt/qemu/snapshot/CentOS-7-x86_64
[root@node1 CentOS-7-x86_64]# ll
-rw------- 1 root root 4483 May 23 08:56 1526980621.xml
-rw------- 1 root root 4532 May 23 08:56 1527036985.xml

11、恢复快照

(1)恢复虚拟机快照必须关闭虚拟机

[root@node1 ~]# virsh shutdown CentOS-7-x86_64
[root@ node1 ~]# virsh list --all
 Id    Name                           State
-------------------------------------------------------------------------------
 -     CentOS-7-x86_64                 shut off

(2)确认虚拟机是否关闭

[root@node1 ~]# virsh domstate CentOS-7-x86_64
shut off

(3)查看虚拟机可以恢复的快照

[root@node1 ~]# virsh snapshot-list CentOS-7-x86_64
 Name                 Creation Time             State
--------------------------------------------------------------------------------------------
 1526980621           2018-05-22 17:17:01 +0800 shutoff
 1527036985           2018-05-23 08:56:25 +0800 shutoff

qemu-img方式查看磁盘的快照版本
[root@node1 opt]# qemu-img snapshot kvm33.qcow2 -l

(4)执行恢复快照,并确认一下版本

[root@node1 ~]# virsh snapshot-revert CentOS-7-x86_64 1526980621
[root@node1 ~]# virsh snapshot-current CentOS-7-x86_64
![](https://upload-images.jianshu.io/upload_images/9193428-808e5e5d0b399f76.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

使用qemu-img还原快照
[root@node1 opt]# qemu-img snapshot test.qcow2 -a 1526980621

(5)提取快照镜像作为单独的一个文件

[root@hadoop102 opt]# qemu-img convert -f qcow2 -O qcow2 -s 1526980621 kvm133.qcow2 kvm133-1526980621.qcow2
尖叫提示:参数-s用于指定需要提取的磁盘快照

12、删除虚拟机快照

(1)查看虚拟机快照

[root@node1 ~]# virsh snapshot-list CentOS-7-x86_64
 Name                 Creation Time             State
-------------------------------------------------------------------------------------------
 1526980621           2018-05-22 17:17:01 +0800 shutoff
 1527036985           2018-05-23 08:56:25 +0800 shutoff

qemu-img方式查看磁盘的快照版本
[root@node1 opt]# qemu-img snapshot kvm33.qcow2 -l

(2)删除快照

[root@node1 ~]# virsh snapshot-delete CentOS-7-x86_64 1527036985
Domain snapshot 1527036985 deleted

使用qemu-img方式删除快照
[root@node1 opt]# qemu-img snapshot kvm133.qcow2 -d snap1

(3)再次查看虚拟机快照

[root@node1 ~]# virsh snapshot-list CentOS-7-x86_64
 Name                 Creation Time             State
-------------------------------------------------------------------------------------------
 1526980621           2018-05-22 17:17:01 +0800 shutoff

qemu-img方式查看磁盘的快照版本
[root@node1 opt]# qemu-img snapshot kvm33.qcow2 -l

你可能感兴趣的:(黑猴子的家:KVM 快照)