A VM with the panel's emulated TPM 2.0 is backed up when it is shut off:
each state file of libvirt's swtpm directory for the VM, read through a
transient pool on it, becomes a small file of the backup (role tpm),
written and read back like the NVRAM file. A running or paused VM with a
TPM is refused, and so is a TPM with its own settings (encryption, a
state path, another backend). The manifest says whether the TPM state was
copied or never written.
A backup schedule (BackupPolicy) names its VMs, chosen or every VM of a
compute at the time it runs (templates left out), a target, a daily time
in the panel's time zone, how many backups of each VM to keep (one at
least), whether frozen file systems are required, and the superuser its
jobs run as. A run (BackupRun) records one VM's backup of one day, keyed
by the VM's row, not its UUID, which two VM rows may share. A backup
keeps the schedule that made it; deleting the schedule keeps its
backups. A backup whose files are gone can be marked missing, and a
target keeps when it was last checked.
The worker runs the tasks apps register with register_periodic about
once a minute, on a thread of their own, one pass at a time, each
guarded: a pass stuck on a host takes no thread recovery or a cancel
needs, and one failing task stops none of the others. Nothing registers
one yet.
backup.create takes the schedule that asked for it; one deleted while
the job was queued leaves the backup without a schedule.
Backups in the menu now opens a page of every backup, newest first,
filtered by VM name, target and state; a removed VM's backups are
marked. Each backup, there and on the VM's Backups tab, has a Delete
button (also DELETE /api/v1/backups/<uuid>/, 202 with the job).
The backup.delete job holds the backup and its target. Through the
first of the target's computes that reaches its pool, it marks the
backup deleting, removes the manifest first, so the target no longer
holds a complete backup, then every other file named from the backup's
UUID (also those a failed backup left), then the row. Recovery runs the
same steps again. A backup being made is refused: its job is cancelled
instead.
States and consistency are shown in the reader's language.
A superuser backs a VM up from its new Backups tab, or with POST
/api/v1/backups/ (202 with the job); GET lists and reads backups. The
backup.create job holds the VM, its compute (shared) and the target, so
migrations, snapshots and power changes of the VM wait meanwhile.
- A shut-off VM's disks are copied one at a time into the target pool,
flat, in their format (createXMLFrom); a cancel stops before the next.
- A running or paused VM's disks go by libvirt's push backup into
volumes made first, as the live clone: the file systems frozen for its
start when the guest agent answers (frozen), crash-consistent
otherwise, or refused when frozen file systems are required. A guest
that shuts down meanwhile does not end the backup.
- A running VM's NVRAM file is kept only when it reads the same after
the copy as before it (three reads), so it is the capture point's.
- Then the NVRAM file, the definition and the manifest (written last)
are uploaded and read back, and the row becomes ready with its files.
- Recovery thaws a frozen guest first, watches a push backup still
running, finishes a copied backup, removes the files of a failed or
cancelled one, and leaves a copy whose end libvirt cannot tell
uncertain with its files named. The target pool is checked by UUID and
its free space before anything is made.