本文整理汇总了Python中barman.compression.CompressionManager.get_compressor方法的典型用法代码示例。如果您正苦于以下问题:Python CompressionManager.get_compressor方法的具体用法?Python CompressionManager.get_compressor怎么用?Python CompressionManager.get_compressor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类barman.compression.CompressionManager
的用法示例。
在下文中一共展示了CompressionManager.get_compressor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_compressor_invalid
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
def test_get_compressor_invalid(self):
#prepare mock obj
config_mock = mock.Mock()
# check custom compression method creation
comp_manager = CompressionManager(config_mock)
assert comp_manager.get_compressor("test_compression") is None
示例2: test_get_compressor_bzip2
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
def test_get_compressor_bzip2(self):
#prepare mock obj
config_mock = mock.Mock()
config_mock.compression = "bzip2"
# check custom compression method creation
comp_manager = CompressionManager(config_mock)
assert comp_manager.get_compressor() is not None
示例3: test_get_compressor_custom
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
def test_get_compressor_custom(self):
#prepare mock obj
config_mock = mock.Mock()
config_mock.compression = "custom"
config_mock.custom_compression_filter = "test_custom_compression_filter"
config_mock.custom_decompression_filter = \
"test_custom_decompression_filter"
# check custom compression method creation
comp_manager = CompressionManager(config_mock)
assert comp_manager.get_compressor() is not None
示例4: BackupManager
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
#.........这里部分代码省略.........
Delete a WAL segment, with the given WalFileInfo
:param barman.infofile.WalFileInfo wal_info: the WAL to delete
"""
try:
os.unlink(wal_info.fullpath(self.server))
try:
os.removedirs(os.path.dirname(wal_info.fullpath(self.server)))
except OSError:
# This is not an error condition
# We always try to remove the the trailing directories,
# this means that hashdir is not empty.
pass
except OSError as e:
output.warning('Ignoring deletion of WAL file %s '
'for server %s: %s',
wal_info.name, self.config.name, e)
def check(self, check_strategy):
"""
This function does some checks on the server.
:param CheckStrategy check_strategy: the strategy for the management
of the results of the various checks
"""
# Check compression_setting parameter
if self.config.compression and not self.compression_manager.check():
check_strategy.result(self.config.name,
'compression settings', False)
else:
status = True
try:
self.compression_manager.get_compressor()
except CompressionIncompatibility as field:
check_strategy.result(self.config.name,
'%s setting' % field, False)
status = False
check_strategy.result(self.config.name,
'compression settings', status)
# Failed backups check
failed_backups = self.get_available_backups((BackupInfo.FAILED,))
status = len(failed_backups) == 0
check_strategy.result(
self.config.name,
'failed backups',
status,
'there are %s failed backups' % (len(failed_backups,))
)
# Minimum redundancy checks
no_backups = len(self.get_available_backups())
# Check minimum_redundancy_requirements parameter
if no_backups < int(self.config.minimum_redundancy):
status = False
else:
status = True
check_strategy.result(
self.config.name,
'minimum redundancy requirements', status,
'have %s backups, expected at least %s' % (
no_backups, self.config.minimum_redundancy))
# TODO: Add a check for the existence of ssh and of rsync
示例5: BackupManager
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
#.........这里部分代码省略.........
clashes = self.pg_config_detect_possible_issues(pg_config)
if remote_command:
recovery = rsync.from_file_list(['postgresql.conf', 'postgresql.conf.origin'], tempdir, ':%s' % dest)
shutil.rmtree(tempdir)
yield ""
yield "Your PostgreSQL server has been successfully prepared for recovery!"
yield ""
yield "Please review network and archive related settings in the PostgreSQL"
yield "configuration file before starting the just recovered instance."
yield ""
if clashes:
yield "WARNING: Before starting up the recovered PostgreSQL server,"
yield "please review also the settings of the following configuration"
yield "options as they might interfere with your current recovery attempt:"
yield ""
for name, value in sorted(clashes.items()):
yield " %s = %s" % (name, value)
yield ""
_logger.info("Recovery completed successful.")
def cron(self, verbose):
'''
Executes maintenance operations, such as WAL trashing.
:param verbose: print some information
'''
found = False
compressor = self.compression_manager.get_compressor()
with self.server.xlogdb('a') as fxlogdb:
if verbose:
yield "Processing xlog segments for %s" % self.config.name
available_backups = self.get_available_backups(BackupInfo.STATUS_ALL)
for filename in sorted(glob(os.path.join(self.config.incoming_wals_directory, '*'))):
if not found and not verbose:
yield "Processing xlog segments for %s" % self.config.name
found = True
if not len(available_backups):
msg = "No base backup available. Trashing file %s" % os.path.basename(filename)
yield "\t%s" % msg
_logger.warning(msg)
os.unlink(filename)
continue
# Archive the WAL file
basename, size, time = self.cron_wal_archival(compressor, filename)
# Updates the information of the WAL archive with the latest segement's
fxlogdb.write("%s\t%s\t%s\t%s\n" % (basename, size, time, self.config.compression))
_logger.info('Processed file %s', filename)
yield "\t%s" % os.path.basename(filename)
if not found and verbose:
yield "\tno file found"
# Retention policy management
if self.server.enforce_retention_policies and self.config.retention_policy_mode == 'auto':
available_backups = self.get_available_backups(BackupInfo.STATUS_ALL)
retention_status = self.config.retention_policy.report()
for bid in sorted(retention_status.iterkeys()):
if retention_status[bid] == BackupInfo.OBSOLETE:
_logger.info("Enforcing retention policy: removing backup %s for server %s" % (
bid, self.config.name))
示例6: test_decode_history_file
# 需要导入模块: from barman.compression import CompressionManager [as 别名]
# 或者: from barman.compression.CompressionManager import get_compressor [as 别名]
def test_decode_history_file(self, tmpdir):
compressor = mock.Mock()
# Regular history file
p = tmpdir.join('00000002.history')
p.write('1\t2/83000168\tat restore point "myrp"\n')
wal_info = WalFileInfo.from_file(p.strpath)
result = xlog.HistoryFileData(
tli=2,
parent_tli=1,
reason='at restore point "myrp"',
switchpoint=0x283000168)
assert xlog.decode_history_file(wal_info, compressor) == [result]
assert len(compressor.mock_calls) == 0
# Comments must be skipped
p = tmpdir.join('00000003.history')
p.write('# Comment\n1\t2/83000168\tat restore point "testcomment"\n')
wal_info = WalFileInfo.from_file(p.strpath)
result = xlog.HistoryFileData(
tli=3,
parent_tli=1,
reason='at restore point "testcomment"',
switchpoint=0x283000168)
assert xlog.decode_history_file(wal_info, compressor) == [result]
assert len(compressor.mock_calls) == 0
# History file with comments and empty lines
p = tmpdir.join('00000004.history')
p.write('# Comment\n\n1\t2/83000168\ttesting "testemptyline"\n')
wal_info = WalFileInfo.from_file(p.strpath)
result = xlog.HistoryFileData(
tli=4,
parent_tli=1,
reason='testing "testemptyline"',
switchpoint=0x283000168)
assert xlog.decode_history_file(wal_info, compressor) == [result]
assert len(compressor.mock_calls) == 0
# Test compression handling Fix for bug #66 on github
config_mock = mock.Mock()
config_mock.compression = "gzip"
# check custom compression method creation
comp_manager = CompressionManager(config_mock, None)
u = tmpdir.join('00000005.uncompressed')
p = tmpdir.join('00000005.history')
u.write('1\t2/83000168\tat restore point "myrp"\n')
result = xlog.HistoryFileData(
tli=5,
parent_tli=1,
reason='at restore point "myrp"',
switchpoint=0x283000168)
comp_manager.get_compressor('gzip').compress(u.strpath,
p.strpath)
wal_info = WalFileInfo.from_file(p.strpath)
assert xlog.decode_history_file(wal_info, comp_manager) == [result]
with pytest.raises(barman.exceptions.BadHistoryFileContents):
# Empty file
p.write('')
assert xlog.decode_history_file(wal_info, compressor)
assert len(compressor.mock_calls) == 0
with pytest.raises(barman.exceptions.BadHistoryFileContents):
# Missing field
p.write('1\t2/83000168')
assert xlog.decode_history_file(wal_info, compressor)
assert len(compressor.mock_calls) == 0
with pytest.raises(barman.exceptions.BadHistoryFileContents):
# Unattended field
p.write('1\t2/83000168\tat restore point "myrp"\ttest')
assert xlog.decode_history_file(wal_info, compressor)
assert len(compressor.mock_calls) == 0