2

Iam managing kvm by libvirt and using qcow2 file format. I can create snapshots of running wm with snapshot-create command, but if I transfer my qcow2 image to another host and define transfered host by virsh define, I cant see snapshots created previously. Is there a way how to transfer snapshots too?

Thanks ;-)

2

Assuming you have already transferred the images themselves and configured added their definitions to the destination libvirt instance all you need to do is to transfer the snapshot definitions as well. Here's a little script to aid you:

#!/bin/sh

SRC_URL=qemu:///system
SRC_DOMAIN_NAME=test
SRC_DOMAIN_UUID=`virsh -c $SRC_URL domuuid $SRC_DOMAIN_NAME`

DST_URL=qemu+ssh://example.com/system
DST_DOMAIN_NAME=test-clone
DST_DOMAIN_UUID=`virsh -c $DST_URL domuuid $DST_DOMAIN_NAME`

# Dump snapshot definitions
virsh -c $SRC_URL snapshot-list $SRC_DOMAIN_NAME | \
awk '$1 ~ /[[:digit:]]+/ { print $1 }' | \
xargs -I{} -n1 sh -c 'virsh -c "$1" snapshot-dumpxml "$2" "$3" | sed s#$4#$5# > "$2-$3.xml"' -- \
$SRC_URL $SRC_DOMAIN_NAME {} $SRC_DOMAIN_UUID $DST_DOMAIN_UUID

# Restore snapshot definitions
find . -type f -name "$SRC_DOMAIN_NAME-*.xml" | \
xargs -n1 echo virsh -c $DST_URL snapshot-create $DST_DOMAIN_NAME 

Just tune the variables to match your hosts and domains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.