def backup(self): """Run a MySQL backup""" if self.schema.timestamp is None: self._fast_refresh_schema() mock_env = None if self.dry_run: mock_env = MockEnvironment() mock_env.replace_environment() LOG.info("Running in dry-run mode.") try: if self.config['mysqldump']['stop-slave']: self.client = connect(self.mysql_config['client']) if self.client.show_status('Slave_running', session=None) != 'ON': raise BackupError( "stop-slave enabled, but replication is " "either not configured or the slave is not " "running.") self.config.setdefault('mysql:replication', {}) _stop_slave(self.client, self.config['mysql:replication']) self._backup() finally: if self.config['mysqldump']['stop-slave'] and \ 'mysql:replication' in self.config: _start_slave(self.client, self.config['mysql:replication']) if mock_env: mock_env.restore_environment()
def backup(self): """Run a MySQL backup""" if self.schema.timestamp is None: self._fast_refresh_schema() try: self.client = connect(self.mysql_config["client"]) except Exception as ex: LOG.debug("%s", ex) raise BackupError("Failed connecting to database'") if self.dry_run: self.mock_env = MockEnvironment() self.mock_env.replace_environment() LOG.info("Running in dry-run mode.") status = self.client.show_databases() if not status: raise BackupError("Failed to run 'show databases'") try: if self.config["mysqldump"]["stop-slave"]: slave_status = self.client.show_slave_status() if not slave_status: raise BackupError("stop-slave enabled, but 'show slave " "status' failed") if slave_status and slave_status["slave_sql_running"] != "Yes": raise BackupError("stop-slave enabled, but replication is " "not running") if not self.dry_run: _stop_slave(self.client, self.config) elif self.config["mysqldump"]["bin-log-position"]: self.config["mysql:replication"] = {} repl_cfg = self.config["mysql:replication"] try: master_info = self.client.show_master_status() if master_info: repl_cfg["master_log_file"] = master_info["file"] repl_cfg["master_log_pos"] = master_info["position"] except MySQLError as exc: raise BackupError( "Failed to acquire master status [%d] %s" % exc.args) self._backup() finally: if self.config["mysqldump"][ "stop-slave"] and "mysql:replication" in self.config: _start_slave(self.client, self.config["mysql:replication"]) if self.mock_env: self.mock_env.restore_environment()
def backup(self): """Run a MySQL backup""" if self.schema.timestamp is None: self._fast_refresh_schema() mock_env = None if self.dry_run: mock_env = MockEnvironment() mock_env.replace_environment() LOG.info("Running in dry-run mode.") try: if self.config['mysqldump']['stop-slave']: self.client = connect(self.mysql_config['client']) slave_status = self.client.show_slave_status() if slave_status is None: raise BackupError("stop-slave enabled, but 'show slave " "status' failed") elif slave_status['slave_sql_running'] != 'Yes': raise BackupError("stop-slave enabled, but replication is " "not running") _stop_slave(self.client, self.config) elif self.config['mysqldump']['bin-log-position']: self.config['mysql:replication'] = {} repl_cfg = self.config['mysql:replication'] try: master_info = self.client.show_master_status() if master_info: repl_cfg['master_log_file'] = master_info['file'] repl_cfg['master_log_pos'] = master_info['position'] except MySQLError as exc: raise BackupError( "Failed to acquire master status [%d] %s" % exc.args) self._backup() finally: if self.config['mysqldump']['stop-slave'] and \ 'mysql:replication' in self.config: _start_slave(self.client, self.config['mysql:replication']) if mock_env: mock_env.restore_environment()