virsh 保护命令 virtual protect rebase

 

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











参考:


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




posted @ 2021-11-10 14:44  redrobot  阅读(218)  评论(0)    收藏  举报