On Fri, May 01, 2020 at 16:05:47 +0100, Stefan Hajnoczi wrote: > On Wed, Apr 22, 2020 at 07:51:09AM +0200, Anders Östling wrote: > > I am fighting to understand the difference between backing up a VM by > > using a regular copy vs using the virsh blockcopy command. > > What I want to do is to suspend the vm, copy the XML and .QCOW2 files > > and then resume the vm again. What are your thoughts? What are the > > drawbacks compared to other methods? The approaches have diffrerent kind of data integrity they provide and downtime they require. Assuming from the above that you don't want to shutdown the OS in the VM you've got following options: 1) pause VM and copy images as described above I definitely don't recommend this approach at all. The drawback is that the QCOW2 file on the disk may have inconsistent metadata. Even if you ensure that the gues OS state is consistend and written to disk it's not guaranteed that qemu's buffers were flushed. Also the VM needs to be suspended during the whole copy, unless you have the image on a filesystem which has --reflink support as pointed out by Stefan. 2) 'virsh blockcopy' The original idea of blockcopy is to move storage of an active VM to a different location. It can be used though to "copy" the active disk and ensure that the metadata is correct when combined with 'virsh blockjob --abort' to finish it. This still requires the guest OS in the VM to ensure that the filesystems on the backed-up disk are consistent. Also the API has one very severe limitation if your VM has multiple disks: There is no way to ensure that you cancel all the copies at the same time, so the 'backup' done this way is not taken at a single point in time. It's also worth noting that the point in time the backup is taken is when the job is --abort-ed. 3) virsh backup This is the newest set of APIs specifically designed to do disk backups of the VM, offers consistency of the image metadata, and taking of the backups of multiple disks at the same point in time. Also the point in time is when the API is started, regardless of how long the actual data handling takes. Your gues OS still needs to ensure filesystem consistency though. Additionally as mentioned by Stefan below you can also do incremental backups as well. One thing to note though is that the backup integration is not entirely finished in libvirt and thus in a 'tech-preview' state. Some interactions corrupt the state for incremental backups. If you are interested, I can give you specific info how to enable support for backups as well as the specifics of the current state of implementation. 4) snapshots Libvirt's snapshot implementation supports taking full VM snapshots including memory and disk image state. This sidesteps the problem of inconsistent filesystem state as the memory state contains also all the buffers. When an external snapshot is created, we add a new set of overlay files on top of the original disk images. This means that they become effectively read-only. You can then copy them aside if you want so. The memory image taken along can be then used to fully restore the state of the VM. There are a few caveats here as well. If the image chain created this way becomes too long it may negatively impact performance. Also reverting the memory image is a partially manual operation for now. I can give specifics if you want. > > Hi Anders, > The kvm@xxxxxxxxxxxxxxx mailing list is mostly for the discussion and > development of the KVM kernel module so you may not get replies. I have > CCed libvir-list and developers who have been involved in libvirt backup > features. > > A naive cp(1) command will be very slow because the entire disk image is > copied to a new file. The fastest solution with cp(1) is the --reflink > flag which basically takes a snapshot of the file and shares the disk > blocks (only available when the host file system supports it and not > available across mounts). > > Libvirt's backup commands are more powerful. They can do things like > copy out a point-in-time snapshot of the disk while the guest is > running. They also support incremental backup so you don't need to > store a full copy of the disk image each time you take a backup. > > I hope others will join the discussion and give examples of some of the > available features. > > Stefan