barman.compression module#
This module is responsible to manage the compression features of Barman
- class barman.compression.BZip2Compressor(config, compression, path=None)View on GitHub#
Bases:
CommandCompressor
Predefined compressor with BZip2
- MAGIC = b'BZh'#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- class barman.compression.CommandCompressor(config, compression, path=None)View on GitHub#
Bases:
Compressor
Base class for compressors built on external commands
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- _build_command(pipe_command)View on GitHub#
Build the command string and create the actual Command object
- Parameters:
pipe_command – the command used to compress/decompress
- Return type:
- compress(src, dst)View on GitHub#
Compress using the specific command defined in the subclass
- Parameters:
src – source file to compress
dst – destination of the decompression
- decompress(src, dst)View on GitHub#
Decompress using the specific command defined in the subclass
- Parameters:
src – source file to decompress
dst – destination of the decompression
- class barman.compression.CompressionView on GitHub#
Bases:
object
Abstract class meant to represent compression interface
- _abc_impl = <_abc._abc_data object>#
- abstract property file_extensionView on GitHub#
- Returns:
- abstract get_file_content(filename, archive)View on GitHub#
- Parameters:
filename – str file to search for in the archive (requires its full path within the archive)
archive – str archive path/name without extension
- Returns:
string content
- abstract property nameView on GitHub#
- Returns:
- abstract uncompress(src, dst, exclude=None, include_args=None)View on GitHub#
- Parameters:
src – source file path without compression extension
dst – destination path
exclude – list of filepath in the archive to exclude from the extraction
include_args – list of filepath in the archive to extract.
- Returns:
- validate_dst(dst)View on GitHub#
- validate_src_and_dst(src)View on GitHub#
- class barman.compression.CompressionManager(config, path)View on GitHub#
Bases:
object
- __init__(config, path)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
path – str
- check(compression=None)View on GitHub#
This method returns True if the compression specified in the configuration file is present in the register, otherwise False
- get_compressor(compression)View on GitHub#
Returns a new compressor instance
- Parameters:
compression (str) – Compression name or none
- get_default_compressor()View on GitHub#
Returns a new default compressor instance
- get_wal_file_info(filename)View on GitHub#
Populate a WalFileInfo object taking into account the server configuration.
Set compression to ‘custom’ if no compression is identified and Barman is configured to use custom compression.
- Parameters:
filename (str) – the path of the file to identify
- Return type:
- identify_compression(filename)View on GitHub#
Try to guess the compression algorithm of a file
- class barman.compression.Compressor(config, compression, path=None)View on GitHub#
Bases:
object
Base class for all the compressors
- MAGIC = None#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- abstract compress(src, dst)View on GitHub#
Abstract Method for compression method
- abstract decompress(src, dst)View on GitHub#
Abstract method for decompression method
- classmethod validate(file_start)View on GitHub#
Guess if the first bytes of a file are compatible with the compression implemented by this class
- Parameters:
file_start – a binary string representing the first few bytes of a file
- Return type:
- class barman.compression.CustomCompressor(config, compression, path=None)View on GitHub#
Bases:
CommandCompressor
Custom compressor
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- class barman.compression.GZipCompression(command)View on GitHub#
Bases:
Compression
- __init__(command)View on GitHub#
- Parameters:
command – barman.fs.UnixLocalCommand
- _abc_impl = <_abc._abc_data object>#
- file_extension = 'tar.gz'#
- get_file_content(filename, archive)View on GitHub#
- Parameters:
filename – str file to search for in the archive (requires its full path within the archive)
archive – str archive path/name without extension
- Returns:
string content
- name = 'gzip'#
- uncompress(src, dst, exclude=None, include_args=None)View on GitHub#
- Parameters:
src – source file path without compression extension
dst – destination path
exclude – list of filepath in the archive to exclude from the extraction
include_args – list of filepath in the archive to extract.
- Returns:
- class barman.compression.GZipCompressor(config, compression, path=None)View on GitHub#
Bases:
CommandCompressor
Predefined compressor with GZip
- MAGIC = b'\x1f\x8b\x08'#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- class barman.compression.GZipPgBaseBackupCompressionOption(pg_base_backup_config)View on GitHub#
Bases:
PgBaseBackupCompressionOption
- validate(pg_server_version, remote_status)View on GitHub#
Validate gzip-specific options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- class barman.compression.InternalCompressor(config, compression, path=None)View on GitHub#
Bases:
Compressor
Base class for compressors built on python libraries
- _abc_impl = <_abc._abc_data object>#
- abstract _compressor(dst)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- abstract _decompressor(src)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- compress(src, dst)View on GitHub#
Compress using the object defined in the subclass
- Parameters:
src – source file to compress
dst – destination of the decompression
- decompress(src, dst)View on GitHub#
Decompress using the object defined in the subclass
- Parameters:
src – source file to decompress
dst – destination of the decompression
- class barman.compression.LZ4Compression(command)View on GitHub#
Bases:
Compression
- __init__(command)View on GitHub#
- Parameters:
command – barman.fs.UnixLocalCommand
- _abc_impl = <_abc._abc_data object>#
- file_extension = 'tar.lz4'#
- get_file_content(filename, archive)View on GitHub#
- Parameters:
filename – str file to search for in the archive (requires its full path within the archive)
archive – str archive path/name without extension
- Returns:
string content
- name = 'lz4'#
- uncompress(src, dst, exclude=None, include_args=None)View on GitHub#
- Parameters:
src – source file path without compression extension
dst – destination path
exclude – list of filepath in the archive to exclude from the extraction
include_args – list of filepath in the archive to extract.
- Returns:
- class barman.compression.LZ4Compressor(config, compression, path=None)View on GitHub#
Bases:
InternalCompressor
Predefined compressor with lz4
- MAGIC = b'\x04"M\x18'#
- __init__(config, compression, path=None)View on GitHub#
Constructor. :param config: barman.config.ServerConfig :param compression: str compression name :param path: str|None
- _abc_impl = <_abc._abc_data object>#
- _compressor(dst)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- _decompressor(src)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- class barman.compression.LZ4PgBaseBackupCompressionOption(pg_base_backup_config)View on GitHub#
Bases:
PgBaseBackupCompressionOption
- validate(pg_server_version, remote_status)View on GitHub#
Validate lz4-specific options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- class barman.compression.NoneCompression(command)View on GitHub#
Bases:
Compression
- __init__(command)View on GitHub#
- Parameters:
command – barman.fs.UnixLocalCommand
- _abc_impl = <_abc._abc_data object>#
- file_extension = 'tar'#
- get_file_content(filename, archive)View on GitHub#
- Parameters:
filename – str file to search for in the archive (requires its full path within the archive)
archive – str archive path/name without extension
- Returns:
string content
- name = 'none'#
- uncompress(src, dst, exclude=None, include_args=None)View on GitHub#
- Parameters:
src – source file path without compression extension
dst – destination path
exclude – list of filepath in the archive to exclude from the extraction
include_args – list of filepath in the archive to extract.
- Returns:
- class barman.compression.NonePgBaseBackupCompressionOption(pg_base_backup_config)View on GitHub#
Bases:
PgBaseBackupCompressionOption
- validate(pg_server_version, remote_status)View on GitHub#
Validate none compression specific options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- class barman.compression.PgBaseBackupCompression(pg_basebackup_compression_cfg, pg_basebackup_compression_option, compression)View on GitHub#
Bases:
object
Represents the pg_basebackup compression options and provides functionality required by the backup process which depends on those options. This is a facade that interacts with appropriate classes
- __init__(pg_basebackup_compression_cfg, pg_basebackup_compression_option, compression)View on GitHub#
Constructor for the PgBaseBackupCompression facade that handles base_backup class related.
- Parameters:
PgBaseBackupCompressionConfig (pg_basebackup_compression_cfg) – pg_basebackup compression configuration
PgBaseBackupCompressionOption (pg_basebackup_compression_option)
Compression (compression)
- get_file_content(filename, archive)View on GitHub#
Returns archive specific file content :param filename: str :param archive: str :return: str
- validate(pg_server_version, remote_status)View on GitHub#
Validate pg_basebackup compression options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- with_suffix(basename)View on GitHub#
Append the suffix to the supplied basename.
- Parameters:
basename (str) – The basename (without compression suffix) of the file to be opened.
- class barman.compression.PgBaseBackupCompressionConfig(backup_compression, backup_compression_format, backup_compression_level, backup_compression_location, backup_compression_workers)View on GitHub#
Bases:
object
Should become a dataclass
- __init__(backup_compression, backup_compression_format, backup_compression_level, backup_compression_location, backup_compression_workers)View on GitHub#
- class barman.compression.PgBaseBackupCompressionOption(pg_base_backup_config)View on GitHub#
Bases:
object
This class is in charge of validating pg_basebackup compression options
- __init__(pg_base_backup_config)View on GitHub#
- Parameters:
pg_base_backup_config – PgBaseBackupCompressionConfig
- validate(pg_server_version, remote_status)View on GitHub#
Validate pg_basebackup compression options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- class barman.compression.PigzCompressor(config, compression, path=None)View on GitHub#
Bases:
CommandCompressor
Predefined compressor with Pigz
Note that pigz on-disk is the same as gzip, so the MAGIC value of this class is the same
- MAGIC = b'\x1f\x8b\x08'#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- class barman.compression.PyBZip2Compressor(config, compression, path=None)View on GitHub#
Bases:
InternalCompressor
Predefined compressor with BZip2 Python libraries
- MAGIC = b'BZh'#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- _compressor(name)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- _decompressor(name)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- class barman.compression.PyGZipCompressor(config, compression, path=None)View on GitHub#
Bases:
InternalCompressor
Predefined compressor that uses GZip Python libraries
- MAGIC = b'\x1f\x8b\x08'#
- __init__(config, compression, path=None)View on GitHub#
- Parameters:
config – barman.config.ServerConfig
compression – str compression name
path – str|None
- _abc_impl = <_abc._abc_data object>#
- _compressor(name)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- _decompressor(name)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- class barman.compression.XZCompressor(config, compression, path=None)View on GitHub#
Bases:
InternalCompressor
Predefined compressor with XZ Python library
- MAGIC = b'\xfd7zXZ\x00'#
- _abc_impl = <_abc._abc_data object>#
- _compressor(dst)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- _decompressor(src)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- class barman.compression.ZSTDCompression(command)View on GitHub#
Bases:
Compression
- __init__(command)View on GitHub#
- Parameters:
command – barman.fs.UnixLocalCommand
- _abc_impl = <_abc._abc_data object>#
- file_extension = 'tar.zst'#
- get_file_content(filename, archive)View on GitHub#
- Parameters:
filename – str file to search for in the archive (requires its full path within the archive)
archive – str archive path/name without extension
- Returns:
string content
- name = 'zstd'#
- uncompress(src, dst, exclude=None, include_args=None)View on GitHub#
- Parameters:
src – source file path without compression extension
dst – destination path
exclude – list of filepath in the archive to exclude from the extraction
include_args – list of filepath in the archive to extract.
- Returns:
- class barman.compression.ZSTDCompressor(config, compression, path=None)View on GitHub#
Bases:
InternalCompressor
Predefined compressor with zstd
- MAGIC = b'(\xb5/\xfd'#
- __init__(config, compression, path=None)View on GitHub#
Constructor. :param config: barman.config.ServerConfig :param compression: str compression name :param path: str|None
- _abc_impl = <_abc._abc_data object>#
- _compressor(dst)View on GitHub#
Abstract compressor factory method
- Parameters:
dst – destination file path
- Returns:
a file-like writable compressor object
- _decompressor(src)View on GitHub#
Abstract decompressor factory method
- Parameters:
src – source file path
- Returns:
a file-like readable decompressor object
- class barman.compression.ZSTDPgBaseBackupCompressionOption(pg_base_backup_config)View on GitHub#
Bases:
PgBaseBackupCompressionOption
- validate(pg_server_version, remote_status)View on GitHub#
Validate zstd-specific options.
- Parameters:
int (pg_server_version) – the server for which the compression options should be validated.
remote_status (dict) – the status of the pg_basebackup command
- Return List:
List of Issues (str) or empty list
- barman.compression._try_import_lz4()View on GitHub#
- barman.compression._try_import_zstd()View on GitHub#
- barman.compression.get_pg_basebackup_compression(server)View on GitHub#
Factory method which returns an instantiated PgBaseBackupCompression subclass for the backup_compression option in config for the supplied server.
- Parameters:
server (barman.server.Server) – the server for which the PgBaseBackupCompression should be constructed
:return GZipPgBaseBackupCompression