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.
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.
Do not mount the folder that is used to store backups on network storage as a folder to store local backups on the cluster node (/image by default). In this case, the backups will be deleted immediately after they are moved to the remote 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:
- If the Stop the VM while it is being backed up option is enabled, stop VM.
- Сreate a snapshot of the VM disk:
- file storage — the snapshot file is created in the VM storage directory (by default — /vm);
- LVM — the LV of the snapshot is created in the VG where the LV of the virtual disk is stored;
- Ceph — the snapshot is created on the Ceph cluster node.
- 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.
- If the Stop the VM while it is being backed up option is enabled, start VM.
- Delete the original snapshot file.
- if a backup needs to be created on an external storage:
- Optimize the snapshot archive with the virt-sparsify utility.
- Move the snapshot archive to an external storage.
LXD cluster
- Create a backup of the VM in the /var/snap/lxd/common/lxd/backups/ directory on the cluster node.
- 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.
- Move the backup archive to the image storage directory on the cluster node (by default — /image).
- Delete the VM backup.
- If a backup needs to be created on an external storage, move the archive to an external storage.
Limitations
No more than one operation of the backup creation can be performed on a cluster node at a time.
Creating backups in LVM storage
Platform actions to create a backup in LVM storage:
-
Create a VM snapshot using a command:
lvcreate --size {self.size_mib} --snapshot --name '{self.snapshot_name}' '{self.disk}'
-
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
- 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:
- Checks whether there is enough space in the storage for VM1.
- Since there is enough space, the backup task is created for VM1.
- Calculates how much space will be left after creating the backup of VM1: 55 GB - 40 GB = 15 GB
- Checks whether there is enough space in the storage for VM2.
- Since there is not enough space, the backup task is not created.
- Checks whether there is enough space in the storage for VM3.
- Since there is enough space, the backup task is created for VM3.
- VM1 and VM3 backups are created on the external storage.