官术网_书友最值得收藏!

Backing up your VM metadata

While a KVM stores some of the resources' configuration on the disk in a human readable format, it is a good idea to query libvirt for the configuration of your resources.

How to do it…

In this recipe we'll back up all relevant KVM metadata by performing the following steps:

Here's the network configuration:

~]# for i in $(virsh net-list --all | sed -e '1,2d' |awk '{print $1}'); do \
 virsh net-dumpxml --network $i --inactive > /tmp/net-$i.xml; \
done

Here's the storage configuration:

~]# for i in $(virsh pool-list --all | sed -e '1,2d' |awk '{print $1}'); do \
 for j in $(virsh vol-list --pool $i |sed -e '1,2d') | awk '{print $1}'; do \
 virsh vol-dumpxml --pool $i --vol $j > /tmp/vol-$j.xml; \
 done \
 virsh pool-dumpxml --pool $i --inactive > /tmp/pool-$i.xml; \
done

Here's the guest configuration:

~]# for i in $(virsh list --all | sed -e '1,2d' |awk '{print $1}'); do \
 virsh dumpxml --domain $i --inactive > /tmp/domain-$i.xml; \
done

How it works…

The virsh net-dumpxml command allows you to dump the precise configuration of the specified network. In combination with virsh net-list, you can create a loop that enumerates all networks and dumps them on the file. By specifying –-all, you will export all networks, even those that are not active. If you do not wish to back up the configuration for nonactive networks, substitute virsh net-list --all with virsh net-list.

Storage pools can be enumerated, similarly to networks, using virsh net-list. However, besides the individual storage pool configuration, we are also interested in the configuration of individual storage volumes. Luckily, both implement a list and dumpxml command! If you're not interested in nonactive pools, you can omit the --all option with virsh pool-list.

Guests can similarly be enumerated and their XML configuration dumped using dumpxml. Again, if you're not interested in nonactive guests, you can omit the --all option with virsh list.

See also

The man page for virsh (1) lists all the possible options for the commands used in the preceding section.

主站蜘蛛池模板: 临汾市| 息烽县| 宁国市| 苏尼特左旗| 汉源县| 沙坪坝区| 江川县| 五河县| 重庆市| 滕州市| 宜君县| 梅河口市| 泾源县| 东莞市| 专栏| 鹤峰县| 玉门市| 太湖县| 吴堡县| 永新县| 龙陵县| 尖扎县| 屏山县| 石景山区| 昆明市| 深水埗区| 绍兴县| 珠海市| 麟游县| 庐江县| 乐昌市| 郑州市| 余庆县| 临泉县| 游戏| 临猗县| 溧水县| 图们市| 嫩江县| 石柱| 瓮安县|