示例#1
0
def exec_diagnose(servers, errors_list):
    """
    Diagnostic command: gathers information from backup server
    and from all the configured servers.

    Gathered information should be used for support and problems detection

    :param dict(str,barman.server.Server) servers: list of configured servers
    :param list errors_list: list of global errors
    """
    # global section. info about barman server
    diagnosis = {"global": {}, "servers": {}}
    # barman global config
    diagnosis["global"]["config"] = dict(barman.__config__._global_config)
    diagnosis["global"]["config"]["errors_list"] = errors_list
    try:
        command = fs.UnixLocalCommand()
        # basic system info
        diagnosis["global"]["system_info"] = command.get_system_info()
    except CommandFailedException as e:
        diagnosis["global"]["system_info"] = {"error": repr(e)}
    diagnosis["global"]["system_info"]["barman_ver"] = barman.__version__
    diagnosis["global"]["system_info"]["timestamp"] = datetime.datetime.now()
    # per server section
    for name in sorted(servers):
        server = servers[name]
        if server is None:
            output.error("Unknown server '%s'" % name)
            continue
        # server configuration
        diagnosis["servers"][name] = {}
        diagnosis["servers"][name]["config"] = vars(server.config)
        del diagnosis["servers"][name]["config"]["config"]
        # server system info
        if server.config.ssh_command:
            try:
                command = fs.UnixRemoteCommand(
                    ssh_command=server.config.ssh_command, path=server.path)
                diagnosis["servers"][name][
                    "system_info"] = command.get_system_info()
            except FsOperationFailed:
                pass
        # barman status information for the server
        diagnosis["servers"][name]["status"] = server.get_remote_status()
        # backup list
        backups = server.get_available_backups(BackupInfo.STATUS_ALL)
        diagnosis["servers"][name]["backups"] = backups
        # wal status
        diagnosis["servers"][name]["wals"] = {
            "last_archived_wal_per_timeline":
            server.backup_manager.get_latest_archived_wals_info(),
        }
        # Release any PostgreSQL resource
        server.close()
    output.info(json.dumps(diagnosis,
                           cls=BarmanEncoder,
                           indent=4,
                           sort_keys=True),
                log=False)
示例#2
0
def exec_diagnose(servers, errors_list):
    """
    Diagnostic command: gathers information from backup server
    and from all the configured servers.

    Gathered information should be used for support and problems detection

    :param dict(str,barman.server.Server) servers: list of configured servers
    :param list errors_list: list of global errors
    """
    # global section. info about barman server
    diagnosis = {'global': {}, 'servers': {}}
    # barman global config
    diagnosis['global']['config'] = dict(barman.__config__._global_config)
    diagnosis['global']['config']['errors_list'] = errors_list
    command = fs.UnixLocalCommand()
    # basic system info
    diagnosis['global']['system_info'] = command.get_system_info()
    diagnosis['global']['system_info']['barman_ver'] = barman.__version__
    # per server section
    for name in sorted(servers):
        server = servers[name]
        if server is None:
            output.error("Unknown server '%s'" % name)
            continue
        # server configuration
        diagnosis['servers'][name] = {}
        diagnosis['servers'][name]['config'] = vars(server.config)
        del diagnosis['servers'][name]['config']['config']
        # server system info
        if server.config.ssh_command:
            try:
                command = fs.UnixRemoteCommand(
                    ssh_command=server.config.ssh_command, path=server.path)
                diagnosis['servers'][name]['system_info'] = (
                    command.get_system_info())
            except FsOperationFailed:
                pass
        # barman statuts information for the server
        diagnosis['servers'][name]['status'] = server.get_remote_status()
        # backup list
        backups = server.get_available_backups(BackupInfo.STATUS_ALL)
        diagnosis['servers'][name]['backups'] = backups
        # wal status
        diagnosis['servers'][name]['wals'] = {
            'last_archived_wal_per_timeline':
            server.backup_manager.get_latest_archived_wals_info(),
        }
        # Release any PostgreSQL resource
        server.close()
    output.info(
        json.dumps(diagnosis,
                   sys.stdout,
                   cls=BarmanEncoder,
                   indent=4,
                   sort_keys=True))
示例#3
0
def exec_diagnose(servers, errors_list):
    """
    Diagnostic command: gathers information from backup server
    and from all the configured servers.

    Gathered information should be used for support and problems detection

    :param dict(str,barman.server.Server) servers: list of configured servers
    :param list errors_list: list of global errors
    """
    # global section. info about barman server
    diagnosis = {"global": {}, "servers": {}}
    # barman global config
    diagnosis["global"]["config"] = dict(barman.__config__._global_config)
    diagnosis["global"]["config"]["errors_list"] = errors_list
    try:
        command = fs.UnixLocalCommand()
        # basic system info
        diagnosis["global"]["system_info"] = command.get_system_info()
    except CommandFailedException as e:
        diagnosis["global"]["system_info"] = {"error": repr(e)}
    diagnosis["global"]["system_info"]["barman_ver"] = barman.__version__
    diagnosis["global"]["system_info"]["timestamp"] = datetime.datetime.now(
        tz=tz.tzlocal()
    )
    # per server section
    for name in sorted(servers):
        server = servers[name]
        if server is None:
            output.error("Unknown server '%s'" % name)
            continue
        # server configuration
        diagnosis["servers"][name] = {}
        diagnosis["servers"][name]["config"] = vars(server.config)
        if "config" in diagnosis["servers"][name]["config"]:
            del diagnosis["servers"][name]["config"]["config"]
        # server system info
        if server.config.ssh_command:
            try:
                command = fs.UnixRemoteCommand(
                    ssh_command=server.config.ssh_command, path=server.path
                )
                diagnosis["servers"][name]["system_info"] = command.get_system_info()
            except FsOperationFailed:
                pass
        # barman status information for the server
        diagnosis["servers"][name]["status"] = server.get_remote_status()
        # backup list
        backups = server.get_available_backups(BackupInfo.STATUS_ALL)
        # update date format for each backup begin_time and end_time and ensure local timezone.
        # This code is a duplicate from BackupInfo.to_json()
        # This should be temporary to keep original behavior for other usage.
        for key in backups.keys():
            data = backups[key].to_dict()
            if data.get("tablespaces") is not None:
                data["tablespaces"] = [list(item) for item in data["tablespaces"]]
            if data.get("begin_time") is not None:
                data["begin_time"] = data["begin_time"].astimezone(tz=tz.tzlocal())
            if data.get("end_time") is not None:
                data["end_time"] = data["end_time"].astimezone(tz=tz.tzlocal())
            backups[key] = data

        diagnosis["servers"][name]["backups"] = backups
        # wal status
        diagnosis["servers"][name]["wals"] = {
            "last_archived_wal_per_timeline": server.backup_manager.get_latest_archived_wals_info(),
        }
        # Release any PostgreSQL resource
        server.close()
    output.info(
        json.dumps(diagnosis, cls=BarmanEncoderV2, indent=4, sort_keys=True), log=False
    )