kvm snapshot 迁移
Posted onecing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kvm snapshot 迁移相关的知识,希望对你有一定的参考价值。
kvm snapshot 迁移。
https://dev.to/mediocredevops/cloning-kvm-snapshots-1paj
1.
virt-clone --original $Source_VM_Name --name $Destination_VM_Name --file /var/lib/libvirt/images/$Destination_VM_Name.qcow2 --print-xml > $Destination_VM_Name.xml
virt-clone --original win7 --name win7-1 --file /var/lib/libvirt/images/win7-1.qcow2 --print-xml > win7-1.xml
2.
cp --progress /var/lib/libvirt/images/centos8.qcow2 /var/lib/libvirt/images/centos8-mig.qcow2
cp win7.qcow2 win71.qcow2
3.
virt-sysprep -a $Destination_VM_Name.qcow2
virt-sysprep -a win71.qcow2
4.
virsh define $Destination_VM_Name.xml
virsh define win7-1.xml
5.
virsh snapshot-list $Source_VM_Name --tree
virsh snapshot-dumpxml $Source_VM_Name $Snapshot_Name --security-info > Snapshot_Name.xml
virsh snapshot-list $Source_VM_Name |sed -e '1,2d' -e '/^$/d'|cut -d' ' -f2| while read -r line; do virsh snapshot-dumpxml $Source_VM_Name --snapshotname $line --security-info > "$line.xml" ;done
virsh snapshot-dumpxml win7 snapshot1 --security-info > snapshot1.xml
6.
<name>$Source_VM_Name</name>
<uuid>$Source_UUID<uuid>
<source file='/var/lib/libvirt/images/$Source_VM_Name.qcow2'/>
to
<name>$Destination_VM_Name</name>
<uuid>$Destination_UUID<uuid>
<source file='/var/lib/libvirt/images/$Destination_VM_Name.qcow2'/>
7.
virsh snapshot-create $Destination_VM Snapshot_Name.xml --redefine
virsh snapshot-create win7-1 snapshot1.xml --redefine
做成自动化脚本就是:
#!/usr/bin/env bash
#################################################
#### Ensure we are in the right path. ###########
#################################################
if [[ 0 -eq `echo $0 | grep -c '^/'` ]]; then
# relative path
EXEC_PATH=$(dirname "`pwd`/$0")
else
# absolute path
EXEC_PATH=$(dirname "$0")
fi
EXEC_PATH=$(echo $EXEC_PATH | sed 's@/\\./@/@g' | sed 's@/\\.*$@@')
cd $EXEC_PATH || exit 1
#################################################
export PS4='+($BASH_SOURCE:$LINENO): $FUNCNAME[0]:+$FUNCNAME[0](): '
virt-clone --original win7 --name win7-1 --file /var/lib/libvirt/images/win7-1.qcow2 --print-xml > win7-1.xml
cp win7.qcow2 win71.qcow2
virt-sysprep -a win71.qcow2
virsh define win7-1.xml
virsh snapshot-dumpxml win7 snapshot1 --security-info > snapshot1.xml
#echo "src-domain:$1"
#echo "dst-domain:$2"
#echo "dst-template:$3"
#echo "src-qcow2:$4"
#echo "dst-qcow2:$5"
#echo "dst-file:$6"
dstuuid=`sed -n "/<uuid>.*<\\/uuid>/p" win7-1.xml | sed -n '1,1p' | sed 's/^[][ ]*//g' |sed -r "s/<uuid>(.*)<\\/uuid>/\\1/g"`d>/\\1/g"`
sed -i "s/<uuid>.*<\\/uuid>/<uuid>$dstuuid<\\/uuid>/g" snapshot1.xml
sed -i "s/<name>win7<\\/name>/<name>win7-1<\\/name>/g" snapshot1.xml
sed -i "s/win7.qcow2/win71.qcow2/g" snapshot1.xml
virsh snapshot-create win7-1 snapshot1.xml --redefine
重新开关一下virt-manager即可看到并使用了
以上是关于kvm snapshot 迁移的主要内容,如果未能解决你的问题,请参考以下文章