当前位置: 首页>>代码示例>>Python>>正文


Python LOG.error方法代码示例

本文整理汇总了Python中twindb_backup.LOG.error方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.error方法的具体用法?Python LOG.error怎么用?Python LOG.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twindb_backup.LOG的用法示例。


在下文中一共展示了LOG.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_connection

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def get_connection(self):
        """
        Connect to MySQL host and yield a connection.

        :return: MySQL connection
        :raise MySQLSourceError: if can't connect to server
        """
        connection = None
        try:
            connection = pymysql.connect(
                host=self.hostname,
                read_default_file=self.defaults_file,
                connect_timeout=self.connect_timeout,
                cursorclass=pymysql.cursors.DictCursor
            )

            yield connection
        except OperationalError:
            LOG.error(
                "Can't connect to MySQL server on %s",
                self.hostname)
            raise MySQLSourceError(
                "Can't connect to MySQL server on %s"
                % self.hostname)
        finally:
            if connection:
                connection.close()
开发者ID:twindb,项目名称:backup,代码行数:29,代码来源:mysql_source.py

示例2: backup_everything

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def backup_everything(run_type, twindb_config, binlogs_only=False):
    """
    Run backup job

    :param run_type: hourly, daily, etc
    :type run_type: str
    :param twindb_config: ConfigParser instance
    :type twindb_config: TwinDBBackupConfig
    :param binlogs_only: If True copy only MySQL binary logs.
    :type binlogs_only: bool
    """
    set_open_files_limit()

    try:
        if not binlogs_only:
            backup_start = time.time()
            backup_files(run_type, twindb_config)
            backup_mysql(run_type, twindb_config)
            backup_binlogs(run_type, twindb_config)
            end = time.time()
            save_measures(backup_start, end)
        else:
            backup_binlogs(run_type, twindb_config)
    except ConfigParser.NoSectionError as err:
        LOG.debug(traceback.format_exc())
        LOG.error(err)
        exit(1)
开发者ID:twindb,项目名称:backup,代码行数:29,代码来源:backup.py

示例3: disable_wsrep_desync

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def disable_wsrep_desync(self):
        """
        Wait till wsrep_local_recv_queue is zero
        and disable wsrep_local_recv_queue then
        """
        max_time = time.time() + 900
        try:
            with self.get_connection() as connection:
                with connection.cursor() as cursor:
                    while time.time() < max_time:
                        cursor.execute("SHOW GLOBAL STATUS LIKE "
                                       "'wsrep_local_recv_queue'")

                        res = {r['Variable_name'].lower(): r['Value'].lower()
                               for r in cursor.fetchall()}

                        if not res.get('wsrep_local_recv_queue'):
                            raise Exception('Unknown status variable '
                                            '"wsrep_local_recv_queue"')

                        if int(res['wsrep_local_recv_queue']) == 0:
                            break

                        time.sleep(1)

                    LOG.debug('Disabling wsrep_desync')
                    cursor.execute("SET GLOBAL wsrep_desync=OFF")
        except pymysql.Error as err:
            LOG.error(err)
开发者ID:twindb,项目名称:backup,代码行数:31,代码来源:mysql_source.py

示例4: _handle_failure_exec

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
 def _handle_failure_exec(self, err, stderr_file):
     """Cleanup on failure exec"""
     LOG.error(err)
     LOG.error('Failed to run xtrabackup. '
               'Check error output in %s', stderr_file.name)
     self.dst.delete(self.get_name())
     exit(1)
开发者ID:twindb,项目名称:backup,代码行数:9,代码来源:mysql_source.py

示例5: get_stream

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def get_stream(self):
        """
        Get a PIPE handler with content of the source
        :return:
        """
        cmd = [
            self._xtrabackup,
            "--defaults-file=%s" % self._connect_info.defaults_file,
            "--stream=xbstream",
            "--host=127.0.0.1",
            "--backup"
        ]
        cmd += ["--target-dir", "."]
        if self.is_galera():
            cmd.append("--galera-info")
            cmd.append("--no-backup-locks")
        if self.incremental:
            cmd += [
                "--incremental-basedir",
                ".",
                "--incremental-lsn=%d" % self._parent_lsn
            ]
        # If this is a Galera node then additional step needs to be taken to
        # prevent the backups from locking up the cluster.
        wsrep_desynced = False
        LOG.debug('Running %s', ' '.join(cmd))
        stderr_file = tempfile.NamedTemporaryFile(delete=False)
        try:
            if self.is_galera():
                wsrep_desynced = self.enable_wsrep_desync()

            LOG.debug('Running %s', ' '.join(cmd))
            proc_xtrabackup = Popen(cmd,
                                    stderr=stderr_file,
                                    stdout=PIPE)

            yield proc_xtrabackup.stdout

            proc_xtrabackup.communicate()
            if proc_xtrabackup.returncode:
                LOG.error('Failed to run xtrabackup. '
                          'Check error output in %s', stderr_file.name)
                try:
                    if LOG.debug_enabled:
                        with open(stderr_file.name) as xb_out:
                            for line in xb_out:
                                print(line, end='', file=sys.stderr)
                except AttributeError:
                    pass
                self.dst.delete(self.get_name())
                exit(1)
            else:
                LOG.debug('Successfully streamed xtrabackup output')
            self._update_backup_info(stderr_file)
        except OSError as err:
            LOG.error('Failed to run %s: %s', cmd, err)
            exit(1)
        finally:
            if wsrep_desynced:
                self.disable_wsrep_desync()
开发者ID:twindb,项目名称:backup,代码行数:62,代码来源:mysql_source.py

示例6: revert_stream

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def revert_stream(self):
        """
        Un-Apply modifier and return output stream.
        The Base modifier does nothing, so it will return the input stream
        without modifications

        :return: output stream handle
        """
        with self._input as input_stream:
            LOG.debug('Running %s', ' '.join(self._unmodifier_cmd))
            proc = Popen(
                self._unmodifier_cmd,
                stdin=input_stream,
                stdout=PIPE,
                stderr=PIPE
            )
            yield proc.stdout

            _, cerr = proc.communicate()
            if proc.returncode:
                msg = '%s exited with non-zero code.' \
                      % ' '.join(self._unmodifier_cmd)
                LOG.error(msg)
                LOG.error(cerr)
                raise ModifierException(msg)
开发者ID:twindb,项目名称:backup,代码行数:27,代码来源:base.py

示例7: backup_mysql

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
 def backup_mysql(self):
     """FLag to backup MySQL or not"""
     try:
         return self.__cfg.getboolean('source', 'backup_mysql')
     except NoOptionError:
         return False
     except NoSectionError as err:
         LOG.error("Section 'source' is mandatory")
         raise ConfigurationError(err)
开发者ID:twindb,项目名称:backup,代码行数:11,代码来源:__init__.py

示例8: restore_mysql

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def restore_mysql(ctx, dst, backup_copy, cache):
    """Restore from mysql backup"""
    LOG.debug('mysql: %r', ctx.obj['twindb_config'])

    if not backup_copy:
        LOG.info('No backup copy specified. Choose one from below:')
        list_available_backups(ctx.obj['twindb_config'])
        exit(1)

    try:
        ensure_empty(dst)

        incomplete_copy = MySQLCopy(
            path=backup_copy
        )
        dst_storage = ctx.obj['twindb_config'].destination(
            backup_source=incomplete_copy.host
        )
        mysql_status = MySQLStatus(dst=dst_storage)

        copies = [
            cp for cp in mysql_status if backup_copy.endswith(cp.name)
        ]
        try:
            copy = copies.pop(0)
        except IndexError:
            raise TwinDBBackupError(
                'Can not find copy %s in MySQL status. '
                'Inspect output of `twindb-backup status` and verify '
                'that correct copy is specified.'
                % backup_copy
            )
        if copies:
            raise TwinDBBackupError(
                'Multiple copies match pattern %s. Make sure you give unique '
                'copy name for restore.'
            )

        if cache:
            restore_from_mysql(
                ctx.obj['twindb_config'],
                copy,
                dst,
                cache=Cache(cache)
            )
        else:
            restore_from_mysql(ctx.obj['twindb_config'], copy, dst)

    except (TwinDBBackupError, CacheException) as err:
        LOG.error(err)
        LOG.debug(traceback.format_exc())
        exit(1)
    except (OSError, IOError) as err:
        LOG.error(err)
        LOG.debug(traceback.format_exc())
        exit(1)
开发者ID:twindb,项目名称:backup,代码行数:58,代码来源:cli.py

示例9: backup_dirs

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
 def backup_dirs(self):
     """Directories to backup"""
     try:
         dirs = self.__cfg.get('source', 'backup_dirs')
         return split(dirs)
     except NoOptionError:
         return []
     except NoSectionError as err:
         LOG.error("Section 'source' is mandatory")
         raise ConfigurationError(err)
开发者ID:twindb,项目名称:backup,代码行数:12,代码来源:__init__.py

示例10: verify_mysql_backup

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def verify_mysql_backup(twindb_config, dst_path, backup_file, hostname=None):
    """
    Restore mysql backup and measure time

    :param hostname:
    :param backup_file:
    :param dst_path:
    :param twindb_config: tool configuration
    :type twindb_config: TwinDBBackupConfig

    """
    dst = twindb_config.destination(backup_source=hostname)
    status = MySQLStatus(dst=dst)
    copy = None

    if backup_file == "latest":
        copy = status.latest_backup
    else:
        for copy in status:
            if backup_file.endswith(copy.key):
                break
    if copy is None:
        return json.dumps({
            'backup_copy': backup_file,
            'restore_time': 0,
            'success': False
        }, indent=4, sort_keys=True)
    start_restore_time = time.time()
    success = True
    tmp_dir = tempfile.mkdtemp()

    try:

        LOG.debug('Verifying backup copy in %s', tmp_dir)
        restore_from_mysql(twindb_config, copy, dst_path, tmp_dir)
        edit_backup_my_cnf(dst_path)

    except (TwinDBBackupError, OSError, IOError) as err:

        LOG.error(err)
        LOG.debug(traceback.format_exc())
        success = False

    finally:

        shutil.rmtree(tmp_dir, ignore_errors=True)

    end_restore_time = time.time()
    restore_time = end_restore_time - start_restore_time
    return json.dumps({
        'backup_copy': copy.key,
        'restore_time': restore_time,
        'success': success
    }, indent=4, sort_keys=True)
开发者ID:twindb,项目名称:backup,代码行数:56,代码来源:verify.py

示例11: share_backup

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def share_backup(ctx, s3_url):
    """Share backup copy for download"""
    if not s3_url:
        LOG.info('No backup copy specified. Choose one from below:')
        list_available_backups(ctx.obj['twindb_config'])
        exit(1)
    try:
        share(ctx.obj['twindb_config'], s3_url)
    except TwinDBBackupError as err:
        LOG.error(err)
        exit(1)
开发者ID:twindb,项目名称:backup,代码行数:13,代码来源:cli.py

示例12: run_command

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def run_command(command, ok_non_zero=False):
    """
    Run shell command locally

    :param command: Command to run
    :type command: list
    :param ok_non_zero: Don't consider non-zero exit code as an error.
    :type ok_non_zero: bool
    :return: file object with stdout as generator to use with ``with``
    """
    try:
        LOG.debug('Running %s', " ".join(command))
        proc = Popen(command, stderr=PIPE, stdout=PIPE)

        yield proc.stdout

        _, cerr = proc.communicate()

        if proc.returncode and not ok_non_zero:
            LOG.error('Command %s exited with error code %d',
                      ' '.join(command),
                      proc.returncode)
            LOG.error(cerr)
            exit(1)
        else:
            LOG.debug('Exited with zero code')

    except OSError as err:
        LOG.error('Failed to run %s',
                  ' '.join(command))
        LOG.error(err)
        exit(1)
开发者ID:twindb,项目名称:backup,代码行数:34,代码来源:util.py

示例13: _load

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def _load(self, status_as_json):
        status = []
        try:
            status_as_obj = json.loads(status_as_json)
        except ValueError:
            raise CorruptedStatus(
                'Could not load status from a bad JSON string %s'
                % (status_as_json, )
            )

        for run_type in INTERVALS:
            for key, value in status_as_obj[run_type].iteritems():

                try:
                    host = key.split('/')[0]
                    file_name = key.split('/')[3]
                    kwargs = {
                        'type': value['type'],
                        'config': self.__serialize_config(value)
                    }
                    keys = [
                        'backup_started',
                        'backup_finished',
                        'binlog',
                        'parent',
                        'lsn',
                        'position',
                        'wsrep_provider_version',
                    ]
                    for copy_key in keys:
                        if copy_key in value:
                            kwargs[copy_key] = value[copy_key]

                    copy = MySQLCopy(
                        host,
                        run_type,
                        file_name,
                        **kwargs
                    )
                    status.append(copy)
                except IndexError as err:
                    LOG.error(err)
                    raise CorruptedStatus('Unexpected key %s' % key)

        return status
开发者ID:twindb,项目名称:backup,代码行数:47,代码来源:mysql_status.py

示例14: _get_config

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
    def _get_config(self, cfg_path):
        """
        Return parsed config

        :param cfg_path: Path to config
        :type cfg_path: str
        :return: Path and config
        :rtype: ConfigParser.ConfigParser
        """
        cfg = ConfigParser.ConfigParser(allow_no_value=True)
        try:
            cmd = "cat %s" % cfg_path
            with self._ssh_client.get_remote_handlers(cmd) as (_, cout, _):
                cfg.readfp(cout)
        except ConfigParser.ParsingError as err:
            LOG.error(err)
            raise
        return cfg
开发者ID:twindb,项目名称:backup,代码行数:20,代码来源:remote_mysql_source.py

示例15: backup

# 需要导入模块: from twindb_backup import LOG [as 别名]
# 或者: from twindb_backup.LOG import error [as 别名]
def backup(ctx, run_type, lock_file, binlogs_only):
    """Run backup job"""
    try:

        run_backup_job(
            ctx.obj['twindb_config'],
            run_type,
            lock_file=lock_file,
            binlogs_only=binlogs_only
        )
    except TwinDBBackupError as err:
        LOG.error(err)
        LOG.debug(traceback.format_exc())
        exit(1)

    except KeyboardInterrupt:
        LOG.info('Exiting...')
        kill_children()
        exit(1)
开发者ID:twindb,项目名称:backup,代码行数:21,代码来源:cli.py


注:本文中的twindb_backup.LOG.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。