barman.cli module#

This module implements the interface with the command line and the logger.

class barman.cli.OrderedHelpFormatter(prog, indent_increment=2, max_help_position=24, width=None)View on GitHub#

Bases: HelpFormatter

_format_usage(usage, actions, groups, prefix)View on GitHub#
barman.cli.archive_wal(args)View on GitHub#

Execute maintenance operations on WAL files for a given server. This command processes any incoming WAL files for the server and archives them along the catalogue.

barman.cli.argument(*name_or_flags, **kwargs)View on GitHub#

Convenience function to properly format arguments to pass to the command decorator.

barman.cli.backup(args)View on GitHub#

Perform a full backup for the given server (supports ‘all’)

barman.cli.backup_completer(prefix, parsed_args, **kwargs)View on GitHub#
barman.cli.check(args)View on GitHub#

Check if the server configuration is working.

This command returns success if every checks pass, or failure if any of these fails

barman.cli.check_backup(args)View on GitHub#

Make sure that all the required WAL files to check the consistency of a physical backup (that is, from the beginning to the end of the full backup) are correctly archived. This command is automatically invoked by the cron command and at the end of every backup operation.

barman.cli.check_target_action(value)View on GitHub#

Check the target action option

Parameters:

value – str containing the value to check

barman.cli.check_wal_archive(args)View on GitHub#

Check the WAL archive can be safely used for a new server.

This will fail if there are any existing WALs in the archive. If the –timeline option is used then any WALs on earlier timelines than that specified will not cause the check to fail.

barman.cli.command(args=None, parent=_SubParsersAction(option_strings=[], dest='command', nargs='A...', const=None, default=None, type=None, choices={'help': ArgumentParser(prog='sphinx-build help', usage=None, description='\n    show this help message and exit\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'list-servers': ArgumentParser(prog='sphinx-build list-servers', usage=None, description='\n    List available servers, with useful information\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'list-server': ArgumentParser(prog='sphinx-build list-servers', usage=None, description='\n    List available servers, with useful information\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'cron': ArgumentParser(prog='sphinx-build cron', usage=None, description='\n    Run maintenance tasks (global command)\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'lock-directory-cleanup': ArgumentParser(prog='sphinx-build lock-directory-cleanup', usage=None, description='\n    Cleanup command for the lock directory, takes care of leftover lock files.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'backup': ArgumentParser(prog='sphinx-build backup', usage=None, description="\n    Perform a full backup for the given server (supports 'all')\n    ", formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'list-backups': ArgumentParser(prog='sphinx-build list-backups', usage=None, description="\n    List available backups for the given server (supports 'all')\n    ", formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'list-backup': ArgumentParser(prog='sphinx-build list-backups', usage=None, description="\n    List available backups for the given server (supports 'all')\n    ", formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'status': ArgumentParser(prog='sphinx-build status', usage=None, description='\n    Shows live information and status of the PostgreSQL server\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'replication-status': ArgumentParser(prog='sphinx-build replication-status', usage=None, description='\n    Shows live information and status of any streaming client\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'rebuild-xlogdb': ArgumentParser(prog='sphinx-build rebuild-xlogdb', usage=None, description='\n    Rebuild the WAL file database guessing it from the disk content.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'restore': ArgumentParser(prog='sphinx-build restore', usage=None, description='\n    Restore a server at a given time, name, LSN or xid\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'recover': ArgumentParser(prog='sphinx-build restore', usage=None, description='\n    Restore a server at a given time, name, LSN or xid\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'show-servers': ArgumentParser(prog='sphinx-build show-servers', usage=None, description='\n    Show all configuration parameters for the specified servers\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'show-server': ArgumentParser(prog='sphinx-build show-servers', usage=None, description='\n    Show all configuration parameters for the specified servers\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'switch-wal': ArgumentParser(prog='sphinx-build switch-wal', usage=None, description='\n    Execute the switch-wal command on the target server\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'switch-xlog': ArgumentParser(prog='sphinx-build switch-wal', usage=None, description='\n    Execute the switch-wal command on the target server\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'check': ArgumentParser(prog='sphinx-build check', usage=None, description='\n    Check if the server configuration is working.\n\n    This command returns success if every checks pass, \n    or failure if any of these fails\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'diagnose': ArgumentParser(prog='sphinx-build diagnose', usage=None, description='\n    Diagnostic command (for support and problems detection purpose)\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'sync-info': ArgumentParser(prog='sphinx-build sync-info', usage=None, description='\n    Output the internal synchronisation status.\n    Used to sync_backup with a passive node\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'sync-backup': ArgumentParser(prog='sphinx-build sync-backup', usage=None, description='\n    Command that synchronises a backup from a master to a passive node\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'sync-wals': ArgumentParser(prog='sphinx-build sync-wals', usage=None, description='\n    Command that synchronises WAL files from a master to a passive node\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'show-backup': ArgumentParser(prog='sphinx-build show-backup', usage=None, description='\n    This method shows a single backup information\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'show-backups': ArgumentParser(prog='sphinx-build show-backup', usage=None, description='\n    This method shows a single backup information\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'list-files': ArgumentParser(prog='sphinx-build list-files', usage=None, description='\n    List all the files for a single backup\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'delete': ArgumentParser(prog='sphinx-build delete', usage=None, description='\n    Delete a backup\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'get-wal': ArgumentParser(prog='sphinx-build get-wal', usage=None, description='\n    Retrieve WAL_NAME file from SERVER_NAME archive.\n    The content will be streamed on standard output unless\n    the --output-directory option is specified.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'put-wal': ArgumentParser(prog='sphinx-build put-wal', usage=None, description='\n    Receive a WAL file from SERVER_NAME and securely store it in the incoming\n    directory. The file will be read from standard input in tar format.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'archive-wal': ArgumentParser(prog='sphinx-build archive-wal', usage=None, description='\n    Execute maintenance operations on WAL files for a given server.\n    This command processes any incoming WAL files for the server\n    and archives them along the catalogue.\n\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'receive-wal': ArgumentParser(prog='sphinx-build receive-wal', usage=None, description='\n    Start a receive-wal process.\n    The process uses the streaming protocol to receive WAL files\n    from the PostgreSQL server.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'check-backup': ArgumentParser(prog='sphinx-build check-backup', usage=None, description='\n    Make sure that all the required WAL files to check\n    the consistency of a physical backup (that is, from the\n    beginning to the end of the full backup) are correctly\n    archived. This command is automatically invoked by the\n    cron command and at the end of every backup operation.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'verify-backup': ArgumentParser(prog='sphinx-build verify-backup', usage=None, description='\n    verify a backup for the given server and backup id\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'verify': ArgumentParser(prog='sphinx-build verify-backup', usage=None, description='\n    verify a backup for the given server and backup id\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'generate-manifest': ArgumentParser(prog='sphinx-build generate-manifest', usage=None, description='\n    Generate a manifest-backup for the given server and backup id\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'keep': ArgumentParser(prog='sphinx-build keep', usage=None, description='\n    Tag the specified backup so that it will never be deleted\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'check-wal-archive': ArgumentParser(prog='sphinx-build check-wal-archive', usage=None, description='\n    Check the WAL archive can be safely used for a new server.\n\n    This will fail if there are any existing WALs in the archive.\n    If the --timeline option is used then any WALs on earlier timelines\n    than that specified will not cause the check to fail.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'config-switch': ArgumentParser(prog='sphinx-build config-switch', usage=None, description='\n    Change the active configuration for a server by applying a named model on\n    top of it, or by resetting the active model.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True), 'config-update': ArgumentParser(prog='sphinx-build config-update', usage=None, description='\n    Receives a set of configuration changes in json format and applies them.\n    ', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)}, required=False, help=None, metavar=None), cmd_aliases=None)View on GitHub#

Decorator to define a new subcommand in a sanity-preserving way. The function will be stored in the func variable when the parser parses arguments so that it can be called directly like so:

args = cli.parse_args()
args.func(args)
Usage example::

@command([argument(“-d”, help=”Enable debug mode”, action=”store_true”)]) def command(args):

print(args)

Then on the command line::

$ python cli.py command -d

barman.cli.config_switch(args)View on GitHub#

Change the active configuration for a server by applying a named model on top of it, or by resetting the active model.

barman.cli.config_update(args)View on GitHub#

Receives a set of configuration changes in json format and applies them.

barman.cli.cron(args)View on GitHub#

Run maintenance tasks (global command)

barman.cli.delete(args)View on GitHub#

Delete a backup

barman.cli.diagnose(args=None)View on GitHub#

Diagnostic command (for support and problems detection purpose)

barman.cli.generate_manifest(args)View on GitHub#

Generate a manifest-backup for the given server and backup id

barman.cli.get_model(args, on_error_stop=True)View on GitHub#

Get a single model retrieving its configuration (wraps get_models_list()).

Warning

This function modifies the args parameter.

Parameters:
  • args – an argparse.Namespace containing a single model_name parameter.

  • on_error_stop – stop if an error is found.

Returns:

a ModelConfig or None if the required model is unknown and on_error_stop is False.

barman.cli.get_models_list(args=None)View on GitHub#

Get the model list from the configuration.

If the args parameter is None returns all defined servers.

Parameters:

args – an argparse.Namespace containing a list model_name parameter.

Returns:

a dict – each key is a model name, and its value the corresponding ModelConfig instance.

barman.cli.get_server(args, skip_inactive=True, skip_disabled=False, skip_passive=False, inactive_is_error=False, disabled_is_error=True, on_error_stop=True, suppress_error=False, wal_streaming=False)View on GitHub#

Get a single server retrieving its configuration (wraps get_server_list())

Returns a Server object or None if the required server is unknown and on_error_stop is False.

WARNING: this function modifies the ‘args’ parameter

Parameters:
  • args – an argparse namespace containing a single server_name parameter WARNING: the function modifies the content of this parameter

  • skip_inactive (bool) – do nothing if the server is inactive

  • skip_disabled (bool) – do nothing if the server is disabled

  • skip_passive (bool) – do nothing if the server is passive

  • inactive_is_error (bool) – treat inactive server as error

  • on_error_stop (bool) – stop if an error is found

  • suppress_error (bool) – suppress display of errors (e.g. diagnose)

  • wal_streaming (bool) – create the barman.server.Server using WAL streaming conninfo (if available in the configuration)

Return type:

Server|None

barman.cli.get_server_list(args=None, skip_inactive=False, skip_disabled=False, skip_passive=False, on_error_stop=True, suppress_error=False, wal_streaming=False)View on GitHub#

Get the server list from the configuration

If args the parameter is None or arg.server_name is [‘all’] returns all defined servers

Parameters:
  • args – an argparse namespace containing a list server_name parameter

  • skip_inactive (bool) – skip inactive servers when ‘all’ is required

  • skip_disabled (bool) – skip disabled servers when ‘all’ is required

  • skip_passive (bool) – skip passive servers when ‘all’ is required

  • on_error_stop (bool) – stop if an error is found

  • suppress_error (bool) – suppress display of errors (e.g. diagnose)

  • wal_streaming (bool) – create barman.server.Server objects using WAL streaming conninfo (if available in the configuration)

Return type:

dict[str,Server]

barman.cli.get_wal(args)View on GitHub#

Retrieve WAL_NAME file from SERVER_NAME archive. The content will be streamed on standard output unless the –output-directory option is specified.

barman.cli.global_config(args)View on GitHub#

Set the configuration file

barman.cli.help(args=None)View on GitHub#

show this help message and exit

barman.cli.keep(args)View on GitHub#

Tag the specified backup so that it will never be deleted

barman.cli.list_backups(args)View on GitHub#

List available backups for the given server (supports ‘all’)

barman.cli.list_files(args)View on GitHub#

List all the files for a single backup

barman.cli.list_servers(args)View on GitHub#

List available servers, with useful information

barman.cli.lock_directory_cleanup(args=None)View on GitHub#

Cleanup command for the lock directory, takes care of leftover lock files.

barman.cli.main()View on GitHub#

The main method of Barman

barman.cli.manage_model_command(model, name=None)View on GitHub#

Standard and consistent method for managing model errors within a model command execution.

Parameters:
  • modelModelConfig to be checked for errors.

  • name – name of the model.

Returns:

True if the command has to be executed with this model.

barman.cli.manage_server_command(server, name=None, inactive_is_error=False, disabled_is_error=True, skip_inactive=True, skip_disabled=True, suppress_error=False)View on GitHub#

Standard and consistent method for managing server errors within a server command execution. By default, suggests to skip any inactive and disabled server; it also emits errors for disabled servers by default.

Returns True if the command has to be executed for this server.

Parameters:
  • server (barman.server.Server) – server to be checked for errors

  • name (str) – name of the server, in a multi-server command

  • inactive_is_error (bool) – treat inactive server as error

  • disabled_is_error (bool) – treat disabled server as error

  • skip_inactive (bool) – skip if inactive

  • skip_disabled (bool) – skip if disabled

Returns:

True if the command has to be executed on this server

Return type:

boolean

barman.cli.parse_backup_id(server, args)View on GitHub#

Parses backup IDs including special words such as latest, oldest, etc.

Exit with error if the backup id doesn’t exist.

Parameters:
  • server (Server) – server object to search for the required backup

  • args – command line arguments namespace

Return type:

barman.infofile.LocalBackupInfo

barman.cli.pretty_args(args)View on GitHub#

Prettify the given argparse namespace to be human readable

Returns:

the human readable content of the namespace

barman.cli.put_wal(args)View on GitHub#

Receive a WAL file from SERVER_NAME and securely store it in the incoming directory. The file will be read from standard input in tar format.

barman.cli.rebuild_xlogdb(args)View on GitHub#

Rebuild the WAL file database guessing it from the disk content.

barman.cli.receive_wal(args)View on GitHub#

Start a receive-wal process. The process uses the streaming protocol to receive WAL files from the PostgreSQL server.

barman.cli.replication_status(args)View on GitHub#

Shows live information and status of any streaming client

barman.cli.restore(args)View on GitHub#

Restore a server at a given time, name, LSN or xid

barman.cli.server_completer(prefix, parsed_args, **kwargs)View on GitHub#
barman.cli.server_completer_all(prefix, parsed_args, **kwargs)View on GitHub#
barman.cli.show_backup(args)View on GitHub#

This method shows a single backup information

barman.cli.show_servers(args)View on GitHub#

Show all configuration parameters for the specified servers

barman.cli.status(args)View on GitHub#

Shows live information and status of the PostgreSQL server

barman.cli.switch_wal(args)View on GitHub#

Execute the switch-wal command on the target server

barman.cli.sync_backup(args)View on GitHub#

Command that synchronises a backup from a master to a passive node

barman.cli.sync_info(args)View on GitHub#

Output the internal synchronisation status. Used to sync_backup with a passive node

barman.cli.sync_wals(args)View on GitHub#

Command that synchronises WAL files from a master to a passive node

barman.cli.verify_backup(args)View on GitHub#

verify a backup for the given server and backup id