def backup(self): if self.dry_run: self.dryrun() return xb_cfg = self.config["xtrabackup"] backup_directory = self.target_directory tmpdir = util.evaluate_tmpdir(xb_cfg["tmpdir"], backup_directory) # innobackupex --tmpdir does not affect xtrabackup util.add_xtrabackup_defaults(self.defaults_path, tmpdir=tmpdir) args = util.build_xb_args(xb_cfg, backup_directory, self.defaults_path) util.execute_pre_command(xb_cfg["pre-command"], backup_directory=backup_directory) stderr = self.open_xb_logfile() try: stdout = self.open_xb_stdout() exc = None try: try: util.run_xtrabackup(args, stdout, stderr) except Exception, exc: LOG.info("!! %s", exc) for line in open(join(self.target_directory, "xtrabackup.log"), "r"): LOG.error(" ! %s", line.rstrip()) raise finally: try: stdout.close() except IOError, e: LOG.error("Error when closing %s: %s", stdout.name, e) if exc is None: raise finally: stderr.close() if xb_cfg["apply-logs"]: util.apply_xtrabackup_logfile(xb_cfg, args[-1])
def dryrun(self, binary_xtrabackup): """Perform test backup""" from subprocess import Popen, list2cmdline, PIPE, STDOUT xb_cfg = self.config["xtrabackup"] args = util.build_xb_args(xb_cfg, self.target_directory, self.defaults_path, binary_xtrabackup) LOG.info("* xtrabackup command: %s", list2cmdline(args)) args = [ "xtrabackup", "--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 xtrabackup binary") stdout = process.stdout.read() process.wait() # Note: xtrabackup --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))
def dryrun(self, binary_xtrabackup): """Perform test backup""" from subprocess import Popen, list2cmdline, PIPE, STDOUT xb_cfg = self.config["xtrabackup"] args = util.build_xb_args( xb_cfg, self.target_directory, self.defaults_path, binary_xtrabackup ) LOG.info("* xtrabackup command: %s", list2cmdline(args)) args = ["xtrabackup", "--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 xtrabackup binary") stdout = process.stdout.read() process.wait() # Note: xtrabackup --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))
def dryrun(self): from subprocess import Popen, list2cmdline, PIPE, STDOUT xb_cfg = self.config["xtrabackup"] args = util.build_xb_args(xb_cfg, self.target_directory, self.defaults_path) LOG.info("* xtrabackup command: %s", list2cmdline(args)) args = ["xtrabackup", "--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, exc: raise BackupError("Failed to find xtrabackup binary")
def dryrun(self): from subprocess import Popen, list2cmdline, PIPE, STDOUT xb_cfg = self.config['xtrabackup'] args = util.build_xb_args(xb_cfg, self.target_directory, self.defaults_path) LOG.info("* xtrabackup command: %s", list2cmdline(args)) args = [ 'xtrabackup', '--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, exc: raise BackupError("Failed to find xtrabackup binary")
def backup(self): """Perform Backup""" xtrabackup_version = util.xtrabackup_version() binary_xtrabackup = False if LooseVersion(xtrabackup_version) > LooseVersion("8.0.0"): LOG.debug("Use xtrabackup without innobackupex ") binary_xtrabackup = True if self.dry_run: self.dryrun(binary_xtrabackup) return xb_cfg = self.config["xtrabackup"] backup_directory = self.target_directory tmpdir = util.evaluate_tmpdir(xb_cfg["tmpdir"], backup_directory) # innobackupex --tmpdir does not affect xtrabackup util.add_xtrabackup_defaults(self.defaults_path, tmpdir=tmpdir) args = util.build_xb_args(xb_cfg, backup_directory, self.defaults_path, binary_xtrabackup) util.execute_pre_command(xb_cfg["pre-command"], backup_directory=backup_directory) stderr = self.open_xb_logfile() try: stdout = self.open_xb_stdout() exc = None try: try: util.run_xtrabackup(args, stdout, stderr) except Exception as exc: LOG.info("!! %s", exc) for line in open( join(self.target_directory, "xtrabackup.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 xb_cfg["apply-logs"]: util.apply_xtrabackup_logfile(xb_cfg, backup_directory, binary_xtrabackup)
def backup(self): """Perform Backup""" xtrabackup_version = util.xtrabackup_version() binary_xtrabackup = False if LooseVersion(xtrabackup_version) > LooseVersion("8.0.0"): LOG.debug("Use xtrabackup without innobackupex ") binary_xtrabackup = True if self.dry_run: self.dryrun(binary_xtrabackup) return xb_cfg = self.config["xtrabackup"] backup_directory = self.target_directory tmpdir = util.evaluate_tmpdir(xb_cfg["tmpdir"], backup_directory) # innobackupex --tmpdir does not affect xtrabackup util.add_xtrabackup_defaults(self.defaults_path, tmpdir=tmpdir) args = util.build_xb_args(xb_cfg, backup_directory, self.defaults_path, binary_xtrabackup) util.execute_pre_command(xb_cfg["pre-command"], backup_directory=backup_directory) stderr = self.open_xb_logfile() try: stdout = self.open_xb_stdout() exc = None try: try: util.run_xtrabackup(args, stdout, stderr) except Exception as exc: LOG.info("!! %s", exc) for line in open(join(self.target_directory, "xtrabackup.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 xb_cfg["apply-logs"]: util.apply_xtrabackup_logfile(xb_cfg, backup_directory, binary_xtrabackup)
def backup(self): """Perform Backup""" util.xtrabackup_version() if self.dry_run: self.dryrun() return xb_cfg = self.config['xtrabackup'] backup_directory = self.target_directory tmpdir = util.evaluate_tmpdir(xb_cfg['tmpdir'], backup_directory) # innobackupex --tmpdir does not affect xtrabackup util.add_xtrabackup_defaults(self.defaults_path, tmpdir=tmpdir) args = util.build_xb_args(xb_cfg, backup_directory, self.defaults_path) util.execute_pre_command(xb_cfg['pre-command'], backup_directory=backup_directory) stderr = self.open_xb_logfile() try: stdout = self.open_xb_stdout() exc = None try: try: util.run_xtrabackup(args, stdout, stderr) except Exception as exc: LOG.info("!! %s", exc) for line in open( join(self.target_directory, 'xtrabackup.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 xb_cfg['apply-logs']: util.apply_xtrabackup_logfile(xb_cfg, args[-1])