Dears,

I've followed the following steps in order to get a snapshot of a running VM on my KVM, but actually i'm not sure if that the correct way or no :

/usr/bin/virsh snapshot-create-as \
--domain VM_NAME SNAPSHOT \
--diskspec vda,file=/var/lib/libvirt/images/snapshot.dsk ,snapshot=external \
--disk-only \
--atomic 
  • then i edit the XML configuration in order to change the disk path to the original :

    virsh edit VM_NAME

replace: /var/lib/libvirt/images/snapshot.dsk with /var/lib/libvirt/images/VM.dsk

  • I delete the created snapshot:

/usr/bin/virsh snapshot-delete VM_NAME SNAPSHOT --metadata

  • then i get a copy from the block disk:
/usr/bin/virsh -q blockcopy VM_NAME vda /backup/block.dsk --wait --verbose -
-shallow --pivot
  • then :

/usr/bin/virsh blockcommit VM_NAME vda --active --verbose --pivot

  • then i define the VM again using the its dump XML..

Are these steps correct for taking a safe backup for the instance ? although of the outputed files' sizes are small comparing to the original ?

and the most important part now is:

How to restore the snapshot or the block in case if i faced any problems ? I tried to restore the block before using this command but it formatted the original disk and replaced with the small block that i backed up before which caused the VM to be lost :

# virsh stop VM_NAME

# qemu-img create \
-b /var/lib/libvirt/images/snapshot.dsk \
-f qcow2 \
var/lib/libvirt/images/VM.dsk

# virsh start VM_NAME

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.