---
po/POTFILES.in | 1 +
tools/Makefile.am | 1 +
tools/virsh-backup.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh-backup.h | 29 +++++++++++++++
tools/virsh-util.c | 11 ++++++
tools/virsh-util.h | 3 ++
tools/virsh.c | 2 ++
tools/virsh.h | 1 +
8 files changed, 148 insertions(+)
create mode 100644 tools/virsh-backup.c
create mode 100644 tools/virsh-backup.h
diff --git a/po/POTFILES.in b/po/POTFILES.in
index cb9831e..2f6d594 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -300,6 +300,7 @@ src/xenconfig/xen_xl.c
src/xenconfig/xen_xm.c
tests/virpolkittest.c
tools/libvirt-guests.sh.in
+tools/virsh-backup.c
tools/virsh-console.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 56691c2..7e0283f 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -228,6 +228,7 @@ virsh_SOURCES = \
virsh-snapshot.c virsh-snapshot.h \
virsh-util.c virsh-util.h \
virsh-volume.c virsh-volume.h \
+ virsh-backup.c virsh-backup.h \
$(NULL)
virsh_LDFLAGS = \
diff --git a/tools/virsh-backup.c b/tools/virsh-backup.c
new file mode 100644
index 0000000..0f72444
--- /dev/null
+++ b/tools/virsh-backup.c
@@ -0,0 +1,100 @@
+/*
+ * virsh-backup.c: Commands to manage domain backup
+ *
+ * Copyright (C) 2017 Parallels International GmbH
+ *
+ * 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
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+#include "virsh-backup.h"
+
+#include "internal.h"
+#include "virfile.h"
+#include "viralloc.h"
+#include "virsh-domain.h"
+#include "virsh-util.h"
+
+#define VIRSH_COMMON_OPT_DOMAIN_FULL \
+ VIRSH_COMMON_OPT_DOMAIN(N_("domain name, id or uuid")) \
+
+/*
+ * "backup-create" command
+ */
+static const vshCmdInfo info_backup_create[] = {
+ {.name = "help",
+ .data = N_("Create a backup from XML")
+ },
+ {.name = "desc",
+ .data = N_("Create a disks backup from XML description")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_backup_create[] = {
+ VIRSH_COMMON_OPT_DOMAIN_FULL,
+ {.name = "xmlfile",
+ .type = VSH_OT_STRING,
+ .help = N_("domain backup XML")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdBackupCreate(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom = NULL;
+ bool ret = false;
+ const char *from = NULL;
+ char *buffer = NULL;
+ unsigned int flags = 0;
+ virDomainBackupPtr backup = NULL;
+
+ if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+ goto cleanup;
+
+ if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0)
+ goto cleanup;
+
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
+ vshSaveLibvirtError();
+ goto cleanup;
+ }
+
+ if (!(backup = virDomainBackupCreateXML(dom, buffer, flags)))
+ goto cleanup;
+
+ vshPrint(ctl, _("Domain backup started from '%s'"), from);
+
+ ret = true;
+
+ cleanup:
+ VIR_FREE(buffer);
+ virshDomainFree(dom);
+ virshDomainBackupFree(backup);
+
+ return ret;
+}
+
+const vshCmdDef backupCmds[] = {
+ {.name = "backup-create",
+ .handler = cmdBackupCreate,
+ .opts = opts_backup_create,
+ .info = info_backup_create,
+ .flags = 0
+ },
+ {.name = NULL}
+};
diff --git a/tools/virsh-backup.h b/tools/virsh-backup.h
new file mode 100644
index 0000000..da7ec22
--- /dev/null
+++ b/tools/virsh-backup.h
@@ -0,0 +1,29 @@
+/*
+ * virsh-backup.h: Commands to manage domain backup
+ *
+ * Copyright (C) 2017 Parallels International GmbH
+ *
+ * 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
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIRSH_BACKUP_H
+# define VIRSH_BACKUP_H
+
+# include "virsh.h"
+
+extern const vshCmdDef backupCmds[];
+
+#endif /* VIRSH_BACKUP_H */
diff --git a/tools/virsh-util.c b/tools/virsh-util.c
index 4b86e29..66eb61a 100644
--- a/tools/virsh-util.c
+++ b/tools/virsh-util.c
@@ -175,6 +175,17 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap)
}
+void
+virshDomainBackupFree(virDomainBackupPtr backup)
+{
+ if (!backup)
+ return;
+
+ vshSaveLibvirtHelperError();
+ virDomainBackupFree(backup); /* sc_prohibit_obj_free_apis_in_virsh */
+}
+
+
int
virshDomainGetXMLFromDom(vshControl *ctl,
virDomainPtr dom,
diff --git a/tools/virsh-util.h b/tools/virsh-util.h
index 64cef23..ebbac5d 100644
--- a/tools/virsh-util.h
+++ b/tools/virsh-util.h
@@ -46,6 +46,9 @@ virshDomainFree(virDomainPtr dom);
void
virshDomainSnapshotFree(virDomainSnapshotPtr snap);
+void
+virshDomainBackupFree(virDomainBackupPtr backup);
+
int
virshDomainState(vshControl *ctl,
virDomainPtr dom,
diff --git a/tools/virsh.c b/tools/virsh.c
index 90f8125..f68edc3 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -71,6 +71,7 @@
#include "virsh-secret.h"
#include "virsh-snapshot.h"
#include "virsh-volume.h"
+#include "virsh-backup.h"
/* Gnulib doesn't guarantee SA_SIGINFO support. */
#ifndef SA_SIGINFO
@@ -844,6 +845,7 @@ static const vshCmdGrp cmdGroups[] = {
{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 9e42ef9..d7a192b 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -57,6 +57,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"
--
1.8.3.1