KVM 虚拟机快照

KVM 虚拟机快照

一、查看kvm磁盘格式

kvm虚拟机默认使用raw格式的镜像格式,性能最好,速度最快,它的缺点就是不支持一些新的功能,如支持镜像,zlib磁盘压缩,AES加密等。要使用镜像功能,磁盘格式必须为qcow2。

查看虚拟机列表

virsh list

查看虚拟机磁盘格式

[root@zerotrust169 vms]# qemu-img info 172.16.100.94
image: 172.16.100.94
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.3G
cluster_size: 65536
Format specific information:
	compat: 1.1
	lazy refcounts: true

如果是file format: qcow2直接执行第三步创建快照

二、转化磁盘格式

file format: qcow2直接跳过此步骤,执行第三步创建快照

关闭虚拟机

[root@zerotrust169 vms]# virsh shutdown 172.16.100.94
Domain 172.16.100.94 is being shutdown

转化磁盘格式

 qemu-img convert -f raw -o qcow2 172.16.100.94 172.16.100.94.qcow2

修改虚拟机配置文件

<disk type='file' device='disk'>
	  <driver name='qemu' type='qcow2'/>
	  <source file='/home/vms/172.16.100.94.qcow2'/>
	  <target dev='vda' bus='virtio'/>
	  <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</disk>

注意:如果更改磁盘后,对应的虚拟机名也修改为172.16.100.94.qcow2,下面创建、恢复、删除快照请使用172.16.100.94.qcow2操作

三、创建快照

创建快照

[root@zerotrust169 vms]# virsh snapshot-create 172.16.100.94
Domain snapshot 1552550023 created

查看快照

[root@zerotrust169 vms]# virsh snapshot-list 172.16.100.94
 Name                 Creation Time             State
------------------------------------------------------------
 1552550023           2019-03-14 15:53:43 +0800 shutoff

[root@zerotrust169 vms]#

快照配置文件在/var/lib/libvirt/qemu/snapshot/172.16.100.94/

四、恢复快照

恢复虚拟机快照必须关闭虚拟机

查看虚拟机状态

virsh list --all

恢复虚拟机指定的快照

virsh snapshot-revert 172.16.100.94 1552550023

五、删除快照

查看虚拟机快照

[root@zerotrust169 vms]# qemu-img info 172.16.100.94
image: 172.16.100.94
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.5G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
1         1552550023                0 2019-03-14 15:53:43   00:00:00.000
2         1552550287             275M 2019-03-14 15:58:07   00:02:31.086
Format specific information:
	compat: 1.1
	lazy refcounts: true

可以看出有15525500231552550287两个快照

删除1552550023快照

[root@zerotrust169 vms]# virsh snapshot-delete 172.16.100.94 1552550023
Domain snapshot 1552550023 deleted

[root@zerotrust169 vms]# qemu-img info 172.16.100.94
image: 172.16.100.94
file format: qcow2
virtual size: 20G (21474836480 bytes)
disk size: 1.6G
cluster_size: 65536
Snapshot list:
ID        TAG                 VM SIZE                DATE       VM CLOCK
2         1552550287             275M 2019-03-14 15:58:07   00:02:31.086
Format specific information:
	compat: 1.1
	lazy refcounts: true
[root@zerotrust169 vms]#

转载于:https://my.oschina.net/lwenhao/blog/3022573

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值