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.
You can create backups automatically according to a schedule. Read more in Creating backups automatically.
Backup creation algorithm
VMmanager actions to create a backup:
- С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.
- Move information from the snapshot to the image storage directory on the cluster node (by default — /images). The platform uses the zstd utility to create the archive.
- 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.
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.
- 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.
- Move the backup archive to the image storage directory on the cluster node (by default — /images).
- Delete the VM backup.
- 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.
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.
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 one after another on the external storage.