1. snapshot OverviewFor openstack, the snapshot of a virtual machine is an image. After the snapshot is completed, it is stored in glance as an image. Although openstack snapshot is based on libvirt (qemu-KVM), there are major differences in implementation between the two:
- Libvirt mainstream snapshot implementation: uses the virdomainsnapshotcreatexml () function (CLI is virsh snapshot-create ). The new snapshot is associated with the Virtual Machine: if it is a built-in snapshot, the snapshot information and the virtual machine exist in the same qcow2 image; if it is an external snapshot, create a qcow2 file, the disk of the original VM will be changed to a read-only template image. The new qcow2 image is only recorded with 2. differential data of template images. This type of snapshot contains the snapshot chain information, which can retain disk and ram information and roll back to the snapshot point.
- Openstack snapshot implementation: openstack does not use virdomainsnapshotcreatexml () to create snapshots. Instead, it simply converts and copies Virtual Machine images, generates an image unrelated to the virtual machine, and finally uploads it to glance. This snapshot does not contain snapshot chain information. It only retains disk information and cannot be rolled back to the snapshot point. You can only use this snapshot image to create a new virtual machine.
2. Cold snapshot and live Snapshot
- Cold snapshot: when creating a snapshot, you must pause the VM.
- Live snapshot: when creating a snapshot, you do not need to pause the VM.
3. Cold snapshot process:
# Save the state and stop a running guest, then detach PCI devices $ Virsh managedsave VM# Create a qemu internal Snapshot $ Qemu-IMG snapshot-C snap1 vm_snapshot# Extract the internal snapshot, convert it to qcow2 and export it a file, then upload to glance $ Qemu-IMG convert-F qcow2 VM-O qcow2 vm_snapshot# Start the guest again $ Virsh start VM
4. Live snapshot Process
# Abort any failed/finished block operations:
$ Virsh blockjob vm vda -- abort
# Undefine a running domain. (Note: undefining a running domain does not _ kill _ the domain, it just converts it from persistent to transient .)
$ Virsh undefine VM
# Create a destination image with the original backing file and matching size of the Instance root disk.
$ Qemu-IMG create-F qcow2 vm_copy -- backing_file = backing_file -- size = root_disk_size
# Invoke 'virsh blockcopy' (this will take time, depending on the size of disk image VM1 ):
$ Virsh blockcopy -- domain vm vda vm_copy -- wait -- verbose
# Abort any failed/finished block operations:
$ Virsh blockjob vm vda -- abort
# Define the guest again (to make it persistent ):
$ Virsh define VM
# From the obtained new copy, convert the qcow2 with a backing file to a qcow2 image with no backing file, then upload to glance:
$ Qemu-IMG convert-F qcow2-o raw vm_copy vm_convert
5. virsh snapshot-create-as/snapshot-create snapshot Analysis
The default value is built-in snapshot, which supports snapshot chain, snapshot rollback, and memory information.
During the snapshot process, the VM gets stuck for a short time.
I wonder why openstack does not use this method to implement mainstream snapshots ?!
6. Conclusion
Supported Functions
- VM snapshot (the snapshot is stored in glance)
- Volume snapshot (LVM snapshot is stored locally)
Restrictions and disadvantages
References:1. https://www.redhat.com/archives/libvirt-users/2012-April/msg00142.html2. http://blog.csdn.net/halcyonbaby/article/details/199981552. http://itxx.sinaapp.com/blog/content/1303. http://kashyapc.com/2012/09/14/externaland-live-snapshots-with-libvirt/