A backup is a virtual machine (VM) disk image that is used to restore it. Unlike custom images, backups contain all VM settings. For example, network settings, passwords, etc.

A backup does not guarantee the consistency of the databases used on the VM.

You can create a backup:

  • on the cluster node where the source VM is located — backups are created in the image storage directory. When migrating the VM, the backups are moved with it to another cluster node. 

    When a VM is deleted, its backups are deleted. To get a copy of the VM, which will be preserved after deleting the original VM, create a disk image. 

  • on an external storage — a backup is first created on the cluster node and then copied to the storage. When copying is complete, the backup is deleted from the cluster node. Read more about storage configuration in Backup storage.

You can create backups automatically according to a schedule. Read more in Creating backups automatically.

Restrictions of backups


When backing up a running VM, the consistency of the software data is not guaranteed. This is because the backup saves an image of the file system. If any operating system processes perform read or write operations while creating a backup, the latter state cannot be restored from the backup. For example, if you create a copy of a VM with a running database, it will be impossible to restore the database. In such cases, we recommend that you stop the VM before creating the backup.

Backup creation algorithm


KVM cluster

VMmanager actions to create a backup:

  1. Сreate a snapshot of the VM. In a file storage, the snapshot is created in the VM storage directory (by default — /vm), in an LVM storage — in LV where the original VM is stored, in a Ceph storage — on the Ceph cluster node.
  2. Move information from the snapshot to the image storage directory on the cluster node (by default — /image). The platform uses the zstd utility to create the archive. The level of compression is determined by the utility algorithms and is not guaranteed by the platform.
  3. Delete the original snapshot file.
  4. if a backup needs to be created on an external storage:
    1. Optimize the snapshot archive with the virt-sparsify utility.
    2. Move the snapshot archive to an external storage.

If you are using a file storage, there must be free space on the cluster node to create the backup, which is twice the size of the VM disk. For example, to create a backup of a VM with a 20 GB disk on the cluster node, you must have at least 40 GB free. 


LXD cluster

  1. Create a backup of the VM in the /var/snap/lxd/common/lxd/backups/ directory on the cluster node.
  2. Create a backup archive in the /var/snap/lxd/common/lxd/backups/instances/ directory on the cluster node. The platform uses the zstd utility to create the archive. The level of compression is determined by the utility algorithms and is not guaranteed by the platform.
  3. Move the backup archive to the image storage directory on the cluster node (by default — /image).
  4. Delete the VM backup.
  5. If a backup needs to be created on an external storage, move the archive to an external storage.

To create a backup, there must be free space on the cluster node, approximately 1.5 times the size of the VM disk. For example, to create a backup of a VM with a 20 GB disk on the cluster node, you must have at least 30 GB free. 

Limitations

No more than one operation can be performed on a cluster node at a time:

  • backup creation;
  • copying to external storage.

The external storage can only accept one backup at a time. Thus, if the storage is used by several nodes of a cluster, you cannot save VM copies from several nodes simultaneously.

Creating backups in LVM storage

Platform actions to create a backup in LVM storage:

  1. Create a VM snapshot using a command:

    lvcreate --size {self.size_mib} --snapshot --name '{self.snapshot_name}' '{self.disk}'
    BASH
  2. Checks for free space on the node and compresses the disk with the zstd utility using the command:

    set -o pipefail; nice -n 5 dd bs=4M if=/vm/{vm_name} | zstd --no-progress --rm -1 -T1 -c | dd bs=4M of=/image/1_{vm_name}_backup.qcow2.zst
    BASH
  3. Moves the snapshot archive to the external LVM storage.

Specific features of creating scheduled backups


When working according to schedule, VMmanager checks the possibility of this operation before copying VM to the external storage. The platform sequentially calculates whether there will be enough space on the external storage for each VM. If there is enough space for the VM in the storage, VMmanager creates a backup task.

For example, you need to create backups for virtual machines VM1 (disk capacity 40 GB), VM2 (disk capacity 20 GB) and VM3 (disk capacity 10 GB). The external storage has 55 GB free. To create the backups, VMmanager:

  1. Checks whether there is enough space in the storage for VM1.
  2. Since there is enough space, the backup task is created for VM1.
  3. Calculates how much space will be left after creating the backup of VM1: 55 GB - 40 GB = 15 GB
  4. Checks whether there is enough space in the storage for VM2.
  5. Since there is not enough space, the backup task is not created.
  6. Checks whether there is enough space in the storage for VM3.
  7. Since there is enough space, the backup task is created for VM3.
  8. VM1 and VM3 backups are created one after another on the external storage.