Exemple #1
0
    def dryrun(self):
        """Test backup without preformaning backup"""

        mb_cfg = self.config["mariabackup"]
        args = util.build_mb_args(mb_cfg, self.target_directory,
                                  self.defaults_path)
        LOG.info("* mariabackup command: %s", list2cmdline(args))
        args = [
            "mariabackup", "--defaults-file=" + self.defaults_path, "--help"
        ]
        cmdline = list2cmdline(args)
        LOG.info("* Verifying generated config '%s'", self.defaults_path)
        LOG.debug("* Verifying via command: %s", cmdline)
        try:
            process = Popen(args, stdout=PIPE, stderr=STDOUT, close_fds=True)
        except OSError:
            raise BackupError("Failed to find mariabackup binary")
        stdout = process.stdout.read()
        process.wait()
        # Note: mariabackup --help will exit with 1 usually
        if process.returncode != 1:
            LOG.error("! %s failed. Output follows below.", cmdline)
            for line in stdout.splitlines():
                LOG.error("! %s", line)
            raise BackupError("%s exited with failure status [%d]" %
                              (cmdline, process.returncode))
Exemple #2
0
 def backup(self):
     """Perform Backup"""
     util.mariabackup_version()
     if self.dry_run:
         self.dryrun()
         return
     mb_cfg = self.config["mariabackup"]
     backup_directory = self.target_directory
     tmpdir = util.evaluate_tmpdir(mb_cfg["tmpdir"], backup_directory)
     # innobackupex --tmpdir does not affect mariabackup
     util.add_mariabackup_defaults(self.defaults_path, tmpdir=tmpdir)
     args = util.build_mb_args(mb_cfg, backup_directory, self.defaults_path)
     util.execute_pre_command(mb_cfg["pre-command"],
                              backup_directory=backup_directory)
     stderr = self.open_mb_logfile()
     try:
         stdout = self.open_mb_stdout()
         exc = None
         try:
             try:
                 util.run_mariabackup(args, stdout, stderr)
             except Exception as exc:
                 LOG.info("!! %s", exc)
                 for line in open(
                         join(self.target_directory, "mariabackup.log"),
                         "r"):
                     LOG.error("    ! %s", line.rstrip())
                 raise
         finally:
             try:
                 stdout.close()
             except IOError as ex:
                 LOG.error("Error when closing %s: %s", stdout.name, ex)
                 if exc is None:
                     raise
     finally:
         stderr.close()
     if mb_cfg["apply-logs"]:
         util.apply_mariabackup_logfile(mb_cfg, backup_directory)
Exemple #3
0
    def dryrun(self):
        """Test backup without preformaning backup"""
        from subprocess import Popen, list2cmdline, PIPE, STDOUT

        mb_cfg = self.config["mariabackup"]
        args = util.build_mb_args(mb_cfg, self.target_directory, self.defaults_path)
        LOG.info("* mariabackup command: %s", list2cmdline(args))
        args = ["mariabackup", "--defaults-file=" + self.defaults_path, "--help"]
        cmdline = list2cmdline(args)
        LOG.info("* Verifying generated config '%s'", self.defaults_path)
        LOG.debug("* Verifying via command: %s", cmdline)
        try:
            process = Popen(args, stdout=PIPE, stderr=STDOUT, close_fds=True)
        except OSError:
            raise BackupError("Failed to find mariabackup binary")
        stdout = process.stdout.read()
        process.wait()
        # Note: mariabackup --help will exit with 1 usually
        if process.returncode != 1:
            LOG.error("! %s failed. Output follows below.", cmdline)
            for line in stdout.splitlines():
                LOG.error("! %s", line)
            raise BackupError("%s exited with failure status [%d]" % (cmdline, process.returncode))
Exemple #4
0
 def backup(self):
     """Perform Backup"""
     util.mariabackup_version()
     if self.dry_run:
         self.dryrun()
         return
     mb_cfg = self.config["mariabackup"]
     backup_directory = self.target_directory
     tmpdir = util.evaluate_tmpdir(mb_cfg["tmpdir"], backup_directory)
     # innobackupex --tmpdir does not affect mariabackup
     util.add_mariabackup_defaults(self.defaults_path, tmpdir=tmpdir)
     args = util.build_mb_args(mb_cfg, backup_directory, self.defaults_path)
     util.execute_pre_command(mb_cfg["pre-command"], backup_directory=backup_directory)
     stderr = self.open_mb_logfile()
     try:
         stdout = self.open_mb_stdout()
         exc = None
         try:
             try:
                 util.run_mariabackup(args, stdout, stderr)
             except Exception as exc:
                 LOG.info("!! %s", exc)
                 for line in open(join(self.target_directory, "mariabackup.log"), "r"):
                     LOG.error("    ! %s", line.rstrip())
                 raise
         finally:
             try:
                 stdout.close()
             except IOError as ex:
                 LOG.error("Error when closing %s: %s", stdout.name, ex)
                 if exc is None:
                     raise
     finally:
         stderr.close()
     if mb_cfg["apply-logs"]:
         util.apply_mariabackup_logfile(mb_cfg, backup_directory)