virsh 保护命令 virtual protect rebase

本文介绍了使用virsh命令管理虚拟机快照的方法,包括全量备份、增量备份、清理快照和重置bitmap。重点讨论了如何利用qemu-img commit和rebase操作进行快照合并及删除,以及持久化bitmap的设置和管理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

virsh list --all 

查看虚拟机列表

virsh list

virsh domblklist centos6.5

qemu-img snapshot -l /var/lib/libvirt/images/centos6.5.qcow2

备份:

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "transaction", "arguments": { "actions": [ { "type": "block-dirty-bitmap-add", "data": {"node":"drive-virtio-disk0", "name":"bitmap0"}}, { "type": "drive-backup", "data": {"device": "drive-virtio-disk0", "target": "/opt/backup/top.img","sync":"top" }} ]} }'

# ...运行一段时间... virsh qemu-monitor-command DOMAIN --pretty '{ "execute" : "drive-backup" , "arguments" : { "device" : "drive-virtio-disk0" , "sync" : "incremental" , "bitmap" : "bitmap0" , "target" : "/opt/backup/inc.0.qcow2" } }'

# ...又运行一段时间... virsh qemu-monitor-command DOMAIN --pretty '{ "execute" : "drive-backup" , "arguments" : { "device" : "drive-virtio-disk0" , "sync" : "incremental" , "bitmap" : "bitmap0" , "target" : "/opt/backup/inc.1.qcow2" } }'

如果之前已经创建过bitmap,此刻想忽略bitmap,重新做一次完整备份,并重置bitmap(用于接下来的增量备份),则可以

{ "execute": "transaction", "arguments": { "actions": [ {"type": "block-dirty-bitmap-clear", "data": {"node": "drive-virtio-disk0", "name": "bitmap0"} }, {"type": "drive-backup", "data": {"device": "drive-virtio-disk0", "target": "/path/to/new_full_backup.img", "sync": "top"} } ] } }

# 查询虚拟机的所有磁盘的bitmap

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "query-block" }'

查看备份任务

# 通过qmp查看

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "query-block-jobs" }'

全量:

virsh qemu-monitor-command DOMAIN '{ "execute" : "drive-backup" , "arguments" : { "device" : "drive-virtio-disk0" , "sync" : "top" , "target" : "/opt/backup/top.img" } }'

解决qemu-img commit   的差异

1.xp xp_snap1 xp_snap2 xp_snap3 xp_new

镜像xp_new与xp的关系如上,左依次为右的backing file

如要删除xp_snap2时,(即关系变为xp xp_snap1 xp_snap3 xp_new)

先用qemu-img commit xp_snap2 命令将xp_snap2的内容commit到xp_snap1

再将xp_snap3的backing file指向xp_snap1

qemu-img rebase -f qcow2 -b xp_snap1 -F qcow2 xp_snap3 (将会比较xp_snap1与xp_snap2是否一致)

qemu-img commit xp_snap3

永久bitmap 

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "transaction", "arguments": { "actions": [ { "type": "block-dirty-bitmap-add", "data": {"node":"drive-virtio-disk0", "name":"bitmap0","persistent": true}}, { "type": "drive-backup", "data": {"device": "drive-virtio-disk0", "target": "/opt/backup/top.img","sync":"top" }} ]} }'

 删除bitmaps

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "block-dirty-bitmap-remove","arguments":{"node":"drive-virtio-disk0","name":"bitmap0"} }'

 清空bitmaps

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "block-dirty-bitmap-clear","arguments":{"node":"drive-virtio-disk0","name":"bitmap0"} }'

增加bitmaps

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "block-dirty-bitmap-add","arguments":{"node":"drive-virtio-disk0","name":"bitmap0"} }'

永久增加bitmaps

virsh qemu-monitor-command DOMAIN --pretty '{ "execute": "block-dirty-bitmap-add","arguments":{"node":"drive-virtio-disk0","name":"bitmap0","":true} }'

问题:

https://www.mail-archive.com/qemu-devel@nongnu.org/msg592973.html

 1

{"id":"libvirt-42","error":{"class":"GenericError","desc":"Can't make
bitmap 'bitmap0' persistent in 'drive-virtio-disk1': Bitmap with the
same name is already stored"}}
In other word, when qemu crash, the qcow2 image remain the incomplete
persistent bitmap.
persistent bitmap will be inconsistent when qemu  crash,
crash will genrerate this question。

问题2:

Cannot store dirty bitmaps in qcow2 v2 files



参考:
https://www.lizi.tw/soft/16760.html      QEMU/KVM磁盘的在线完整及增量备份

mount -t nfs 192.168.10.161:/mnt/vg /home/kvm -o rw

 一键接管

virsh domblklist demo

virsh dumpxml demo > demo.xml

qemu-img rebase -u

qemu-img commit inc2.qcow2

 qemu-img rebase -u -b base.img commit.img

qemu-img commit  commit.img

外置快照的删除(qemu-img commit/rebase)

1.方法

我们需要删除快照sn2 当前: [centosbase] <– centos2 <– centos2_sn1 <– centos2_sn2 <– centos2_sn3 <– centos2_sn4(当前使用磁盘) 目标: [centosbase] <– centos2 <– centos2_sn1 <—————— centos2_sn3 <– centos2_sn4(当前使用磁盘) 现在删除第二个快照(sn2).有两种方式: (1): 复制sn2数据到后端sn1,将会commit所有sn2中的数据到sn2的backing file(sn1),和virsh blockcommit类似 (2): 复制sn2数据到前段sn3,将会commit所有sn2中的数据到sn2的overlays,和virsh blockpull类似 注意: 必须保证sn1没有被其他快照作为后端(即centos2_sn1只被当前链使用)

2.(1): 复制sn2数据到后端sn1

qemu-img commit centos2_sn2.qcow2
qemu-img rebase -u -b centos2_sn1.qcow2 centos2_sn3.qcow2     #让sn3指向sn1

#现在sn1中包含了之前的sn1/sn2中的数据,所以此时不再需要sn2中的数据,直接让sn3指向sn1即可,可以直接删除sn2 注意: -u代表’Unsafe mode’ – 此模式下仅仅修改了指向到的backing file名字(不复制数据)

修改网卡 

修改img  路径

virsh define  /mnt/102.xml

virsh start name_102

qemu-img -V

查看

qemu-img version 4.1.0

qemu >=2.10  才能  永久bitmaps 

qemu >= 2.10

(免费订阅,永久学习)学习地址: Dpdk/网络协议栈/vpp/OvS/DDos/NFV/虚拟化/高性能专家-学习视频教程-腾讯课堂

更多DPDK相关学习资料有需要的可以自行报名学习,免费订阅,永久学习,或点击这里加qun免费
领取,关注我持续更新哦! !  

原文链接:https://www.cnblogs.com/rebrobot/p/15533530.html
参考:

https://opengers.github.io/virtualization/kvm-libvirt-qemu-5/
https://qemu-project.gitlab.io/qemu/interop/dbus-vmstate.html
https://qemu-project.gitlab.io/qemu/system/index.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值