You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

152 lines
3.9 KiB

  1. /*
  2. * This library is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU Lesser General Public
  4. * License as published by the Free Software Foundation; either
  5. * version 2.1 of the License, or (at your option) any later version.
  6. *
  7. * This library is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. * Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public
  13. * License along with this library. If not, see
  14. * <http://www.gnu.org/licenses/>.
  15. */
  16. #include <config.h>
  17. #include "virsh-backup.h"
  18. #include "virsh-util.h"
  19. #include "internal.h"
  20. #include "virfile.h"
  21. /*
  22. * "backup-begin" command
  23. */
  24. static const vshCmdInfo info_backup_begin[] = {
  25. {.name = "help",
  26. .data = N_("Start a disk backup of a live domain")
  27. },
  28. {.name = "desc",
  29. .data = N_("Use XML to start a full or incremental disk backup of a live "
  30. "domain, optionally creating a checkpoint")
  31. },
  32. {.name = NULL}
  33. };
  34. static const vshCmdOptDef opts_backup_begin[] = {
  35. VIRSH_COMMON_OPT_DOMAIN_FULL(0),
  36. {.name = "backupxml",
  37. .type = VSH_OT_STRING,
  38. .help = N_("domain backup XML"),
  39. },
  40. {.name = "checkpointxml",
  41. .type = VSH_OT_STRING,
  42. .help = N_("domain checkpoint XML"),
  43. },
  44. {.name = "reuse-external",
  45. .type = VSH_OT_BOOL,
  46. .help = N_("reuse files provided by caller"),
  47. },
  48. {.name = NULL}
  49. };
  50. static bool
  51. cmdBackupBegin(vshControl *ctl,
  52. const vshCmd *cmd)
  53. {
  54. g_autoptr(virshDomain) dom = NULL;
  55. const char *backup_from = NULL;
  56. g_autofree char *backup_buffer = NULL;
  57. const char *check_from = NULL;
  58. g_autofree char *check_buffer = NULL;
  59. unsigned int flags = 0;
  60. if (vshCommandOptBool(cmd, "reuse-external"))
  61. flags |= VIR_DOMAIN_BACKUP_BEGIN_REUSE_EXTERNAL;
  62. if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
  63. return false;
  64. if (vshCommandOptStringReq(ctl, cmd, "backupxml", &backup_from) < 0)
  65. return false;
  66. if (!backup_from) {
  67. backup_buffer = g_strdup("<domainbackup/>");
  68. } else {
  69. if (virFileReadAll(backup_from, VSH_MAX_XML_FILE, &backup_buffer) < 0) {
  70. vshSaveLibvirtError();
  71. return false;
  72. }
  73. }
  74. if (vshCommandOptStringReq(ctl, cmd, "checkpointxml", &check_from) < 0)
  75. return false;
  76. if (check_from) {
  77. if (virFileReadAll(check_from, VSH_MAX_XML_FILE, &check_buffer) < 0) {
  78. vshSaveLibvirtError();
  79. return false;
  80. }
  81. }
  82. if (virDomainBackupBegin(dom, backup_buffer, check_buffer, flags) < 0)
  83. return false;
  84. vshPrint(ctl, _("Backup started\n"));
  85. return true;
  86. }
  87. /*
  88. * "backup-dumpxml" command
  89. */
  90. static const vshCmdInfo info_backup_dumpxml[] = {
  91. {.name = "help",
  92. .data = N_("Dump XML for an ongoing domain block backup job")
  93. },
  94. {.name = "desc",
  95. .data = N_("Backup Dump XML")
  96. },
  97. {.name = NULL}
  98. };
  99. static const vshCmdOptDef opts_backup_dumpxml[] = {
  100. VIRSH_COMMON_OPT_DOMAIN_FULL(0),
  101. {.name = NULL}
  102. };
  103. static bool
  104. cmdBackupDumpXML(vshControl *ctl,
  105. const vshCmd *cmd)
  106. {
  107. g_autoptr(virshDomain) dom = NULL;
  108. g_autofree char *xml = NULL;
  109. if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
  110. return false;
  111. if (!(xml = virDomainBackupGetXMLDesc(dom, 0)))
  112. return false;
  113. vshPrint(ctl, "%s", xml);
  114. return true;
  115. }
  116. const vshCmdDef backupCmds[] = {
  117. {.name = "backup-begin",
  118. .handler = cmdBackupBegin,
  119. .opts = opts_backup_begin,
  120. .info = info_backup_begin,
  121. .flags = 0
  122. },
  123. {.name = "backup-dumpxml",
  124. .handler = cmdBackupDumpXML,
  125. .opts = opts_backup_dumpxml,
  126. .info = info_backup_dumpxml,
  127. .flags = 0
  128. },
  129. {.name = NULL}
  130. };