From nobody Fri Dec 19 02:49:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1571415146; cv=none; d=zoho.com; s=zohoarc; b=XD4QR1V3YPr/rVSSd5GxI6jMwiZ6tQ97xH9nDO1T+HIMxg++guSyQ2BTngdJYAwd7spTMrWes51azQHA+jngKTrHqezbyqIwCPIpmTygZEQTGO6E/dkyEzPZ8w4OfbCzYJgHQpHkIfmyK22BgnAkTTQWa2rHwhjh3iKz8FnAA2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571415146; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uLPZOLcuF6O/8ksXuPn9EfyqE8N68mmJlHD0pdCdloQ=; b=E3b8JJtJBW5ZOcdcNAPUfJmoPZveaHyJJdNQLHj7j1jzdzkyAMyYhdwUEfDyJumydT3jk8nsPmf6Q/QEopj40xzM/YPNMyngBYn4Psciii73dgC47gN6eP3/q07taRDIIJJPk2zbcgyH8z4NfDsnbgA+n6WFZn6QR/mN47S2b6w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1571415146801341.6949373451862; Fri, 18 Oct 2019 09:12:26 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1C6A9C04959E; Fri, 18 Oct 2019 16:12:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2A0560619; Fri, 18 Oct 2019 16:12:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7AB2D3FB55; Fri, 18 Oct 2019 16:12:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9IGCN5J005367 for ; Fri, 18 Oct 2019 12:12:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E7E2600C8; Fri, 18 Oct 2019 16:12:23 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C414E600C1; Fri, 18 Oct 2019 16:12:20 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 18 Oct 2019 18:11:18 +0200 Message-Id: <2b25a8b3e09569ae8ed2d97561ffd9ab5f729489.1571414890.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC 33/40] backup: Implement virsh support for backup X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 18 Oct 2019 16:12:25 +0000 (UTC) Content-Type: text/plain; charset="utf-8" From: Eric Blake Introduce virsh commands for performing backup jobs. Signed-off-by: Eric Blake --- tools/Makefile.am | 1 + tools/virsh-backup.c | 209 +++++++++++++++++++++++++++++++++++++++++++ tools/virsh-backup.h | 21 +++++ tools/virsh.c | 2 + tools/virsh.h | 1 + tools/virsh.pod | 37 ++++++++ 6 files changed, 271 insertions(+) create mode 100644 tools/virsh-backup.c create mode 100644 tools/virsh-backup.h diff --git a/tools/Makefile.am b/tools/Makefile.am index 68320c7246..813cfaeb53 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -233,6 +233,7 @@ virt_login_shell_helper_CFLAGS =3D \ virsh_SOURCES =3D \ virsh.c virsh.h \ + virsh-backup.c virsh-backup.h\ virsh-checkpoint.c virsh-checkpoint.h \ virsh-completer.c virsh-completer.h \ virsh-completer-domain.c virsh-completer-domain.h \ diff --git a/tools/virsh-backup.c b/tools/virsh-backup.c new file mode 100644 index 0000000000..7719b4f3cc --- /dev/null +++ b/tools/virsh-backup.c @@ -0,0 +1,209 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include +#include "virsh-backup.h" +#include "virsh-util.h" + +#include "internal.h" +#include "virfile.h" + +/* + * "backup-begin" command + */ +static const vshCmdInfo info_backup_begin[] =3D { + {.name =3D "help", + .data =3D N_("Start a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("Use XML to start a full or incremental disk backup of a= live " + "domain, optionally creating a checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_begin[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "backupxml", + .type =3D VSH_OT_STRING, + .help =3D N_("domain backup XML"), + }, + {.name =3D "checkpointxml", + .type =3D VSH_OT_STRING, + .help =3D N_("domain checkpoint XML"), + }, + {.name =3D NULL} +}; + +static bool +cmdBackupBegin(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + const char *backup_from =3D NULL; + g_autofree char *backup_buffer =3D NULL; + const char *check_from =3D NULL; + g_autofree char *check_buffer =3D NULL; + unsigned int flags =3D 0; + int id; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "backupxml", &backup_from) < 0) + return false; + + if (!backup_from) { + backup_buffer =3D vshStrdup(ctl, ""); + } else { + if (virFileReadAll(backup_from, VSH_MAX_XML_FILE, &backup_buffer) = < 0) { + vshSaveLibvirtError(); + return false; + } + } + + if (vshCommandOptStringReq(ctl, cmd, "checkpointxml", &check_from) < 0) + return false; + if (check_from) { + if (virFileReadAll(check_from, VSH_MAX_XML_FILE, &check_buffer) < = 0) { + vshSaveLibvirtError(); + return false; + } + } + + if ((id =3D virDomainBackupBegin(dom, backup_buffer, check_buffer, fla= gs)) < 0) + return false; + + vshPrint(ctl, _("Backup id %d started\n"), id); + + return true; +} + + +/* + * "backup-dumpxml" command + */ +static const vshCmdInfo info_backup_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("Dump XML for an ongoing domain block backup job") + }, + {.name =3D "desc", + .data =3D N_("Backup Dump XML") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_dumpxml[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .help =3D N_("backup job id"), + }, + {.name =3D NULL} +}; + +static bool +cmdBackupDumpXML(vshControl *ctl, + const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + g_autofree char *xml =3D NULL; + unsigned int flags =3D 0; + int id =3D 0; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_XML_SECURE; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!(xml =3D virDomainBackupGetXMLDesc(dom, id, flags))) + return false; + + vshPrint(ctl, "%s", xml); + return true; +} + + +/* + * "backup-end" command + */ +static const vshCmdInfo info_backup_end[] =3D { + {.name =3D "help", + .data =3D N_("Conclude a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("End a domain block backup job") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_end[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .help =3D N_("backup job id"), + }, + {.name =3D NULL} +}; + +static bool +cmdBackupEnd(vshControl *ctl, const vshCmd *cmd) +{ + g_autoptr(virshDomain) dom =3D NULL; + unsigned int flags =3D 0; + int id =3D 0; + int rc; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if ((rc =3D virDomainBackupEnd(dom, id, flags)) < 0) + return false; + + vshPrint(ctl, _("Backup id %d terminated"), id); + + return true; +} + + +const vshCmdDef backupCmds[] =3D { + {.name =3D "backup-begin", + .handler =3D cmdBackupBegin, + .opts =3D opts_backup_begin, + .info =3D info_backup_begin, + .flags =3D 0 + }, + {.name =3D "backup-dumpxml", + .handler =3D cmdBackupDumpXML, + .opts =3D opts_backup_dumpxml, + .info =3D info_backup_dumpxml, + .flags =3D 0 + }, + {.name =3D "backup-end", + .handler =3D cmdBackupEnd, + .opts =3D opts_backup_end, + .info =3D info_backup_end, + .flags =3D 0 + }, + {.name =3D NULL} +}; diff --git a/tools/virsh-backup.h b/tools/virsh-backup.h new file mode 100644 index 0000000000..95c2f5a424 --- /dev/null +++ b/tools/virsh-backup.h @@ -0,0 +1,21 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "virsh.h" + +extern const vshCmdDef backupCmds[]; diff --git a/tools/virsh.c b/tools/virsh.c index a3553ddd36..59c3ddb4b7 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -47,6 +47,7 @@ #include "virstring.h" #include "virgettext.h" +#include "virsh-backup.h" #include "virsh-checkpoint.h" #include "virsh-console.h" #include "virsh-domain.h" @@ -831,6 +832,7 @@ static const vshCmdGrp cmdGroups[] =3D { {VIRSH_CMD_GRP_NODEDEV, "nodedev", nodedevCmds}, {VIRSH_CMD_GRP_SECRET, "secret", secretCmds}, {VIRSH_CMD_GRP_SNAPSHOT, "snapshot", snapshotCmds}, + {VIRSH_CMD_GRP_BACKUP, "backup", backupCmds}, {VIRSH_CMD_GRP_STORAGE_POOL, "pool", storagePoolCmds}, {VIRSH_CMD_GRP_STORAGE_VOL, "volume", storageVolCmds}, {VIRSH_CMD_GRP_VIRSH, "virsh", virshCmds}, diff --git a/tools/virsh.h b/tools/virsh.h index b4e610b2a4..d84659124a 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -51,6 +51,7 @@ #define VIRSH_CMD_GRP_NWFILTER "Network Filter" #define VIRSH_CMD_GRP_SECRET "Secret" #define VIRSH_CMD_GRP_SNAPSHOT "Snapshot" +#define VIRSH_CMD_GRP_BACKUP "Backup" #define VIRSH_CMD_GRP_HOST_AND_HV "Host and Hypervisor" #define VIRSH_CMD_GRP_VIRSH "Virsh itself" diff --git a/tools/virsh.pod b/tools/virsh.pod index cf2798e71a..83cb315506 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1327,6 +1327,43 @@ addresses, currently 'lease' to read DHCP leases, 'a= gent' to query the guest OS via an agent, or 'arp' to get IP from host's arp tables. If unspecified, 'lease' is the default. +=3Ditem B I [I] +[I + +Begin a new backup job, and output the resulting job id on success. If +I is omitted, this defaults to a full backup using a push +model to filenames generated by libvirt; supplying XML allows +fine-tuning such as requesting an incremental backup relative to an +earlier checkpoint, controlling which disks participate or which +filenames are involved, or requesting the use of a pull model backup. +The B command shows any resulting values assigned by +libvirt. For more information on backup XML, see: +L. + +If I is specified, a second file with a top-level +element of is used to create a simultaneous +checkpoint, for doing a later incremental backup relative to the time +the backup was created. See B for more details on +checkpoints. + +This command returns as soon as possible, and the backup job runs in +the background; the progress of a push model backup can be checked +with B or by waiting for an event with B (the +progress of a pull model backup is under the control of whatever third +party connects to the NBD export). The job is ended with B. + +=3Ditem B I [I] + +Output XML describing the backup job I. The default for I is +0, which works as long as there are no parallel jobs; it is also +possible to use the positive id printed by B on success. + +=3Ditem B I [I] + +End the current backup job I. The default for I is 0, which +works as long as there are no parallel jobs; it is also possible to +use the positive id printed by B on success. + =3Ditem B I [I<--inactive>] Print a table showing the brief information of all virtual interfaces --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list