首页 > 代码库 > kvm快照

kvm快照

Kvm快照:

1、基于lvm的快照

2、kvm自带的快照功能(需要qcow2 磁盘文件才支持快照)

 

关闭kvm虚拟机:

 

查看磁盘文件信息:

[root@super67 ~]# qemu-img info /var/lib/libvirt/images/ubuntu16-1.img

image: /var/lib/libvirt/images/ubuntu16-1.img

file format: raw

virtual size: 0 (0 bytes)

disk size: 0

 

磁盘格式转换:

[root@super67 ~]# qemu-img convert -f raw -O qcow2 /var/lib/libvirt/images/ubuntu16-1.img /var/lib/libvirt/images/ubuntu16-1.qcow2

 

查看:

[root@super67 ~]# ll /var/lib/libvirt/images

-rw-r--r-- 1 qemu qemu 1485881344 Sep  4 12:47 ubuntu-16.04-desktop-amd64.iso

-rwxr-xr-x 1 root root        107 Sep  4 13:58 ubuntu16-1.img

-rw-r--r-- 1 root root     196608 Sep  4 14:11 ubuntu16-1.qcow2

-rw------- 1 root root 8589934592 Sep  4 10:50 www.linux1.cn.img

 

[root@super67 ~]#  qemu-img info /var/lib/libvirt/images/ubuntu16-1.qcow2

image: /var/lib/libvirt/images/ubuntu16-1.qcow2

file format: qcow2

virtual size: 0 (0 bytes)

disk size: 132K

cluster_size: 65536

 

 

编辑ubuntu16-1配置文件:

[root@super67 ~]# virsh edit ubuntu16-1

技术分享

现在ubuntu16-1虚拟机已经是支持快照的虚拟机了。

接下来进行快照:

[root@super67 ~]# cd /var/lib/libvirt/images

 

创建快照(名字为ubuntu16-1-copy)

[root@super67 images]# virsh snapshot-create ubuntu16-1

Domain snapshot 1472969993 created

[root@super67 images]# virsh snapshot-create-as ubuntu16-1 ubuntu16-1-copy

Domain snapshot ubuntu16-1-copy created

 

查看快照版本:

[root@super67 images]# virsh snapshot-list ubuntu16-1

 Name                 Creation Time             State

------------------------------------------------------------

 1472969993           2016-09-04 14:19:53 +0800 shutoff

 ubuntu16-1-copy      2016-09-04 14:20:53 +0800 shutoff

 

查看当前快照版本:

[root@super67 images]# virsh snapshot-current ubuntu16-1 |grep "<name>"

  <name>ubuntu16-1-copy</name>

    <name>1472969993</name>

    <name>ubuntu16-1</name>

 

再次创建快照:

[root@super67 images]# virsh snapshot-create-as ubuntu16-1 ubuntu16-1-copy1

Domain snapshot ubuntu16-1-copy1 created

 

查看当前版本:

[root@super67 images]# virsh snapshot-current ubuntu16-1 |grep "<name>"

  <name>ubuntu16-1-copy1</name>

    <name>ubuntu16-1-copy</name>

    <name>ubuntu16-1</name>

 

恢复快照(kvm虚拟机要先关机)

[root@super67 images]# virsh snapshot-revert ubuntu16-1 ubuntu16-1-copy

 

查看版本:

[root@super67 images]# virsh snapshot-current ubuntu16-1 |grep "<name>"

  <name>ubuntu16-1-copy</name>

    <name>1472969993</name>

    <name>ubuntu16-1</name>

 

查看快照:

[root@super67 ~]# qemu-img info /var/lib/libvirt/images/ubuntu16-1.qcow2

image: /var/lib/libvirt/images/ubuntu16-1.qcow2

file format: qcow2

virtual size: 0 (0 bytes)

disk size: 144K

cluster_size: 65536

Snapshot list:

ID        TAG                 VM SIZE                DATE       VM CLOCK

1         1472969993                0 2016-09-04 14:19:53   00:00:00.000

2         ubuntu16-1-copy           0 2016-09-04 14:20:53   00:00:00.000

3         ubuntu16-1-copy1          0 2016-09-04 14:25:28   00:00:00.000

 

 

删除快照:(用TAG号删)

[root@super67 ~]# virsh snapshot-delete ubuntu16-1 ubuntu16-1-copy1

Domain snapshot ubuntu16-1-copy1 deleted

 

查看快照:

[root@super67 ~]# qemu-img info /var/lib/libvirt/images/ubuntu16-1.qcow2

image: /var/lib/libvirt/images/ubuntu16-1.qcow2

file format: qcow2

virtual size: 0 (0 bytes)

disk size: 144K

cluster_size: 65536

Snapshot list:

ID        TAG                 VM SIZE                DATE       VM CLOCK

1         1472969993                0 2016-09-04 14:19:53   00:00:00.000

2         ubuntu16-1-copy           0 2016-09-04 14:20:53   00:00:00.000

 

kvm快照