]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
lib: Introduce VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN flag
authorPeter Krempa <pkrempa@redhat.com>
Thu, 13 Nov 2025 15:12:08 +0000 (16:12 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 24 Nov 2025 15:40:24 +0000 (16:40 +0100)
This flag will instruct the hypervisor driver to keep the VM around
while the backup is running if the guest OS decides to shut down, so
that the backup can be finished.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/manpages/virsh.rst
include/libvirt/libvirt-domain.h
src/libvirt-domain.c
tools/virsh-backup.c

index 73263ffc7f0a64f24264ee736084307db7a5e011..a9d691824e6c547b325340c91d3d42d02b52d1bd 100644 (file)
@@ -2186,6 +2186,7 @@ backup-begin
 ::
 
    backup-begin domain [backupxml] [checkpointxml] [--reuse-external]
+       [--preserve-domain-on-shutdown]
 
 Begin a new backup job. If *backupxml* is omitted, this defaults to a full
 backup using a push model to filenames generated by libvirt; supplying XML
@@ -2199,6 +2200,11 @@ libvirt. For more information on backup XML, see:
 If *--reuse-external* is used it instructs libvirt to reuse temporary
 and output files provided by the user in *backupxml*.
 
+When the *--preserve-domain-on-shutdown* flag is used libvirt will not
+terminate the VM if the guest OS shuts down while the backup is running. The VM
+will be instead kept in VIR_DOMAIN_PAUSED state until the backup job finishes.
+The vm can be also resumed in order to boot again.
+
 If *checkpointxml* is specified, a second file with a top-level
 element of *domaincheckpoint* is used to create a simultaneous
 checkpoint, for doing a later incremental backup relative to the time
index 3f5bd1ff7bb3e620c7717678d6a35511663acf4f..16fac6b0851c6c502418ef6d65fe5121b0447e4e 100644 (file)
@@ -8518,8 +8518,10 @@ int virDomainAgentSetResponseTimeout(virDomainPtr domain,
  * Since: 6.0.0
  */
 typedef enum {
-    VIR_DOMAIN_BACKUP_BEGIN_REUSE_EXTERNAL = (1 << 0), /* reuse separately
-                                                          provided images (Since: 6.0.0) */
+    /* reuse separately provided images (Since: 6.0.0) */
+    VIR_DOMAIN_BACKUP_BEGIN_REUSE_EXTERNAL = (1 << 0),
+    /* preserve the domain if the guest OS shuts down while the backup is running (Since: 11.10.0) */
+    VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN = (1 << 1),
 } virDomainBackupBeginFlags;
 
 int virDomainBackupBegin(virDomainPtr domain,
index ca110bdf8585d3c9f0dec12396a04758fc337734..74c70a0a43fe95f2d18fca3a1bcb5ba998d7b047 100644 (file)
@@ -13682,6 +13682,11 @@ virDomainAgentSetResponseTimeout(virDomainPtr domain,
  * temporary files described by the @backupXML document were created by the
  * caller with correct format and size to hold the backup or temporary data.
  *
+ * When the VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN flag is used
+ * libvirt will not terminate the VM if the guest OS shuts down while the
+ * backup is running. The VM will be kept in the VIR_DOMAIN_PAUSED state
+ * until the backup job finishes or until it's resumed via virDomainResume.
+ *
  * The creation of a new checkpoint allows for future incremental backups.
  * Note that some hypervisors may require a particular disk format, such as
  * qcow2, in order to take advantage of checkpoints, while allowing arbitrary
index 39e62f9ba91c100bf6da2bbdb06218f9ff6670fa..1d009a3f2c47f5d083c13e703198a2a42d0dd89c 100644 (file)
@@ -48,6 +48,10 @@ static const vshCmdOptDef opts_backup_begin[] = {
      .type = VSH_OT_BOOL,
      .help = N_("reuse files provided by caller"),
     },
+    {.name = "preserve-domain-on-shutdown",
+     .type = VSH_OT_BOOL,
+     .help = N_("avoid shutdown of the domain while the backup is running"),
+    },
     {.name = NULL}
 };
 
@@ -65,6 +69,9 @@ cmdBackupBegin(vshControl *ctl,
     if (vshCommandOptBool(cmd, "reuse-external"))
         flags |= VIR_DOMAIN_BACKUP_BEGIN_REUSE_EXTERNAL;
 
+    if (vshCommandOptBool(cmd, "preserve-domain-on-shutdown"))
+        flags |= VIR_DOMAIN_BACKUP_BEGIN_PRESERVE_SHUTDOWN_DOMAIN;
+
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;