I have a virtual machine (centos) running some file service for small files. What is the recommended way for backup? Should I backup the virtual machine disk/file (from outeside the virtual machine) or should run a backup agent inside the virtual machine, so i'll backup up the content and not the whole virutal disk?


TLDR: Install a backup agent within the VM.

Backing up the disk image from outside the VM certainly looks tempting, doesn't it? Especially if you have several VMs, then you can just tell the host machine to back up all the disk images and you're done, without needing to individually configure each VM to back itself up.

The problem with that approach, though, is that the host machine isn't aware of what the VM's operating system is doing internally. It doesn't know if there are any disk writes pending or in progress. It doesn't know about any write caches or output buffers internal to the VM process. And, therefore, it can't guarantee that the disk image it backs up will be a consistent image at the time of backup. The backed-up image file will almost certainly still be usable, but there's a strong chance that you'll need to run a filesystem repair on it first to clean things up.

The other major drawback to doing full-disk-image backups from the outside is that such backups are primarily useful for full-system restores. I you just need to get back last Thursday's version of one lost file, they're not so good for that - you need to restore the whole image from Thursday's backup, then use other tools to extract that one file from the second copy of the image, which will take a lot more time and space than if you had done a backup from within the VM and been able to restore only the one file of interest.

Also related to this is that full-image backups are more difficult (at best) to perform incrementally, meaning that you need to make a complete copy of the entire image every time you run a backup. With a content-based backup from within the VM, you can take periodic full backups and only back up changed files in between, allowing much more frequent backups with the same amount of storage space.

If you're making an image of the entire VM for disaster recovery purposes, or to use it as a master to clone for creating other VMs, then shutting the VM down and copying the full disk image is a good way to go about it. But it's not a good approach to doing routine backups of a running system.

  • I am doing backups with agent inside VM together with full clone of a machine. Aug 30 '20 at 12:16
  • 2
    KVM will tell the VM's qemu-guest-agent to quiesce the filesystem when freezing the VM filesystem. It also will let you run your own custom scripts to quiesce other stuff (e.g. MySQL). AFAIK every hypervisor has such capability, though possibly not the ability to run custom quiesce scripts. A hypervisor-aware backup tool will use this capability. I personally have KVM VMs on ZFS zvol backing store, which makes snapshotting and point in time restores very easy. Aug 30 '20 at 16:23
  • Thank you, this is very good and valid points. The backups purpose is not for restoring singel files, but only in case of hardware failure or other causes for the entire content to be damaged. It wont be a very long history of backups. Only one each night and kept for a week. There is no write operation between 01 and 06 in the night, so at that point it should be safe to take a backup . I se one big benifit by backing up the entire disk. This is much easier to restore. No need to reinstall the os, install agent and restore. Thank you for good points.
    – Mr Zach
    Aug 30 '20 at 16:27

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.