mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-25 19:23:00 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
613f6c602c | ||
|
|
4a94c2c9bf | ||
|
|
08843d51d9 | ||
|
|
ea9213cb03 | ||
|
|
1ea4433aa9 | ||
|
|
4c0e2cab78 | ||
|
|
31a2ac914a | ||
|
|
d6ef0df50d | ||
|
|
cc60a71210 | ||
|
|
4cd7556a34 | ||
|
|
b4b1fa939d | ||
|
|
16d7131fb7 | ||
|
|
091d60c226 | ||
|
|
0fbdf8d860 | ||
|
|
192bfe46a9 | ||
|
|
080c3afa0d | ||
|
|
a9a65ebe54 | ||
|
|
616eb6b6da | ||
|
|
00d1dea94e | ||
|
|
127ad1dd1f | ||
|
|
fc58ba5763 | ||
|
|
7e6bee84b0 | ||
|
|
01811e03ba | ||
|
|
9712d00680 | ||
|
|
275e99d0b9 | ||
|
|
b9328e6d42 | ||
|
|
2934d0902c | ||
|
|
1ad43ad4b5 | ||
|
|
32ab17fa46 | ||
|
|
6054ced931 | ||
|
|
1412038ed3 | ||
|
|
fa8bc285c8 | ||
|
|
f256908b27 | ||
|
|
3f78ac4085 | ||
|
|
5f595f7ac3 | ||
|
|
b27e625a77 | ||
|
|
fc2c181b74 | ||
|
|
010b82d6d8 | ||
|
|
aaf3462d17 | ||
|
|
f709125110 | ||
|
|
3512191f3e | ||
|
|
06b5d81baa | ||
|
|
9d71bf916e | ||
|
|
59fe01b56d | ||
|
|
08e358e27f | ||
|
|
ce22d2d302 | ||
|
|
2d08a63e60 | ||
|
|
d96f2239c1 | ||
|
|
67a349ae44 | ||
|
|
dcefded0fa | ||
|
|
1bcdebd1cc | ||
|
|
7a8e0e89dd | ||
|
|
489ae080e5 | ||
|
|
0e3da7be63 |
@@ -24,6 +24,8 @@ clone:
|
||||
steps:
|
||||
- name: build
|
||||
image: alpine:3.13
|
||||
environment:
|
||||
TEST_CONTAINER: true
|
||||
pull: always
|
||||
commands:
|
||||
- scripts/run-full-tests
|
||||
|
||||
@@ -1,3 +1,40 @@
|
||||
1.7.12
|
||||
* #413: Add "log_file" context to command hooks so your scripts can consume the borgmatic log file.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/
|
||||
* #666, #670: Fix error when running the "info" action with the "--match-archives" or "--archive"
|
||||
flags. Also fix the "--match-archives"/"--archive" flags to correctly override the
|
||||
"match_archives" configuration option for the "transfer", "list", "rlist", and "info" actions.
|
||||
* #668: Fix error when running the "prune" action with both "archive_name_format" and "prefix"
|
||||
options set.
|
||||
* #672: Selectively shallow merge certain mappings or sequences when including configuration files.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#shallow-merge
|
||||
* #672: Selectively omit list values when including configuration files. See the documentation for
|
||||
more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#list-merge
|
||||
* #673: View the results of configuration file merging via "validate-borgmatic-config --show" flag.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#debugging-includes
|
||||
* Add optional support for running end-to-end tests and building documentation with rootless Podman
|
||||
instead of Docker.
|
||||
|
||||
1.7.11
|
||||
* #479, #588: BREAKING: Automatically use the "archive_name_format" option to filter which archives
|
||||
get used for borgmatic actions that operate on multiple archives. Override this behavior with the
|
||||
new "match_archives" option in the storage section. This change is "breaking" in that it silently
|
||||
changes which archives get considered for "rlist", "prune", "check", etc. See the documentation
|
||||
for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#archive-naming
|
||||
* #479, #588: The "prefix" options have been deprecated in favor of the new "archive_name_format"
|
||||
auto-matching behavior and the "match_archives" option.
|
||||
* #658: Add "--log-file-format" flag for customizing the log message format. See the documentation
|
||||
for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/inspect-your-backups/#logging-to-file
|
||||
* #662: Fix regression in which the "check_repositories" option failed to match repositories.
|
||||
* #663: Fix regression in which the "transfer" action produced a traceback.
|
||||
* Add spellchecking of source code during test runs.
|
||||
|
||||
1.7.10
|
||||
* #396: When a database command errors, display and log the error message instead of swallowing it.
|
||||
* #501: Optionally error if a source directory does not exist via "source_directories_must_exist"
|
||||
@@ -388,7 +425,7 @@
|
||||
configuration schema descriptions.
|
||||
|
||||
1.5.6
|
||||
* #292: Allow before_backup and similiar hooks to exit with a soft failure without altering the
|
||||
* #292: Allow before_backup and similar hooks to exit with a soft failure without altering the
|
||||
monitoring status on Healthchecks or other providers. Support this by waiting to ping monitoring
|
||||
services with a "start" status until after before_* hooks finish. Failures in before_* hooks
|
||||
still trigger a monitoring "fail" status.
|
||||
@@ -457,7 +494,7 @@
|
||||
* For "list" and "info" actions, show repository names even at verbosity 0.
|
||||
|
||||
1.4.22
|
||||
* #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON ouput.
|
||||
* #276, #285: Disable colored output when "--json" flag is used, so as to produce valid JSON output.
|
||||
* After a backup of a database dump in directory format, properly remove the dump directory.
|
||||
* In "borgmatic --help", don't expand $HOME in listing of default "--config" paths.
|
||||
|
||||
@@ -829,7 +866,7 @@
|
||||
* #77: Skip non-"*.yaml" config filenames in /etc/borgmatic.d/ so as not to parse backup files,
|
||||
editor swap files, etc.
|
||||
* #81: Document user-defined hooks run before/after backup, or on error.
|
||||
* Add code style guidelines to the documention.
|
||||
* Add code style guidelines to the documentation.
|
||||
|
||||
1.2.0
|
||||
* #61: Support for Borg --list option via borgmatic command-line to list all archives.
|
||||
|
||||
@@ -17,10 +17,10 @@ def run_transfer(
|
||||
'''
|
||||
Run the "transfer" action for the given repository.
|
||||
'''
|
||||
logger.info(f'{repository}: Transferring archives to repository')
|
||||
logger.info(f'{repository["path"]}: Transferring archives to repository')
|
||||
borgmatic.borg.transfer.transfer_archives(
|
||||
global_arguments.dry_run,
|
||||
repository,
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
transfer_arguments,
|
||||
|
||||
+21
-10
@@ -12,7 +12,6 @@ DEFAULT_CHECKS = (
|
||||
{'name': 'repository', 'frequency': '1 month'},
|
||||
{'name': 'archives', 'frequency': '1 month'},
|
||||
)
|
||||
DEFAULT_PREFIX = '{hostname}-' # noqa: FS003
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -146,9 +145,10 @@ def filter_checks_on_frequency(
|
||||
return tuple(filtered_checks)
|
||||
|
||||
|
||||
def make_check_flags(local_borg_version, checks, check_last=None, prefix=None):
|
||||
def make_check_flags(local_borg_version, storage_config, checks, check_last=None, prefix=None):
|
||||
'''
|
||||
Given the local Borg version and a parsed sequence of checks, transform the checks into tuple of
|
||||
Given the local Borg version, a storage configuration dict, a parsed sequence of checks, the
|
||||
check last value, and a consistency check prefix, transform the checks into tuple of
|
||||
command-line flags.
|
||||
|
||||
For example, given parsed checks of:
|
||||
@@ -174,10 +174,21 @@ def make_check_flags(local_borg_version, checks, check_last=None, prefix=None):
|
||||
|
||||
if 'archives' in checks:
|
||||
last_flags = ('--last', str(check_last)) if check_last else ()
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
|
||||
match_archives_flags = ('--match-archives', f'sh:{prefix}*') if prefix else ()
|
||||
else:
|
||||
match_archives_flags = ('--glob-archives', f'{prefix}*') if prefix else ()
|
||||
match_archives_flags = (
|
||||
(
|
||||
('--match-archives', f'sh:{prefix}*')
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
||||
else ('--glob-archives', f'{prefix}*')
|
||||
)
|
||||
if prefix
|
||||
else (
|
||||
flags.make_match_archives_flags(
|
||||
storage_config.get('match_archives'),
|
||||
storage_config.get('archive_name_format'),
|
||||
local_borg_version,
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
last_flags = ()
|
||||
match_archives_flags = ()
|
||||
@@ -291,7 +302,7 @@ def check_archives(
|
||||
extra_borg_options = storage_config.get('extra_borg_options', {}).get('check', '')
|
||||
|
||||
if set(checks).intersection({'repository', 'archives', 'data'}):
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
lock_wait = storage_config.get('lock_wait')
|
||||
|
||||
verbosity_flags = ()
|
||||
if logger.isEnabledFor(logging.INFO):
|
||||
@@ -299,12 +310,12 @@ def check_archives(
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
|
||||
prefix = consistency_config.get('prefix', DEFAULT_PREFIX)
|
||||
prefix = consistency_config.get('prefix')
|
||||
|
||||
full_command = (
|
||||
(local_path, 'check')
|
||||
+ (('--repair',) if repair else ())
|
||||
+ make_check_flags(local_borg_version, checks, check_last, prefix)
|
||||
+ make_check_flags(local_borg_version, storage_config, checks, check_last, prefix)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ verbosity_flags
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import itertools
|
||||
import re
|
||||
|
||||
from borgmatic.borg import feature
|
||||
|
||||
@@ -56,3 +57,27 @@ def make_repository_archive_flags(repository_path, archive, local_borg_version):
|
||||
if feature.available(feature.Feature.SEPARATE_REPOSITORY_ARCHIVE, local_borg_version)
|
||||
else (f'{repository_path}::{archive}',)
|
||||
)
|
||||
|
||||
|
||||
def make_match_archives_flags(match_archives, archive_name_format, local_borg_version):
|
||||
'''
|
||||
Return match archives flags based on the given match archives value, if any. If it isn't set,
|
||||
return match archives flags to match archives created with the given archive name format, if
|
||||
any. This is done by replacing certain archive name format placeholders for ephemeral data (like
|
||||
"{now}") with globs.
|
||||
'''
|
||||
if match_archives:
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
|
||||
return ('--match-archives', match_archives)
|
||||
else:
|
||||
return ('--glob-archives', re.sub(r'^sh:', '', match_archives))
|
||||
|
||||
if not archive_name_format:
|
||||
return ()
|
||||
|
||||
derived_match_archives = re.sub(r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format)
|
||||
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
|
||||
return ('--match-archives', f'sh:{derived_match_archives}')
|
||||
else:
|
||||
return ('--glob-archives', f'{derived_match_archives}')
|
||||
|
||||
+10
-7
@@ -44,17 +44,20 @@ def display_archives_info(
|
||||
else flags.make_flags('glob-archives', f'{info_arguments.prefix}*')
|
||||
)
|
||||
if info_arguments.prefix
|
||||
else ()
|
||||
else (
|
||||
flags.make_match_archives_flags(
|
||||
info_arguments.match_archives
|
||||
or info_arguments.archive
|
||||
or storage_config.get('match_archives'),
|
||||
storage_config.get('archive_name_format'),
|
||||
local_borg_version,
|
||||
)
|
||||
)
|
||||
)
|
||||
+ flags.make_flags_from_arguments(
|
||||
info_arguments, excludes=('repository', 'archive', 'prefix')
|
||||
info_arguments, excludes=('repository', 'archive', 'prefix', 'match_archives')
|
||||
)
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
+ (
|
||||
flags.make_flags('match-archives', info_arguments.archive)
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
||||
else flags.make_flags('glob-archives', info_arguments.archive)
|
||||
)
|
||||
)
|
||||
|
||||
if info_arguments.json:
|
||||
|
||||
+22
-16
@@ -7,10 +7,10 @@ from borgmatic.execute import execute_command
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def make_prune_flags(retention_config, local_borg_version):
|
||||
def make_prune_flags(storage_config, retention_config, local_borg_version):
|
||||
'''
|
||||
Given a retention config dict mapping from option name to value, tranform it into an iterable of
|
||||
command-line name-value flag pairs.
|
||||
Given a retention config dict mapping from option name to value, transform it into an sequence of
|
||||
command-line flags.
|
||||
|
||||
For example, given a retention config of:
|
||||
|
||||
@@ -24,18 +24,28 @@ def make_prune_flags(retention_config, local_borg_version):
|
||||
)
|
||||
'''
|
||||
config = retention_config.copy()
|
||||
prefix = config.pop('prefix', '{hostname}-') # noqa: FS003
|
||||
prefix = config.pop('prefix', None)
|
||||
|
||||
if prefix:
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version):
|
||||
config['match_archives'] = f'sh:{prefix}*'
|
||||
else:
|
||||
config['glob_archives'] = f'{prefix}*'
|
||||
|
||||
return (
|
||||
flag_pairs = (
|
||||
('--' + option_name.replace('_', '-'), str(value)) for option_name, value in config.items()
|
||||
)
|
||||
|
||||
return tuple(element for pair in flag_pairs for element in pair) + (
|
||||
(
|
||||
('--match-archives', f'sh:{prefix}*')
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
||||
else ('--glob-archives', f'{prefix}*')
|
||||
)
|
||||
if prefix
|
||||
else (
|
||||
flags.make_match_archives_flags(
|
||||
storage_config.get('match_archives'),
|
||||
storage_config.get('archive_name_format'),
|
||||
local_borg_version,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def prune_archives(
|
||||
dry_run,
|
||||
@@ -60,11 +70,7 @@ def prune_archives(
|
||||
|
||||
full_command = (
|
||||
(local_path, 'prune')
|
||||
+ tuple(
|
||||
element
|
||||
for pair in make_prune_flags(retention_config, local_borg_version)
|
||||
for element in pair
|
||||
)
|
||||
+ make_prune_flags(storage_config, retention_config, local_borg_version)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
|
||||
@@ -52,7 +52,7 @@ def resolve_archive_name(
|
||||
return latest_archive
|
||||
|
||||
|
||||
MAKE_FLAGS_EXCLUDES = ('repository', 'prefix')
|
||||
MAKE_FLAGS_EXCLUDES = ('repository', 'prefix', 'match_archives')
|
||||
|
||||
|
||||
def make_rlist_command(
|
||||
@@ -94,7 +94,13 @@ def make_rlist_command(
|
||||
else flags.make_flags('glob-archives', f'{rlist_arguments.prefix}*')
|
||||
)
|
||||
if rlist_arguments.prefix
|
||||
else ()
|
||||
else (
|
||||
flags.make_match_archives_flags(
|
||||
rlist_arguments.match_archives or storage_config.get('match_archives'),
|
||||
storage_config.get('archive_name_format'),
|
||||
local_borg_version,
|
||||
)
|
||||
)
|
||||
)
|
||||
+ flags.make_flags_from_arguments(rlist_arguments, excludes=MAKE_FLAGS_EXCLUDES)
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
|
||||
@@ -28,15 +28,20 @@ def transfer_archives(
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('lock-wait', storage_config.get('lock_wait', None))
|
||||
+ (('--progress',) if transfer_arguments.progress else ())
|
||||
+ (
|
||||
flags.make_flags(
|
||||
'match-archives', transfer_arguments.match_archives or transfer_arguments.archive
|
||||
flags.make_flags_from_arguments(
|
||||
transfer_arguments,
|
||||
excludes=('repository', 'source_repository', 'archive', 'match_archives'),
|
||||
)
|
||||
or (
|
||||
flags.make_match_archives_flags(
|
||||
transfer_arguments.match_archives
|
||||
or transfer_arguments.archive
|
||||
or storage_config.get('match_archives'),
|
||||
storage_config.get('archive_name_format'),
|
||||
local_borg_version,
|
||||
)
|
||||
)
|
||||
)
|
||||
+ flags.make_flags_from_arguments(
|
||||
transfer_arguments,
|
||||
excludes=('repository', 'source_repository', 'archive', 'match_archives'),
|
||||
)
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
+ flags.make_flags('other-repo', transfer_arguments.source_repository)
|
||||
|
||||
@@ -178,10 +178,12 @@ def make_parsers():
|
||||
help='Log verbose progress to monitoring integrations that support logging (from only errors to very verbose: -1, 0, 1, or 2)',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--log-file',
|
||||
'--log-file', type=str, help='Write log messages to this file instead of syslog',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--log-file-format',
|
||||
type=str,
|
||||
default=None,
|
||||
help='Write log messages to this file instead of syslog',
|
||||
help='Log format string used for log messages written to the log file',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--override',
|
||||
@@ -293,7 +295,7 @@ def make_parsers():
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--upgrader',
|
||||
help='Upgrader type used to convert the transfered data, e.g. "From12To20" to upgrade data from Borg 1.2 to 2.0 format, defaults to no conversion',
|
||||
help='Upgrader type used to convert the transferred data, e.g. "From12To20" to upgrade data from Borg 1.2 to 2.0 format, defaults to no conversion',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--progress',
|
||||
@@ -650,7 +652,7 @@ def make_parsers():
|
||||
'--json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'-P', '--prefix', help='Only list archive names starting with this prefix'
|
||||
'-P', '--prefix', help='Deprecated. Only list archive names starting with this prefix'
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'-a',
|
||||
@@ -705,7 +707,7 @@ def make_parsers():
|
||||
'--json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'-P', '--prefix', help='Only list archive names starting with this prefix'
|
||||
'-P', '--prefix', help='Deprecated. Only list archive names starting with this prefix'
|
||||
)
|
||||
list_group.add_argument(
|
||||
'-a',
|
||||
@@ -777,7 +779,9 @@ def make_parsers():
|
||||
'--json', dest='json', default=False, action='store_true', help='Output results as JSON'
|
||||
)
|
||||
info_group.add_argument(
|
||||
'-P', '--prefix', help='Only show info for archive names starting with this prefix'
|
||||
'-P',
|
||||
'--prefix',
|
||||
help='Deprecated. Only show info for archive names starting with this prefix',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'-a',
|
||||
@@ -875,7 +879,17 @@ def parse_arguments(*unparsed_arguments):
|
||||
and arguments['transfer'].match_archives
|
||||
):
|
||||
raise ValueError(
|
||||
'With the transfer action, only one of --archive and --glob-archives flags can be used.'
|
||||
'With the transfer action, only one of --archive and --match-archives flags can be used.'
|
||||
)
|
||||
|
||||
if 'list' in arguments and (arguments['list'].prefix and arguments['list'].match_archives):
|
||||
raise ValueError(
|
||||
'With the list action, only one of --prefix or --match-archives flags can be used.'
|
||||
)
|
||||
|
||||
if 'rlist' in arguments and (arguments['rlist'].prefix and arguments['rlist'].match_archives):
|
||||
raise ValueError(
|
||||
'With the rlist action, only one of --prefix or --match-archives flags can be used.'
|
||||
)
|
||||
|
||||
if 'info' in arguments and (
|
||||
|
||||
@@ -267,6 +267,7 @@ def run_actions(
|
||||
'repository': repository_path,
|
||||
# Deprecated: For backwards compatibility with borgmatic < 1.6.0.
|
||||
'repositories': ','.join([repo['path'] for repo in location['repositories']]),
|
||||
'log_file': global_arguments.log_file if global_arguments.log_file else '',
|
||||
}
|
||||
|
||||
command.execute_hook(
|
||||
@@ -700,6 +701,7 @@ def main(): # pragma: no cover
|
||||
verbosity_to_log_level(global_arguments.log_file_verbosity),
|
||||
verbosity_to_log_level(global_arguments.monitoring_verbosity),
|
||||
global_arguments.log_file,
|
||||
global_arguments.log_file_format,
|
||||
)
|
||||
except (FileNotFoundError, PermissionError) as error:
|
||||
configure_logging(logging.CRITICAL)
|
||||
|
||||
@@ -2,6 +2,7 @@ import logging
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import borgmatic.config.generate
|
||||
from borgmatic.config import collect, validate
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -23,16 +24,22 @@ def parse_arguments(*arguments):
|
||||
default=config_paths,
|
||||
help=f'Configuration filenames or directories, defaults to: {config_paths}',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-s',
|
||||
'--show',
|
||||
action='store_true',
|
||||
help='Show the validated configuration after all include merging has occurred',
|
||||
)
|
||||
|
||||
return parser.parse_args(arguments)
|
||||
|
||||
|
||||
def main(): # pragma: no cover
|
||||
args = parse_arguments(*sys.argv[1:])
|
||||
arguments = parse_arguments(*sys.argv[1:])
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||
|
||||
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||
config_filenames = tuple(collect.collect_config_filenames(arguments.config_paths))
|
||||
if len(config_filenames) == 0:
|
||||
logger.critical('No files to validate found')
|
||||
sys.exit(1)
|
||||
@@ -40,13 +47,22 @@ def main(): # pragma: no cover
|
||||
found_issues = False
|
||||
for config_filename in config_filenames:
|
||||
try:
|
||||
validate.parse_configuration(config_filename, validate.schema_filename())
|
||||
config, parse_logs = validate.parse_configuration(
|
||||
config_filename, validate.schema_filename()
|
||||
)
|
||||
except (ValueError, OSError, validate.Validation_error) as error:
|
||||
logging.critical(f'{config_filename}: Error parsing configuration file')
|
||||
logging.critical(error)
|
||||
found_issues = True
|
||||
else:
|
||||
for log in parse_logs:
|
||||
logger.handle(log)
|
||||
|
||||
if arguments.show:
|
||||
print('---')
|
||||
print(borgmatic.config.generate.render_configuration(config))
|
||||
|
||||
if found_issues:
|
||||
sys.exit(1)
|
||||
else:
|
||||
logger.info(f"All given configuration files are valid: {', '.join(config_filenames)}")
|
||||
|
||||
logger.info(f"All given configuration files are valid: {', '.join(config_filenames)}")
|
||||
|
||||
@@ -43,7 +43,7 @@ def convert_legacy_parsed_config(source_config, source_excludes, schema):
|
||||
]
|
||||
)
|
||||
|
||||
# Split space-seperated values into actual lists, make "repository" into a list, and merge in
|
||||
# Split space-separated values into actual lists, make "repository" into a list, and merge in
|
||||
# excludes.
|
||||
location = destination_config['location']
|
||||
location['source_directories'] = source_config.location['source_directories'].split(' ')
|
||||
|
||||
+79
-24
@@ -38,6 +38,37 @@ def include_configuration(loader, filename_node, include_directory):
|
||||
return load_configuration(include_filename)
|
||||
|
||||
|
||||
def raise_retain_node_error(loader, node):
|
||||
'''
|
||||
Given a ruamel.yaml.loader.Loader and a YAML node, raise an error about "!retain" usage.
|
||||
|
||||
Raise ValueError if a mapping or sequence node is given, as that indicates that "!retain" was
|
||||
used in a configuration file without a merge. In configuration files with a merge, mapping and
|
||||
sequence nodes with "!retain" tags are handled by deep_merge_nodes() below.
|
||||
|
||||
Also raise ValueError if a scalar node is given, as "!retain" is not supported on scalar nodes.
|
||||
'''
|
||||
if isinstance(node, (ruamel.yaml.nodes.MappingNode, ruamel.yaml.nodes.SequenceNode)):
|
||||
raise ValueError(
|
||||
'The !retain tag may only be used within a configuration file containing a merged !include tag.'
|
||||
)
|
||||
|
||||
raise ValueError('The !retain tag may only be used on a YAML mapping or sequence.')
|
||||
|
||||
|
||||
def raise_omit_node_error(loader, node):
|
||||
'''
|
||||
Given a ruamel.yaml.loader.Loader and a YAML node, raise an error about "!omit" usage.
|
||||
|
||||
Raise ValueError unconditionally, as an "!omit" node here indicates it was used in a
|
||||
configuration file without a merge. In configuration files with a merge, nodes with "!omit"
|
||||
tags are handled by deep_merge_nodes() below.
|
||||
'''
|
||||
raise ValueError(
|
||||
'The !omit tag may only be used on a scalar (e.g., string) list element within a configuration file containing a merged !include tag.'
|
||||
)
|
||||
|
||||
|
||||
class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||
'''
|
||||
A YAML "constructor" (a ruamel.yaml concept) that supports a custom "!include" tag for including
|
||||
@@ -50,6 +81,8 @@ class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||
'!include',
|
||||
functools.partial(include_configuration, include_directory=include_directory),
|
||||
)
|
||||
self.add_constructor('!retain', raise_retain_node_error)
|
||||
self.add_constructor('!omit', raise_omit_node_error)
|
||||
|
||||
def flatten_mapping(self, node):
|
||||
'''
|
||||
@@ -115,6 +148,16 @@ def load_configuration(filename):
|
||||
return config
|
||||
|
||||
|
||||
def filter_omitted_nodes(nodes):
|
||||
'''
|
||||
Given a list of nodes, return a filtered list omitting any nodes with an "!omit" tag or with a
|
||||
value matching such nodes.
|
||||
'''
|
||||
omitted_values = tuple(node.value for node in nodes if node.tag == '!omit')
|
||||
|
||||
return [node for node in nodes if node.value not in omitted_values]
|
||||
|
||||
|
||||
DELETED_NODE = object()
|
||||
|
||||
|
||||
@@ -176,6 +219,8 @@ def deep_merge_nodes(nodes):
|
||||
),
|
||||
]
|
||||
|
||||
If a mapping or sequence node has a YAML "!retain" tag, then that node is not merged.
|
||||
|
||||
The purpose of deep merging like this is to support, for instance, merging one borgmatic
|
||||
configuration file into another for reuse, such that a configuration section ("retention",
|
||||
etc.) does not completely replace the corresponding section in a merged file.
|
||||
@@ -198,32 +243,42 @@ def deep_merge_nodes(nodes):
|
||||
|
||||
# If we're dealing with MappingNodes, recurse and merge its values as well.
|
||||
if isinstance(b_value, ruamel.yaml.nodes.MappingNode):
|
||||
replaced_nodes[(b_key, b_value)] = (
|
||||
b_key,
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
tag=b_value.tag,
|
||||
value=deep_merge_nodes(a_value.value + b_value.value),
|
||||
start_mark=b_value.start_mark,
|
||||
end_mark=b_value.end_mark,
|
||||
flow_style=b_value.flow_style,
|
||||
comment=b_value.comment,
|
||||
anchor=b_value.anchor,
|
||||
),
|
||||
)
|
||||
# A "!retain" tag says to skip deep merging for this node. Replace the tag so
|
||||
# downstream schema validation doesn't break on our application-specific tag.
|
||||
if b_value.tag == '!retain':
|
||||
b_value.tag = 'tag:yaml.org,2002:map'
|
||||
else:
|
||||
replaced_nodes[(b_key, b_value)] = (
|
||||
b_key,
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
tag=b_value.tag,
|
||||
value=deep_merge_nodes(a_value.value + b_value.value),
|
||||
start_mark=b_value.start_mark,
|
||||
end_mark=b_value.end_mark,
|
||||
flow_style=b_value.flow_style,
|
||||
comment=b_value.comment,
|
||||
anchor=b_value.anchor,
|
||||
),
|
||||
)
|
||||
# If we're dealing with SequenceNodes, merge by appending one sequence to the other.
|
||||
elif isinstance(b_value, ruamel.yaml.nodes.SequenceNode):
|
||||
replaced_nodes[(b_key, b_value)] = (
|
||||
b_key,
|
||||
ruamel.yaml.nodes.SequenceNode(
|
||||
tag=b_value.tag,
|
||||
value=a_value.value + b_value.value,
|
||||
start_mark=b_value.start_mark,
|
||||
end_mark=b_value.end_mark,
|
||||
flow_style=b_value.flow_style,
|
||||
comment=b_value.comment,
|
||||
anchor=b_value.anchor,
|
||||
),
|
||||
)
|
||||
# A "!retain" tag says to skip deep merging for this node. Replace the tag so
|
||||
# downstream schema validation doesn't break on our application-specific tag.
|
||||
if b_value.tag == '!retain':
|
||||
b_value.tag = 'tag:yaml.org,2002:seq'
|
||||
else:
|
||||
replaced_nodes[(b_key, b_value)] = (
|
||||
b_key,
|
||||
ruamel.yaml.nodes.SequenceNode(
|
||||
tag=b_value.tag,
|
||||
value=filter_omitted_nodes(a_value.value + b_value.value),
|
||||
start_mark=b_value.start_mark,
|
||||
end_mark=b_value.end_mark,
|
||||
flow_style=b_value.flow_style,
|
||||
comment=b_value.comment,
|
||||
anchor=b_value.anchor,
|
||||
),
|
||||
)
|
||||
|
||||
return [
|
||||
replaced_nodes.get(node, node) for node in nodes if replaced_nodes.get(node) != DELETED_NODE
|
||||
|
||||
@@ -6,7 +6,7 @@ properties:
|
||||
constants:
|
||||
type: object
|
||||
description: |
|
||||
Constants to use in the configuration file. All occurences of the
|
||||
Constants to use in the configuration file. All occurrences of the
|
||||
constant name within culy braces will be replaced with the value.
|
||||
For example, if you have a constant named "hostname" with the value
|
||||
"myhostname", then the string "{hostname}" will be replaced with
|
||||
@@ -46,29 +46,21 @@ properties:
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
description: |
|
||||
Path to local or remote repository
|
||||
(required). Tildes are expanded.
|
||||
Multiple repositories are backed up
|
||||
to in sequence. Borg placeholders
|
||||
can be used. See the output of
|
||||
"borg help placeholders" for
|
||||
details. See ssh_command for SSH
|
||||
options like identity file or port.
|
||||
If systemd service is used, then
|
||||
add local repository paths in the
|
||||
systemd service file to the
|
||||
ReadWritePaths list.
|
||||
example: ssh://user@backupserver/./{fqdn}
|
||||
label:
|
||||
type: string
|
||||
description: |
|
||||
Optional label for the repository. This
|
||||
can be used with the --repository flag
|
||||
to select a repository to backup to.
|
||||
If not specified, the repository path is
|
||||
used as the label.
|
||||
example: backupserver
|
||||
description: |
|
||||
A required list of local or remote repositories with paths
|
||||
and optional labels (which can be used with the --repository
|
||||
flag to select a repository). Tildes are expanded. Multiple
|
||||
repositories are backed up to in sequence. Borg placeholders
|
||||
can be used. See the output of "borg help placeholders" for
|
||||
details. See ssh_command for SSH options like identity file
|
||||
or port. If systemd service is used, then add local
|
||||
repository paths in the systemd service file to the
|
||||
ReadWritePaths list. Prior to borgmatic 1.7.10, repositories
|
||||
was just a list of plain path strings.
|
||||
example:
|
||||
- path: ssh://user@backupserver/./sourcehostname.borg
|
||||
label: backupserver
|
||||
@@ -386,12 +378,21 @@ properties:
|
||||
description: |
|
||||
Name of the archive. Borg placeholders can be used. See the
|
||||
output of "borg help placeholders" for details. Defaults to
|
||||
"{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}". If you specify this
|
||||
option, consider also specifying a prefix in the retention
|
||||
and consistency sections to avoid accidental
|
||||
pruning/checking of archives with different archive name
|
||||
formats.
|
||||
"{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}". When running
|
||||
actions like rlist, info, or check, borgmatic automatically
|
||||
tries to match only archives created with this name format.
|
||||
example: "{hostname}-documents-{now}"
|
||||
match_archives:
|
||||
type: string
|
||||
description: |
|
||||
A Borg pattern for filtering down the archives used by
|
||||
borgmatic actions that operate on multiple archives. For
|
||||
Borg 1.x, use a shell pattern here and see the output of
|
||||
"borg help placeholders" for details. For Borg 2.x, see the
|
||||
output of "borg help match-archives". If match_archives is
|
||||
not specified, borgmatic defaults to deriving the
|
||||
match_archives value from archive_name_format.
|
||||
example: "sh:{hostname}-*"
|
||||
relocated_repo_access_is_ok:
|
||||
type: boolean
|
||||
description: |
|
||||
@@ -485,10 +486,12 @@ properties:
|
||||
prefix:
|
||||
type: string
|
||||
description: |
|
||||
When pruning, only consider archive names starting with this
|
||||
prefix. Borg placeholders can be used. See the output of
|
||||
"borg help placeholders" for details. Defaults to
|
||||
"{hostname}-". Use an empty value to disable the default.
|
||||
Deprecated. When pruning, only consider archive names
|
||||
starting with this prefix. Borg placeholders can be used.
|
||||
See the output of "borg help placeholders" for details.
|
||||
If a prefix is not specified, borgmatic defaults to
|
||||
matching archives based on the archive_name_format (see
|
||||
above).
|
||||
example: sourcehostname
|
||||
consistency:
|
||||
type: object
|
||||
@@ -546,12 +549,12 @@ properties:
|
||||
items:
|
||||
type: string
|
||||
description: |
|
||||
Paths to a subset of the repositories in the location
|
||||
section on which to run consistency checks. Handy in case
|
||||
some of your repositories are very large, and so running
|
||||
consistency checks on them would take too long. Defaults to
|
||||
running consistency checks on all repositories configured in
|
||||
the location section.
|
||||
Paths or labels for a subset of the repositories in the
|
||||
location section on which to run consistency checks. Handy
|
||||
in case some of your repositories are very large, and so
|
||||
running consistency checks on them would take too long.
|
||||
Defaults to running consistency checks on all repositories
|
||||
configured in the location section.
|
||||
example:
|
||||
- user@backupserver:sourcehostname.borg
|
||||
check_last:
|
||||
@@ -564,11 +567,12 @@ properties:
|
||||
prefix:
|
||||
type: string
|
||||
description: |
|
||||
When performing the "archives" check, only consider archive
|
||||
names starting with this prefix. Borg placeholders can be
|
||||
used. See the output of "borg help placeholders" for
|
||||
details. Defaults to "{hostname}-". Use an empty value to
|
||||
disable the default.
|
||||
Deprecated. When performing the "archives" check, only
|
||||
consider archive names starting with this prefix. Borg
|
||||
placeholders can be used. See the output of "borg help
|
||||
placeholders" for details. If a prefix is not specified,
|
||||
borgmatic defaults to matching archives based on the
|
||||
archive_name_format (see above).
|
||||
example: sourcehostname
|
||||
output:
|
||||
type: object
|
||||
@@ -937,14 +941,14 @@ properties:
|
||||
type: string
|
||||
enum: ['sql']
|
||||
description: |
|
||||
Database dump output format. Currenly only "sql"
|
||||
is supported. Defaults to "sql" for a single
|
||||
database. Or, when database name is "all" and
|
||||
format is blank, dumps all databases to a single
|
||||
file. But if a format is specified with an "all"
|
||||
database name, dumps each database to a separate
|
||||
file of that format, allowing more convenient
|
||||
restores of individual databases.
|
||||
Database dump output format. Currently only
|
||||
"sql" is supported. Defaults to "sql" for a
|
||||
single database. Or, when database name is "all"
|
||||
and format is blank, dumps all databases to a
|
||||
single file. But if a format is specified with
|
||||
an "all" database name, dumps each database to a
|
||||
separate file of that format, allowing more
|
||||
convenient restores of individual databases.
|
||||
example: directory
|
||||
add_drop_database:
|
||||
type: boolean
|
||||
|
||||
@@ -69,7 +69,10 @@ def apply_logical_validation(config_filename, parsed_configuration):
|
||||
location_repositories = parsed_configuration.get('location', {}).get('repositories')
|
||||
check_repositories = parsed_configuration.get('consistency', {}).get('check_repositories', [])
|
||||
for repository in check_repositories:
|
||||
if repository not in location_repositories:
|
||||
if not any(
|
||||
repositories_match(repository, config_repository)
|
||||
for config_repository in location_repositories
|
||||
):
|
||||
raise Validation_error(
|
||||
config_filename,
|
||||
(
|
||||
|
||||
+10
-3
@@ -68,7 +68,7 @@ class Multi_stream_handler(logging.Handler):
|
||||
|
||||
def emit(self, record):
|
||||
'''
|
||||
Dispatch the log record to the approriate stream handler for the record's log level.
|
||||
Dispatch the log record to the appropriate stream handler for the record's log level.
|
||||
'''
|
||||
self.log_level_to_handler[record.levelno].emit(record)
|
||||
|
||||
@@ -156,6 +156,7 @@ def configure_logging(
|
||||
log_file_log_level=None,
|
||||
monitoring_log_level=None,
|
||||
log_file=None,
|
||||
log_file_format=None,
|
||||
):
|
||||
'''
|
||||
Configure logging to go to both the console and (syslog or log file). Use the given log levels,
|
||||
@@ -200,12 +201,18 @@ def configure_logging(
|
||||
|
||||
if syslog_path and not interactive_console():
|
||||
syslog_handler = logging.handlers.SysLogHandler(address=syslog_path)
|
||||
syslog_handler.setFormatter(logging.Formatter('borgmatic: %(levelname)s %(message)s'))
|
||||
syslog_handler.setFormatter(
|
||||
logging.Formatter('borgmatic: {levelname} {message}', style='{') # noqa: FS003
|
||||
)
|
||||
syslog_handler.setLevel(syslog_log_level)
|
||||
handlers = (console_handler, syslog_handler)
|
||||
elif log_file:
|
||||
file_handler = logging.handlers.WatchedFileHandler(log_file)
|
||||
file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
|
||||
file_handler.setFormatter(
|
||||
logging.Formatter(
|
||||
log_file_format or '[{asctime}] {levelname}: {message}', style='{' # noqa: FS003
|
||||
)
|
||||
)
|
||||
file_handler.setLevel(log_file_log_level)
|
||||
handlers = (console_handler, file_handler)
|
||||
else:
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
FROM alpine:3.17.1 as borgmatic
|
||||
FROM docker.io/alpine:3.17.1 as borgmatic
|
||||
|
||||
COPY . /app
|
||||
RUN apk add --no-cache py3-pip py3-ruamel.yaml py3-ruamel.yaml.clib
|
||||
@@ -8,7 +8,7 @@ RUN borgmatic --help > /command-line.txt \
|
||||
echo -e "\n--------------------------------------------------------------------------------\n" >> /command-line.txt \
|
||||
&& borgmatic "$action" --help >> /command-line.txt; done
|
||||
|
||||
FROM node:19.5.0-alpine as html
|
||||
FROM docker.io/node:19.5.0-alpine as html
|
||||
|
||||
ARG ENVIRONMENT=production
|
||||
|
||||
@@ -28,7 +28,7 @@ COPY . /source
|
||||
RUN NODE_ENV=${ENVIRONMENT} npx eleventy --input=/source/docs --output=/output/docs \
|
||||
&& mv /output/docs/index.html /output/index.html
|
||||
|
||||
FROM nginx:1.22.1-alpine
|
||||
FROM docker.io/nginx:1.22.1-alpine
|
||||
|
||||
COPY --from=html /output /usr/share/nginx/html
|
||||
COPY --from=borgmatic /etc/borgmatic/config.yaml /usr/share/nginx/html/docs/reference/config.yaml
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Footer catgory navigation */
|
||||
/* Footer category navigation */
|
||||
.elv-cat-list-active {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="icon" href="docs/static/borgmatic.png" type="image/x-icon">
|
||||
<title>{{ subtitle + ' - ' if subtitle}}{{ title }}</title>
|
||||
{%- set css %}
|
||||
{% include 'index.css' %}
|
||||
|
||||
@@ -66,6 +66,9 @@ variables you can use here:
|
||||
|
||||
* `configuration_filename`: borgmatic configuration filename in which the
|
||||
hook was defined
|
||||
* `log_file`
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span>:
|
||||
path of the borgmatic log file, only set when the `--log-file` flag is used
|
||||
* `repository`: path of the current repository as configured in the current
|
||||
borgmatic configuration file
|
||||
|
||||
|
||||
@@ -49,9 +49,12 @@ location:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- /mnt/removable/backup.borg
|
||||
- path: /mnt/removable/backup.borg
|
||||
```
|
||||
|
||||
<span class="minilink minilink-addedin">Prior to version 1.7.10</span> Omit
|
||||
the `path:` portion of the `repositories` list.
|
||||
|
||||
Then, write a `before_backup` hook in that same configuration file that uses
|
||||
the external `findmnt` utility to see whether the drive is mounted before
|
||||
proceeding.
|
||||
@@ -79,13 +82,16 @@ location:
|
||||
- /home
|
||||
|
||||
repositories:
|
||||
- ssh://me@buddys-server.org/./backup.borg
|
||||
- path: ssh://me@buddys-server.org/./backup.borg
|
||||
|
||||
hooks:
|
||||
before_backup:
|
||||
- ping -q -c 1 buddys-server.org > /dev/null || exit 75
|
||||
```
|
||||
|
||||
<span class="minilink minilink-addedin">Prior to version 1.7.10</span> Omit
|
||||
the `path:` portion of the `repositories` list.
|
||||
|
||||
Or to only run backups if the battery level is high enough:
|
||||
|
||||
```yaml
|
||||
@@ -110,8 +116,8 @@ There are some caveats you should be aware of with this feature.
|
||||
* You'll generally want to put a soft failure command in the `before_backup`
|
||||
hook, so as to gate whether the backup action occurs. While a soft failure is
|
||||
also supported in the `after_backup` hook, returning a soft failure there
|
||||
won't prevent any actions from occuring, because they've already occurred!
|
||||
Similiarly, you can return a soft failure from an `on_error` hook, but at
|
||||
won't prevent any actions from occurring, because they've already occurred!
|
||||
Similarly, you can return a soft failure from an `on_error` hook, but at
|
||||
that point it's too late to prevent the error.
|
||||
* Returning a soft failure does prevent further commands in the same hook from
|
||||
executing. So, like a standard error, it is an "early out". Unlike a standard
|
||||
|
||||
@@ -25,7 +25,7 @@ so that you can run borgmatic commands while you're hacking on them to
|
||||
make sure your changes work.
|
||||
|
||||
```bash
|
||||
cd borgmatic/
|
||||
cd borgmatic
|
||||
pip3 install --user --editable .
|
||||
```
|
||||
|
||||
@@ -51,7 +51,6 @@ pip3 install --user tox
|
||||
Finally, to actually run tests, run:
|
||||
|
||||
```bash
|
||||
cd borgmatic
|
||||
tox
|
||||
```
|
||||
|
||||
@@ -74,6 +73,15 @@ can ask isort to order your imports for you:
|
||||
tox -e isort
|
||||
```
|
||||
|
||||
Similarly, if you get errors about spelling mistakes in source code, you can
|
||||
ask [codespell](https://github.com/codespell-project/codespell) to correct
|
||||
them:
|
||||
|
||||
```bash
|
||||
tox -e codespell
|
||||
```
|
||||
|
||||
|
||||
### End-to-end tests
|
||||
|
||||
borgmatic additionally includes some end-to-end tests that integration test
|
||||
@@ -93,6 +101,30 @@ scripts/run-end-to-end-dev-tests
|
||||
Note that this scripts assumes you have permission to run Docker. If you
|
||||
don't, then you may need to run with `sudo`.
|
||||
|
||||
|
||||
#### Podman
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span>
|
||||
borgmatic's end-to-end tests optionally support using
|
||||
[rootless](https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md)
|
||||
[Podman](https://podman.io/) instead of Docker.
|
||||
|
||||
Setting up Podman is outside the scope of this documentation, but here are
|
||||
some key points to double-check:
|
||||
|
||||
* Install Podman along with `podman-docker` and your desired networking
|
||||
support.
|
||||
* Configure `/etc/subuid` and `/etc/subgid` to map users/groups for the
|
||||
non-root user who will run tests.
|
||||
* Create a non-root Podman socket for that user:
|
||||
```bash
|
||||
systemctl --user enable --now podman.socket
|
||||
```
|
||||
|
||||
Then you'll be able to run end-to-end tests as per normal, and the test script
|
||||
will automatically use your non-root Podman socket instead of a Docker socket.
|
||||
|
||||
|
||||
## Code style
|
||||
|
||||
Start with [PEP 8](https://www.python.org/dev/peps/pep-0008/). But then, apply
|
||||
@@ -101,10 +133,10 @@ the following deviations from it:
|
||||
* For strings, prefer single quotes over double quotes.
|
||||
* Limit all lines to a maximum of 100 characters.
|
||||
* Use trailing commas within multiline values or argument lists.
|
||||
* For multiline constructs, put opening and closing delimeters on lines
|
||||
* For multiline constructs, put opening and closing delimiters on lines
|
||||
separate from their contents.
|
||||
* Within multiline constructs, use standard four-space indentation. Don't align
|
||||
indentation with an opening delimeter.
|
||||
indentation with an opening delimiter.
|
||||
|
||||
borgmatic code uses the [Black](https://black.readthedocs.io/en/stable/) code
|
||||
formatter, the [Flake8](http://flake8.pycqa.org/en/latest/) code checker, and
|
||||
@@ -141,3 +173,15 @@ http://localhost:8080 to view the documentation with your changes.
|
||||
To close the documentation server, ctrl-C the script. Note that it does not
|
||||
currently auto-reload, so you'll need to stop it and re-run it for any
|
||||
additional documentation changes to take effect.
|
||||
|
||||
|
||||
#### Podman
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span>
|
||||
borgmatic's developer build for documentation optionally supports using
|
||||
[rootless](https://github.com/containers/podman/blob/main/docs/tutorials/rootless_tutorial.md)
|
||||
[Podman](https://podman.io/) instead of Docker.
|
||||
|
||||
Setting up Podman is outside the scope of this documentation. But once you
|
||||
install `podman-docker`, then `scripts/dev-docs` should automatically use
|
||||
Podman instead of Docker.
|
||||
|
||||
@@ -111,7 +111,7 @@ By default, borgmatic logs to a local syslog-compatible daemon if one is
|
||||
present and borgmatic is running in a non-interactive console. Where those
|
||||
logs show up depends on your particular system. If you're using systemd, try
|
||||
running `journalctl -xe`. Otherwise, try viewing `/var/log/syslog` or
|
||||
similiar.
|
||||
similar.
|
||||
|
||||
You can customize the log level used for syslog logging with the
|
||||
`--syslog-verbosity` flag, and this is independent from the console logging
|
||||
@@ -154,5 +154,39 @@ borgmatic --log-file /path/to/file.log
|
||||
|
||||
Note that if you use the `--log-file` flag, you are responsible for rotating
|
||||
the log file so it doesn't grow too large, for example with
|
||||
[logrotate](https://wiki.archlinux.org/index.php/Logrotate). Also, there is a
|
||||
`--log-file-verbosity` flag to customize the log file's log level.
|
||||
[logrotate](https://wiki.archlinux.org/index.php/Logrotate).
|
||||
|
||||
You can the `--log-file-verbosity` flag to customize the log file's log level:
|
||||
|
||||
```bash
|
||||
borgmatic --log-file /path/to/file.log --log-file-verbosity 2
|
||||
```
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.11</span> Use the
|
||||
`--log-file-format` flag to override the default log message format. This
|
||||
format string can contain a series of named placeholders wrapped in curly
|
||||
brackets. For instance, the default log format is: `[{asctime}] {levelname}:
|
||||
{message}`. This means each log message is recorded as the log time (in square
|
||||
brackets), a logging level name, a colon, and the actual log message.
|
||||
|
||||
So if you just want each log message to get logged *without* a timestamp or a
|
||||
logging level name:
|
||||
|
||||
```bash
|
||||
borgmatic --log-file /path/to/file.log --log-file-format "{message}"
|
||||
```
|
||||
|
||||
Here is a list of available placeholders:
|
||||
|
||||
* `{asctime}`: time the log message was created
|
||||
* `{levelname}`: level of the log message (`INFO`, `DEBUG`, etc.)
|
||||
* `{lineno}`: line number in the source file where the log message originated
|
||||
* `{message}`: actual log message
|
||||
* `{pathname}`: path of the source file where the log message originated
|
||||
|
||||
See the [Python logging
|
||||
documentation](https://docs.python.org/3/library/logging.html#logrecord-attributes)
|
||||
for additional placeholders.
|
||||
|
||||
Note that this `--log-file-format` flg only applies to the specified
|
||||
`--log-file` and not to syslog or other logging.
|
||||
|
||||
@@ -24,6 +24,9 @@ location:
|
||||
- path: /var/lib/backups/local.borg
|
||||
```
|
||||
|
||||
<span class="minilink minilink-addedin">Prior to version 1.7.10</span> Omit
|
||||
the `path:` portion of the `repositories` list.
|
||||
|
||||
When you run borgmatic with this configuration, it invokes Borg once for each
|
||||
configured repository in sequence. (So, not in parallel.) That means—in each
|
||||
repository—borgmatic creates a single new backup archive containing all of
|
||||
@@ -31,9 +34,8 @@ your source directories.
|
||||
|
||||
Here's a way of visualizing what borgmatic does with the above configuration:
|
||||
|
||||
1. Backup `/home` and `/etc` to `1234@usw-s001.rsync.net:backups.borg`
|
||||
2. Backup `/home` and `/etc` to `k8pDxu32@k8pDxu32.repo.borgbase.com:repo`
|
||||
3. Backup `/home` and `/etc` to `/var/lib/backups/local.borg`
|
||||
1. Backup `/home` and `/etc` to `k8pDxu32@k8pDxu32.repo.borgbase.com:repo`
|
||||
2. Backup `/home` and `/etc` to `/var/lib/backups/local.borg`
|
||||
|
||||
This gives you redundancy of your data across repositories and even
|
||||
potentially across providers.
|
||||
|
||||
@@ -54,6 +54,93 @@ choice](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#autopilot),
|
||||
each entry using borgmatic's `--config` flag instead of relying on
|
||||
`/etc/borgmatic.d`.
|
||||
|
||||
|
||||
## Archive naming
|
||||
|
||||
If you've got multiple borgmatic configuration files, you might want to create
|
||||
archives with different naming schemes for each one. This is especially handy
|
||||
if each configuration file is backing up to the same Borg repository but you
|
||||
still want to be able to distinguish backup archives for one application from
|
||||
another.
|
||||
|
||||
borgmatic supports this use case with an `archive_name_format` option. The
|
||||
idea is that you define a string format containing a number of [Borg
|
||||
placeholders](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-placeholders),
|
||||
and borgmatic uses that format to name any new archive it creates. For
|
||||
instance:
|
||||
|
||||
```yaml
|
||||
storage:
|
||||
...
|
||||
archive_name_format: home-directories-{now}
|
||||
```
|
||||
|
||||
This means that when borgmatic creates an archive, its name will start with
|
||||
the string `home-directories-` and end with a timestamp for its creation time.
|
||||
If `archive_name_format` is unspecified, the default is
|
||||
`{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}`, meaning your system hostname plus a
|
||||
timestamp in a particular format.
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.11</span> borgmatic
|
||||
uses the `archive_name_format` option to automatically limit which archives
|
||||
get used for actions operating on multiple archives. This prevents, for
|
||||
instance, duplicate archives from showing up in `rlist` or `info` results—even
|
||||
if the same repository appears in multiple borgmatic configuration files. To
|
||||
take advantage of this feature, simply use a different `archive_name_format`
|
||||
in each configuration file.
|
||||
|
||||
Under the hood, borgmatic accomplishes this by substituting globs for certain
|
||||
ephemeral data placeholders in your `archive_name_format`—and using the result
|
||||
to filter archives when running supported actions.
|
||||
|
||||
For instance, let's say that you have this in your configuration:
|
||||
|
||||
```yaml
|
||||
storage:
|
||||
...
|
||||
archive_name_format: {hostname}-user-data-{now}
|
||||
```
|
||||
|
||||
borgmatic considers `{now}` an emphemeral data placeholder that will probably
|
||||
change per archive, while `{hostname}` won't. So it turns the example value
|
||||
into `{hostname}-user-data-*` and applies it to filter down the set of
|
||||
archives used for actions like `rlist`, `info`, `prune`, `check`, etc.
|
||||
|
||||
The end result is that when borgmatic runs the actions for a particular
|
||||
application-specific configuration file, it only operates on the archives
|
||||
created for that application. Of course, this doesn't apply to actions like
|
||||
`compact` that operate on an entire repository.
|
||||
|
||||
If this behavior isn't quite smart enough for your needs, you can use the
|
||||
`match_archives` option to override the pattern that borgmatic uses for
|
||||
filtering archives. For example:
|
||||
|
||||
```yaml
|
||||
storage:
|
||||
...
|
||||
archive_name_format: {hostname}-user-data-{now}
|
||||
match_archives: sh:myhost-user-data-*
|
||||
```
|
||||
|
||||
For Borg 1.x, use a shell pattern for the `match_archives` value and see the
|
||||
[Borg patterns
|
||||
documentation](https://borgbackup.readthedocs.io/en/stable/usage/help.html#borg-help-patterns)
|
||||
for more information. For Borg 2.x, see the [match archives
|
||||
documentation](https://borgbackup.readthedocs.io/en/2.0.0b5/usage/help.html#borg-help-match-archives).
|
||||
|
||||
Some borgmatic command-line actions also have a `--match-archives` flag that
|
||||
overrides both the auto-matching behavior and the `match_archives`
|
||||
configuration option.
|
||||
|
||||
<span class="minilink minilink-addedin">Prior to 1.7.11</span> The way to
|
||||
limit the archives used for the `prune` action was a `prefix` option in the
|
||||
`retention` section for matching against the start of archive names. And the
|
||||
option for limiting the archives used for the `check` action was a separate
|
||||
`prefix` in the `consistency` section. Both of these options are deprecated in
|
||||
favor of the auto-matching behavior (or `match_archives`/`--match-archives`)
|
||||
in newer versions of borgmatic.
|
||||
|
||||
|
||||
## Configuration includes
|
||||
|
||||
Once you have multiple different configuration files, you might want to share
|
||||
@@ -185,9 +272,140 @@ Once this include gets merged in, the resulting configuration would have a
|
||||
When there's an option collision between the local file and the merged
|
||||
include, the local file's option takes precedence.
|
||||
|
||||
|
||||
#### List merge
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.6.1</span> Colliding
|
||||
list values are appended together.
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span> If there
|
||||
is a list value from an include that you *don't* want in your local
|
||||
configuration file, you can omit it with an `!omit` tag. For instance:
|
||||
|
||||
```yaml
|
||||
<<: !include /etc/borgmatic/common.yaml
|
||||
|
||||
location:
|
||||
source_directories:
|
||||
- !omit /home
|
||||
- /var
|
||||
```
|
||||
|
||||
And `common.yaml` like this:
|
||||
|
||||
```yaml
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
- /etc
|
||||
```
|
||||
|
||||
Once this include gets merged in, the resulting configuration will have a
|
||||
`source_directories` value of `/etc` and `/var`—with `/home` omitted.
|
||||
|
||||
This feature currently only works on scalar (e.g. string or number) list items
|
||||
and will not work elsewhere in a configuration file. Be sure to put the
|
||||
`!omit` tag *before* the list item (after the dash). Putting `!omit` after the
|
||||
list item will not work, as it gets interpreted as part of the string. Here's
|
||||
an example of some things not to do:
|
||||
|
||||
```yaml
|
||||
<<: !include /etc/borgmatic/common.yaml
|
||||
|
||||
location:
|
||||
source_directories:
|
||||
# Do not do this! It will not work. "!omit" belongs before "/home".
|
||||
- /home !omit
|
||||
|
||||
# Do not do this either! "!omit" only works on scalar list items.
|
||||
repositories: !omit
|
||||
# Also do not do this for the same reason! This is a list item, but it's
|
||||
# not a scalar.
|
||||
- !omit path: repo.borg
|
||||
```
|
||||
|
||||
Additionally, the `!omit` tag only works in a configuration file that also
|
||||
performs a merge include with `<<: !include`. It doesn't make sense within,
|
||||
for instance, an included configuration file itself (unless it in turn
|
||||
performs its own merge include). That's because `!omit` only applies to the
|
||||
file doing the include; it doesn't work in reverse or propagate through
|
||||
includes.
|
||||
|
||||
|
||||
### Shallow merge
|
||||
|
||||
Even though deep merging is generally pretty handy for included files,
|
||||
sometimes you want specific sections in the local file to take precedence over
|
||||
included sections—without any merging occurring for them.
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span> That's
|
||||
where the `!retain` tag comes in. Whenever you're merging an included file
|
||||
into your configuration file, you can optionally add the `!retain` tag to
|
||||
particular local mappings or lists to retain the local values and ignore
|
||||
included values.
|
||||
|
||||
For instance, start with this configuration file containing the `!retain` tag
|
||||
on the `retention` mapping:
|
||||
|
||||
```yaml
|
||||
<<: !include /etc/borgmatic/common.yaml
|
||||
|
||||
location:
|
||||
repositories:
|
||||
- path: repo.borg
|
||||
|
||||
retention: !retain
|
||||
keep_daily: 5
|
||||
```
|
||||
|
||||
And `common.yaml` like this:
|
||||
|
||||
```yaml
|
||||
location:
|
||||
repositories:
|
||||
- path: common.borg
|
||||
|
||||
retention:
|
||||
keep_hourly: 24
|
||||
keep_daily: 7
|
||||
```
|
||||
|
||||
Once this include gets merged in, the resulting configuration will have a
|
||||
`keep_daily` value of `5` and nothing else in the `retention` section. That's
|
||||
because the `!retain` tag says to retain the local version of `retention` and
|
||||
ignore any values coming in from the include. But because the `repositories`
|
||||
list doesn't have a `!retain` tag, it still gets merged together to contain
|
||||
both `common.borg` and `repo.borg`.
|
||||
|
||||
The `!retain` tag can only be placed on mappings and lists, and it goes right
|
||||
after the name of the option (and its colon) on the same line. The effects of
|
||||
`!retain` are recursive, meaning that if you place a `!retain` tag on a
|
||||
top-level mapping, even deeply nested values within it will not be merged.
|
||||
|
||||
Additionally, the `!retain` tag only works in a configuration file that also
|
||||
performs a merge include with `<<: !include`. It doesn't make sense within,
|
||||
for instance, an included configuration file itself (unless it in turn
|
||||
performs its own merge include). That's because `!retain` only applies to the
|
||||
file doing the include; it doesn't work in reverse or propagate through
|
||||
includes.
|
||||
|
||||
|
||||
## Debugging includes
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span> If you'd
|
||||
like to see what the loaded configuration looks like after includes get merged
|
||||
in, run `validate-borgmatic-config` on your configuration file:
|
||||
|
||||
```bash
|
||||
sudo validate-borgmatic-config --show
|
||||
```
|
||||
|
||||
You'll need to specify your configuration file with `--config` if it's not in
|
||||
a default location.
|
||||
|
||||
This will output the merged configuration as borgmatic sees it, which can be
|
||||
helpful for understanding how your includes work in practice.
|
||||
|
||||
|
||||
## Configuration overrides
|
||||
|
||||
@@ -272,7 +490,7 @@ Here's an example usage:
|
||||
```yaml
|
||||
constants:
|
||||
user: foo
|
||||
my_prefix: bar-
|
||||
archive_prefix: bar
|
||||
|
||||
location:
|
||||
source_directories:
|
||||
@@ -281,20 +499,14 @@ location:
|
||||
...
|
||||
|
||||
storage:
|
||||
archive_name_format: '{my_prefix}{now}'
|
||||
|
||||
retention:
|
||||
prefix: {my_prefix}
|
||||
|
||||
consistency:
|
||||
prefix: {my_prefix}
|
||||
archive_name_format: '{archive_prefix}-{now}'
|
||||
```
|
||||
|
||||
In this example, when borgmatic runs, all instances of `{user}` get replaced
|
||||
with `foo` and all instances of `{my_prefix}` get replaced with `bar-`. (And
|
||||
in this particular example, `{now}` doesn't get replaced with anything, but
|
||||
gets passed directly to Borg.) After substitution, the logical result looks
|
||||
something like this:
|
||||
with `foo` and all instances of `{archive-prefix}` get replaced with `bar-`.
|
||||
(And in this particular example, `{now}` doesn't get replaced with anything,
|
||||
but gets passed directly to Borg.) After substitution, the logical result
|
||||
looks something like this:
|
||||
|
||||
```yaml
|
||||
location:
|
||||
@@ -305,12 +517,6 @@ location:
|
||||
|
||||
storage:
|
||||
archive_name_format: 'bar-{now}'
|
||||
|
||||
retention:
|
||||
prefix: bar-
|
||||
|
||||
consistency:
|
||||
prefix: bar-
|
||||
```
|
||||
|
||||
An alternate to constants is passing in your values via [environment
|
||||
|
||||
@@ -90,7 +90,7 @@ installing borgmatic:
|
||||
* [Fedora unofficial](https://copr.fedorainfracloud.org/coprs/heffer/borgmatic/)
|
||||
* [Arch Linux](https://www.archlinux.org/packages/community/any/borgmatic/)
|
||||
* [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=borgmatic)
|
||||
* [OpenBSD](http://ports.su/sysutils/borgmatic)
|
||||
* [OpenBSD](https://openports.pl/path/sysutils/borgmatic)
|
||||
* [openSUSE](https://software.opensuse.org/package/borgmatic)
|
||||
* [macOS (via Homebrew)](https://formulae.brew.sh/formula/borgmatic)
|
||||
* [macOS (via MacPorts)](https://ports.macports.org/port/borgmatic/)
|
||||
@@ -157,7 +157,7 @@ variable or set the `BORG_PASSPHRASE` environment variable. See the
|
||||
section](https://borgbackup.readthedocs.io/en/stable/quickstart.html#repository-encryption)
|
||||
of the Borg Quick Start for more info.
|
||||
|
||||
Alternatively, you can specify the passphrase programatically by setting
|
||||
Alternatively, you can specify the passphrase programmatically by setting
|
||||
either the borgmatic `encryption_passcommand` configuration variable or the
|
||||
`BORG_PASSCOMMAND` environment variable. See the [Borg Security
|
||||
FAQ](http://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-encryption-passphrase-programmatically)
|
||||
@@ -180,6 +180,9 @@ following command is available for that:
|
||||
sudo validate-borgmatic-config
|
||||
```
|
||||
|
||||
You'll need to specify your configuration file with `--config` if it's not in
|
||||
a default location.
|
||||
|
||||
This command's exit status (`$?` in Bash) is zero when configuration is valid
|
||||
and non-zero otherwise.
|
||||
|
||||
|
||||
@@ -145,15 +145,18 @@ like this:
|
||||
```yaml
|
||||
location:
|
||||
repositories:
|
||||
- original.borg
|
||||
- path: original.borg
|
||||
```
|
||||
|
||||
<span class="minilink minilink-addedin">Prior to version 1.7.10</span> Omit
|
||||
the `path:` portion of the `repositories` list.
|
||||
|
||||
Change it to a new (not yet created) repository path:
|
||||
|
||||
```yaml
|
||||
location:
|
||||
repositories:
|
||||
- upgraded.borg
|
||||
- path: upgraded.borg
|
||||
```
|
||||
|
||||
Then, run the `rcreate` action (formerly `init`) to create that new Borg 2
|
||||
|
||||
@@ -7,8 +7,10 @@ eleventyNavigation:
|
||||
---
|
||||
## borgmatic options
|
||||
|
||||
Here are all of the available borgmatic command-line options. This includes the separate options for
|
||||
each action sub-command:
|
||||
Here are all of the available borgmatic command-line options, including the
|
||||
separate options for each action sub-command. Note that most of the
|
||||
flags listed here do not have equivalents in borgmatic's [configuration
|
||||
file](https://torsion.org/borgmatic/docs/reference/configuration/).
|
||||
|
||||
```
|
||||
{% include borgmatic/command-line.txt %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script is for running all tests, including end-to-end tests, on a developer machine. It sets
|
||||
# up database containers to run tests against, runs the tests, and then tears down the containers.
|
||||
# This script is for running end-to-end tests on a developer machine. It sets up database containers
|
||||
# to run tests against, runs the tests, and then tears down the containers.
|
||||
#
|
||||
# Run this script from the root directory of the borgmatic source.
|
||||
#
|
||||
@@ -10,5 +10,11 @@
|
||||
|
||||
set -e
|
||||
|
||||
USER_PODMAN_SOCKET_PATH=/run/user/$UID/podman/podman.sock
|
||||
|
||||
if [ -e "$USER_PODMAN_SOCKET_PATH" ]; then
|
||||
export DOCKER_HOST="unix://$USER_PODMAN_SOCKET_PATH"
|
||||
fi
|
||||
|
||||
docker-compose --file tests/end-to-end/docker-compose.yaml up --force-recreate \
|
||||
--renew-anon-volumes --abort-on-container-exit
|
||||
|
||||
@@ -8,7 +8,14 @@
|
||||
# For more information, see:
|
||||
# https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
|
||||
|
||||
set -ex
|
||||
set -e
|
||||
|
||||
if [ -z "$TEST_CONTAINER" ] ; then
|
||||
echo "This script is designed to work inside a test container and is not intended to"
|
||||
echo "be run manually. If you're trying to run borgmatic's end-to-end tests, execute"
|
||||
echo "scripts/run-end-to-end-dev-tests instead."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
apk add --no-cache python3 py3-pip borgbackup postgresql-client mariadb-client mongodb-tools \
|
||||
py3-ruamel.yaml py3-ruamel.yaml.clib bash sqlite
|
||||
|
||||
@@ -20,3 +20,6 @@ known_first_party = borgmatic
|
||||
line_length = 100
|
||||
multi_line_output = 3
|
||||
skip = .tox
|
||||
|
||||
[codespell]
|
||||
skip = .git,.tox,build
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
VERSION = '1.7.10'
|
||||
VERSION = '1.7.12'
|
||||
|
||||
|
||||
setup(
|
||||
|
||||
@@ -2,6 +2,7 @@ appdirs==1.4.4; python_version >= '3.8'
|
||||
attrs==20.3.0; python_version >= '3.8'
|
||||
black==19.10b0; python_version >= '3.8'
|
||||
click==7.1.2; python_version >= '3.8'
|
||||
codespell==2.2.4
|
||||
colorama==0.4.4
|
||||
coverage==5.3
|
||||
flake8==4.0.1
|
||||
|
||||
@@ -1,22 +1,24 @@
|
||||
version: '3'
|
||||
services:
|
||||
postgresql:
|
||||
image: postgres:13.1-alpine
|
||||
image: docker.io/postgres:13.1-alpine
|
||||
environment:
|
||||
POSTGRES_PASSWORD: test
|
||||
POSTGRES_DB: test
|
||||
mysql:
|
||||
image: mariadb:10.5
|
||||
image: docker.io/mariadb:10.5
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: test
|
||||
MYSQL_DATABASE: test
|
||||
mongodb:
|
||||
image: mongo:5.0.5
|
||||
image: docker.io/mongo:5.0.5
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: root
|
||||
MONGO_INITDB_ROOT_PASSWORD: test
|
||||
tests:
|
||||
image: alpine:3.13
|
||||
image: docker.io/alpine:3.13
|
||||
environment:
|
||||
TEST_CONTAINER: true
|
||||
volumes:
|
||||
- "../..:/app:ro"
|
||||
tmpfs:
|
||||
@@ -28,3 +30,4 @@ services:
|
||||
depends_on:
|
||||
- postgresql
|
||||
- mysql
|
||||
- mongodb
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
@@ -26,3 +27,16 @@ def test_validate_config_command_with_invalid_configuration_fails():
|
||||
exit_code = subprocess.call(f'validate-borgmatic-config --config {config_path}'.split(' '))
|
||||
|
||||
assert exit_code == 1
|
||||
|
||||
|
||||
def test_validate_config_command_with_show_flag_displays_configuration():
|
||||
with tempfile.TemporaryDirectory() as temporary_directory:
|
||||
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||
|
||||
subprocess.check_call(f'generate-borgmatic-config --destination {config_path}'.split(' '))
|
||||
output = subprocess.check_output(
|
||||
f'validate-borgmatic-config --config {config_path} --show'.split(' ')
|
||||
).decode(sys.stdout.encoding)
|
||||
|
||||
assert 'location:' in output
|
||||
assert 'repositories:' in output
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import copy
|
||||
|
||||
import flexmock
|
||||
|
||||
import borgmatic.borg.info
|
||||
import borgmatic.borg.list
|
||||
import borgmatic.borg.rlist
|
||||
import borgmatic.borg.transfer
|
||||
import borgmatic.commands.arguments
|
||||
|
||||
|
||||
def assert_command_does_not_duplicate_flags(command, *args, **kwargs):
|
||||
'''
|
||||
Assert that the given Borg command sequence does not contain any duplicated flags, e.g.
|
||||
"--match-archives" twice anywhere in the command.
|
||||
'''
|
||||
flag_counts = {}
|
||||
|
||||
for flag_name in command:
|
||||
if not flag_name.startswith('--'):
|
||||
continue
|
||||
|
||||
if flag_name in flag_counts:
|
||||
flag_counts[flag_name] += 1
|
||||
else:
|
||||
flag_counts[flag_name] = 1
|
||||
|
||||
assert flag_counts == {
|
||||
flag_name: 1 for flag_name in flag_counts
|
||||
}, f"Duplicate flags found in: {' '.join(command)}"
|
||||
|
||||
|
||||
def fuzz_argument(arguments, argument_name):
|
||||
'''
|
||||
Given an argparse.Namespace instance of arguments and an argument name in it, copy the arguments
|
||||
namespace and set the argument name in the copy with a fake value. Return the copied arguments.
|
||||
|
||||
This is useful for "fuzzing" a unit under test by passing it each possible argument in turn,
|
||||
making sure it doesn't blow up or duplicate Borg arguments.
|
||||
'''
|
||||
arguments_copy = copy.copy(arguments)
|
||||
value = getattr(arguments_copy, argument_name)
|
||||
setattr(arguments_copy, argument_name, not value if isinstance(value, bool) else 'value')
|
||||
|
||||
return arguments_copy
|
||||
|
||||
|
||||
def test_transfer_archives_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments(
|
||||
'transfer', '--source-repository', 'foo'
|
||||
)['transfer']
|
||||
flexmock(borgmatic.borg.transfer).should_receive('execute_command').replace_with(
|
||||
assert_command_does_not_duplicate_flags
|
||||
)
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
borgmatic.borg.transfer.transfer_archives(
|
||||
False, 'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
)
|
||||
|
||||
|
||||
def test_make_list_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments('list')['list']
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
command = borgmatic.borg.list.make_list_command(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
)
|
||||
|
||||
assert_command_does_not_duplicate_flags(command)
|
||||
|
||||
|
||||
def test_make_rlist_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments('rlist')['rlist']
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
command = borgmatic.borg.rlist.make_rlist_command(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
)
|
||||
|
||||
assert_command_does_not_duplicate_flags(command)
|
||||
|
||||
|
||||
def test_display_archives_info_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments('info')['info']
|
||||
flexmock(borgmatic.borg.info).should_receive('execute_command_and_capture_output').replace_with(
|
||||
assert_command_does_not_duplicate_flags
|
||||
)
|
||||
flexmock(borgmatic.borg.info).should_receive('execute_command').replace_with(
|
||||
assert_command_does_not_duplicate_flags
|
||||
)
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
borgmatic.borg.info.display_archives_info(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
)
|
||||
@@ -465,6 +465,20 @@ def test_parse_arguments_disallows_transfer_with_both_archive_and_match_archives
|
||||
)
|
||||
|
||||
|
||||
def test_parse_arguments_disallows_list_with_both_prefix_and_match_archives():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.parse_arguments('list', '--prefix', 'foo', '--match-archives', 'sh:*bar')
|
||||
|
||||
|
||||
def test_parse_arguments_disallows_rlist_with_both_prefix_and_match_archives():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.parse_arguments('rlist', '--prefix', 'foo', '--match-archives', 'sh:*bar')
|
||||
|
||||
|
||||
def test_parse_arguments_disallows_info_with_both_archive_and_match_archives():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
|
||||
@@ -18,3 +18,12 @@ def test_parse_arguments_with_multiple_config_paths_parses_as_list():
|
||||
parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
|
||||
|
||||
assert parser.config_paths == ['myconfig', 'otherconfig']
|
||||
|
||||
|
||||
def test_parse_arguments_supports_show_flag():
|
||||
config_paths = ['default']
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
||||
|
||||
parser = module.parse_arguments('--config', 'myconfig', '--show')
|
||||
|
||||
assert parser.show
|
||||
|
||||
@@ -2,7 +2,6 @@ import io
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
import ruamel.yaml
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.config import load as module
|
||||
@@ -150,6 +149,248 @@ def test_load_configuration_merges_include():
|
||||
assert module.load_configuration('config.yaml') == {'foo': 'override', 'baz': 'quux'}
|
||||
|
||||
|
||||
def test_load_configuration_with_retain_tag_merges_include_but_keeps_local_values():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
foo: bar
|
||||
baz: quux
|
||||
|
||||
other:
|
||||
a: b
|
||||
c: d
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff: !retain
|
||||
foo: override
|
||||
|
||||
other:
|
||||
a: override
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {
|
||||
'stuff': {'foo': 'override'},
|
||||
'other': {'a': 'override', 'c': 'd'},
|
||||
}
|
||||
|
||||
|
||||
def test_load_configuration_with_retain_tag_but_without_merge_include_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff: !retain
|
||||
foo: bar
|
||||
baz: quux
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
foo: override
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_retain_tag_on_scalar_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
foo: bar
|
||||
baz: quux
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
foo: !retain override
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_merges_include_and_omits_requested_values():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- !omit b
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {'stuff': ['a', 'c', 'x', 'y']}
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_unknown_value_merges_include_and_does_not_raise():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- !omit q
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {'stuff': ['a', 'b', 'c', 'x', 'y']}
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_non_list_item_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff: !omit
|
||||
- x
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_non_scalar_list_item_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- foo: bar
|
||||
baz: quux
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- !omit foo: bar
|
||||
baz: quux
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_but_without_merge_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- !omit b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_does_not_merge_include_list():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
@@ -173,42 +414,79 @@ def test_load_configuration_does_not_merge_include_list():
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ruamel.yaml.error.YAMLError):
|
||||
with pytest.raises(module.ruamel.yaml.error.YAMLError):
|
||||
assert module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'node_class',
|
||||
(
|
||||
module.ruamel.yaml.nodes.MappingNode,
|
||||
module.ruamel.yaml.nodes.SequenceNode,
|
||||
module.ruamel.yaml.nodes.ScalarNode,
|
||||
),
|
||||
)
|
||||
def test_raise_retain_node_error_raises(node_class):
|
||||
with pytest.raises(ValueError):
|
||||
module.raise_retain_node_error(
|
||||
loader=flexmock(), node=node_class(tag=flexmock(), value=flexmock())
|
||||
)
|
||||
|
||||
|
||||
def test_raise_omit_node_error_raises():
|
||||
with pytest.raises(ValueError):
|
||||
module.raise_omit_node_error(loader=flexmock(), node=flexmock())
|
||||
|
||||
|
||||
def test_filter_omitted_nodes():
|
||||
nodes = [
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='a'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='b'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='c'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='a'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='!omit', value='b'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='c'),
|
||||
]
|
||||
|
||||
result = module.filter_omitted_nodes(nodes)
|
||||
|
||||
assert [item.value for item in result] == ['a', 'c', 'a', 'c']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_replaces_colliding_scalar_values():
|
||||
node_values = [
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_hourly'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='24'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:int', value='24'
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_daily'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='7'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='7'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_daily'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='5'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='5'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -230,35 +508,39 @@ def test_deep_merge_nodes_replaces_colliding_scalar_values():
|
||||
def test_deep_merge_nodes_keeps_non_colliding_scalar_values():
|
||||
node_values = [
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_hourly'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='24'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:int', value='24'
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_daily'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='7'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='7'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_minutely'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='10'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:int', value='10'
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -282,28 +564,28 @@ def test_deep_merge_nodes_keeps_non_colliding_scalar_values():
|
||||
def test_deep_merge_nodes_keeps_deeply_nested_values():
|
||||
node_values = [
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='storage'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='storage'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='lock_wait'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='5'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='5'),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='extra_borg_options'
|
||||
),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='init'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='--init-option'
|
||||
),
|
||||
),
|
||||
@@ -314,22 +596,22 @@ def test_deep_merge_nodes_keeps_deeply_nested_values():
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='storage'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='storage'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='extra_borg_options'
|
||||
),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='prune'
|
||||
),
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='--prune-option'
|
||||
),
|
||||
),
|
||||
@@ -361,32 +643,48 @@ def test_deep_merge_nodes_keeps_deeply_nested_values():
|
||||
def test_deep_merge_nodes_appends_colliding_sequence_values():
|
||||
node_values = [
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:int', value=['echo 1', 'echo 2']
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
ruamel.yaml.nodes.MappingNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
ruamel.yaml.nodes.ScalarNode(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:int', value=['echo 3', 'echo 4']
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 4'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -401,4 +699,178 @@ def test_deep_merge_nodes_appends_colliding_sequence_values():
|
||||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert options[0][1].value == ['echo 1', 'echo 2', 'echo 3', 'echo 4']
|
||||
assert [item.value for item in options[0][1].value] == ['echo 1', 'echo 2', 'echo 3', 'echo 4']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_only_keeps_mapping_values_tagged_with_retain():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_hourly'
|
||||
),
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:int', value='24'
|
||||
),
|
||||
),
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_daily'
|
||||
),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='7'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='!retain',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='keep_daily'
|
||||
),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:int', value='5'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
result = module.deep_merge_nodes(node_values)
|
||||
assert len(result) == 1
|
||||
(section_key, section_value) = result[0]
|
||||
assert section_key.value == 'retention'
|
||||
assert section_value.tag == 'tag:yaml.org,2002:map'
|
||||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'keep_daily'
|
||||
assert options[0][1].value == '5'
|
||||
|
||||
|
||||
def test_deep_merge_nodes_only_keeps_sequence_values_tagged_with_retain():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='!retain',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 4'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
result = module.deep_merge_nodes(node_values)
|
||||
assert len(result) == 1
|
||||
(section_key, section_value) = result[0]
|
||||
assert section_key.value == 'hooks'
|
||||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert options[0][1].tag == 'tag:yaml.org,2002:seq'
|
||||
assert [item.value for item in options[0][1].value] == ['echo 3', 'echo 4']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_skips_sequence_values_tagged_with_omit():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(tag='!omit', value='echo 2'),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
result = module.deep_merge_nodes(node_values)
|
||||
assert len(result) == 1
|
||||
(section_key, section_value) = result[0]
|
||||
assert section_key.value == 'hooks'
|
||||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert [item.value for item in options[0][1].value] == ['echo 1', 'echo 3']
|
||||
|
||||
@@ -8,7 +8,7 @@ from flexmock import flexmock
|
||||
from borgmatic.config import validate as module
|
||||
|
||||
|
||||
def test_schema_filename_returns_plausable_path():
|
||||
def test_schema_filename_returns_plausible_path():
|
||||
schema_path = module.schema_filename()
|
||||
|
||||
assert schema_path.endswith('/schema.yaml')
|
||||
|
||||
@@ -147,7 +147,7 @@ def test_log_outputs_kills_other_processes_when_one_errors():
|
||||
['sleep', '2'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
)
|
||||
flexmock(module).should_receive('exit_code_indicates_error').with_args(
|
||||
other_process, None, 'borg'
|
||||
['sleep', '2'], None, 'borg'
|
||||
).and_return(False)
|
||||
flexmock(module).should_receive('output_buffer_for_process').with_args(process, ()).and_return(
|
||||
process.stdout
|
||||
|
||||
@@ -10,7 +10,7 @@ def test_run_transfer_does_not_raise():
|
||||
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
|
||||
|
||||
module.run_transfer(
|
||||
repository='repo',
|
||||
repository={'path': 'repo'},
|
||||
storage={},
|
||||
local_borg_version=None,
|
||||
transfer_arguments=transfer_arguments,
|
||||
|
||||
@@ -189,150 +189,170 @@ def test_filter_checks_on_frequency_restains_check_with_unelapsed_frequency_and_
|
||||
|
||||
def test_make_check_flags_with_repository_check_returns_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository',))
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',))
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_returns_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('archives',))
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',))
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_returns_flag_and_implies_archives():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('data',))
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',))
|
||||
|
||||
assert flags == ('--archives-only', '--verify-data',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_extract_omits_extract_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('extract',))
|
||||
flags = module.make_check_flags('1.2.3', {}, ('extract',))
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_and_data_checks_does_not_return_repository_only():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository', 'data',))
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'data',))
|
||||
|
||||
assert flags == ('--verify-data',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_default_prefix_returns_default_flags():
|
||||
def test_make_check_flags_with_default_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), prefix='foo',)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', ('repository', 'archives'), prefix=module.DEFAULT_PREFIX
|
||||
'1.2.3', {}, ('repository', 'archives', 'extract'), prefix='foo',
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', f'sh:{module.DEFAULT_PREFIX}*')
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_and_default_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', ('repository', 'archives', 'extract'), prefix=module.DEFAULT_PREFIX
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', f'sh:{module.DEFAULT_PREFIX}*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_and_default_prefix_without_borg_features_returns_glob_archives_flags():
|
||||
def test_make_check_flags_with_all_checks_and_prefix_without_borg_features_returns_glob_archives_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', ('repository', 'archives', 'extract'), prefix=module.DEFAULT_PREFIX
|
||||
'1.2.3', {}, ('repository', 'archives', 'extract'), prefix='foo',
|
||||
)
|
||||
|
||||
assert flags == ('--glob-archives', f'{module.DEFAULT_PREFIX}*')
|
||||
assert flags == ('--glob-archives', 'foo*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('archives',), check_last=3)
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), check_last=3)
|
||||
|
||||
assert flags == ('--archives-only', '--last', '3')
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('data',), check_last=3)
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',), check_last=3)
|
||||
|
||||
assert flags == ('--archives-only', '--last', '3', '--verify-data')
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_last_omits_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository',), check_last=3)
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',), check_last=3)
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository', 'archives'), check_last=3)
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('archives',), prefix='foo-')
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), prefix='foo-')
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('data',), prefix='foo-')
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',), prefix='foo-')
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*', '--verify-data')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_empty_prefix_omits_match_archives_flag():
|
||||
def test_make_check_flags_with_archives_check_and_empty_prefix_uses_archive_name_format_instead():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('archives',), prefix='')
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', {'archive_name_format': 'bar-{now}'}, ('archives',), prefix='' # noqa: FS003
|
||||
)
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:bar-*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_none_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('archives',), prefix=None)
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), prefix=None)
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository',), prefix='foo-')
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',), prefix='foo-')
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', ('repository', 'archives'), prefix='foo-')
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), prefix='foo-')
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
|
||||
@@ -427,7 +447,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', checks, check_last, module.DEFAULT_PREFIX
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
@@ -581,7 +601,7 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', checks, check_last, module.DEFAULT_PREFIX
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
||||
@@ -608,7 +628,7 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', checks, check_last, module.DEFAULT_PREFIX
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
|
||||
@@ -628,6 +648,7 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
|
||||
def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
storage_config = {'lock_wait': 5}
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
@@ -635,7 +656,7 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', checks, check_last, module.DEFAULT_PREFIX
|
||||
'1.2.3', storage_config, checks, check_last, None,
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
|
||||
@@ -645,7 +666,7 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
location_config={},
|
||||
storage_config={'lock_wait': 5},
|
||||
storage_config=storage_config,
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
)
|
||||
@@ -662,7 +683,7 @@ def test_check_archives_with_retention_prefix():
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', checks, check_last, prefix
|
||||
'1.2.3', {}, checks, check_last, prefix
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import flags as module
|
||||
@@ -78,3 +79,52 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
|
||||
assert module.make_repository_archive_flags(
|
||||
repository_path='repo', archive='archive', local_borg_version='1.2.3'
|
||||
) == ('repo::archive',)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'match_archives, archive_name_format,feature_available,expected_result',
|
||||
(
|
||||
(None, None, True, ()),
|
||||
(None, '', True, ()),
|
||||
('re:foo-.*', '{hostname}-{now}', True, ('--match-archives', 're:foo-.*'),), # noqa: FS003
|
||||
('sh:foo-*', '{hostname}-{now}', False, ('--glob-archives', 'foo-*'),), # noqa: FS003
|
||||
('foo-*', '{hostname}-{now}', False, ('--glob-archives', 'foo-*'),), # noqa: FS003
|
||||
(
|
||||
None,
|
||||
'{hostname}-docs-{now}', # noqa: FS003
|
||||
True,
|
||||
('--match-archives', 'sh:{hostname}-docs-*'), # noqa: FS003
|
||||
),
|
||||
(
|
||||
None,
|
||||
'{utcnow}-docs-{user}', # noqa: FS003
|
||||
True,
|
||||
('--match-archives', 'sh:*-docs-{user}'), # noqa: FS003
|
||||
),
|
||||
(None, '{fqdn}-{pid}', True, ('--match-archives', 'sh:{fqdn}-*')), # noqa: FS003
|
||||
(
|
||||
None,
|
||||
'stuff-{now:%Y-%m-%dT%H:%M:%S.%f}', # noqa: FS003
|
||||
True,
|
||||
('--match-archives', 'sh:stuff-*'),
|
||||
),
|
||||
(
|
||||
None,
|
||||
'{hostname}-docs-{now}', # noqa: FS003
|
||||
False,
|
||||
('--glob-archives', '{hostname}-docs-*'), # noqa: FS003
|
||||
),
|
||||
(None, '{utcnow}-docs-{user}', False, ('--glob-archives', '*-docs-{user}')), # noqa: FS003
|
||||
),
|
||||
)
|
||||
def test_make_match_archives_flags_makes_flags_with_globs(
|
||||
match_archives, archive_name_format, feature_available, expected_result
|
||||
):
|
||||
flexmock(module.feature).should_receive('available').and_return(feature_available)
|
||||
|
||||
assert (
|
||||
module.make_match_archives_flags(
|
||||
match_archives, archive_name_format, local_borg_version=flexmock()
|
||||
)
|
||||
== expected_result
|
||||
)
|
||||
|
||||
+157
-16
@@ -12,6 +12,9 @@ def test_display_archives_info_calls_borg_with_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -26,7 +29,7 @@ def test_display_archives_info_calls_borg_with_parameters():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
@@ -34,6 +37,9 @@ def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -48,7 +54,7 @@ def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
@@ -56,6 +62,9 @@ def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_outpu
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -68,7 +77,7 @@ def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_outpu
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
@@ -78,6 +87,9 @@ def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -93,7 +105,7 @@ def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
@@ -101,6 +113,9 @@ def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_outp
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -113,7 +128,7 @@ def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_outp
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
@@ -123,6 +138,9 @@ def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -134,7 +152,7 @@ def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
@@ -144,14 +162,14 @@ def test_display_archives_info_with_archive_calls_borg_with_match_archives_param
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'match-archives', 'archive'
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'archive', None, '2.3.4'
|
||||
).and_return(('--match-archives', 'archive'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--repo', 'repo', '--match-archives', 'archive'),
|
||||
('borg', 'info', '--match-archives', 'archive', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
@@ -161,7 +179,7 @@ def test_display_archives_info_with_archive_calls_borg_with_match_archives_param
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive='archive', json=False, prefix=None),
|
||||
info_arguments=flexmock(archive='archive', json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
@@ -169,6 +187,9 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -183,7 +204,7 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
@@ -195,6 +216,9 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'remote-path', 'borg1'
|
||||
).and_return(('--remote-path', 'borg1'))
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -209,7 +233,7 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
@@ -221,6 +245,9 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('lock-wait', 5).and_return(
|
||||
('--lock-wait', '5')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
storage_config = {'lock_wait': 5}
|
||||
@@ -236,17 +263,20 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete
|
||||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_prefix_calls_borg_with_match_archives_parameters():
|
||||
def test_display_archives_info_transforms_prefix_into_match_archives_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'match-archives', 'sh:foo*'
|
||||
).and_return(('--match-archives', 'sh:foo*'))
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -265,12 +295,121 @@ def test_display_archives_info_with_prefix_calls_borg_with_match_archives_parame
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argument_name', ('match_archives', 'sort_by', 'first', 'last'))
|
||||
def test_display_archives_info_prefers_prefix_over_archive_name_format():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'match-archives', 'sh:foo*'
|
||||
).and_return(('--match-archives', 'sh:foo*'))
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--match-archives', 'sh:foo*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix='foo'),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_transforms_archive_name_format_into_match_archives_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_with_match_archives_option_calls_borg_with_match_archives_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'sh:foo-*', 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:foo-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={
|
||||
'archive_name_format': 'bar-{now}', # noqa: FS003
|
||||
'match_archives': 'sh:foo-*',
|
||||
},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_with_match_archives_flag_calls_borg_with_match_archives_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'sh:foo-*', 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:foo-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--match-archives', 'sh:foo-*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives='sh:foo-*'),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argument_name', ('sort_by', 'first', 'last'))
|
||||
def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flag_name = f"--{argument_name.replace('_', ' ')}"
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
(flag_name, 'value')
|
||||
)
|
||||
@@ -287,5 +426,7 @@ def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, **{argument_name: 'value'}),
|
||||
info_arguments=flexmock(
|
||||
archive=None, json=False, prefix=None, match_archives=None, **{argument_name: 'value'}
|
||||
),
|
||||
)
|
||||
|
||||
@@ -18,18 +18,17 @@ def insert_execute_command_mock(prune_command, output_log_level):
|
||||
).once()
|
||||
|
||||
|
||||
BASE_PRUNE_FLAGS = (('--keep-daily', '1'), ('--keep-weekly', '2'), ('--keep-monthly', '3'))
|
||||
BASE_PRUNE_FLAGS = ('--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
||||
|
||||
|
||||
def test_make_prune_flags_returns_flags_from_config_plus_default_prefix_glob():
|
||||
def test_make_prune_flags_returns_flags_from_config():
|
||||
retention_config = OrderedDict((('keep_daily', 1), ('keep_weekly', 2), ('keep_monthly', 3)))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
||||
result = module.make_prune_flags({}, retention_config, local_borg_version='1.2.3')
|
||||
|
||||
assert tuple(result) == BASE_PRUNE_FLAGS + (
|
||||
('--match-archives', 'sh:{hostname}-*'), # noqa: FS003
|
||||
)
|
||||
assert result == BASE_PRUNE_FLAGS
|
||||
|
||||
|
||||
def test_make_prune_flags_accepts_prefix_with_placeholders():
|
||||
@@ -37,15 +36,18 @@ def test_make_prune_flags_accepts_prefix_with_placeholders():
|
||||
(('keep_daily', 1), ('prefix', 'Documents_{hostname}-{now}')) # noqa: FS003
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
||||
result = module.make_prune_flags({}, retention_config, local_borg_version='1.2.3')
|
||||
|
||||
expected = (
|
||||
('--keep-daily', '1'),
|
||||
('--match-archives', 'sh:Documents_{hostname}-{now}*'), # noqa: FS003
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--match-archives',
|
||||
'sh:Documents_{hostname}-{now}*', # noqa: FS003
|
||||
)
|
||||
|
||||
assert tuple(result) == expected
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives():
|
||||
@@ -53,37 +55,56 @@ def test_make_prune_flags_with_prefix_without_borg_features_uses_glob_archives()
|
||||
(('keep_daily', 1), ('prefix', 'Documents_{hostname}-{now}')) # noqa: FS003
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
||||
result = module.make_prune_flags({}, retention_config, local_borg_version='1.2.3')
|
||||
|
||||
expected = (
|
||||
('--keep-daily', '1'),
|
||||
('--glob-archives', 'Documents_{hostname}-{now}*'), # noqa: FS003
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--glob-archives',
|
||||
'Documents_{hostname}-{now}*', # noqa: FS003
|
||||
)
|
||||
|
||||
assert tuple(result) == expected
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_make_prune_flags_treats_empty_prefix_as_no_prefix():
|
||||
retention_config = OrderedDict((('keep_daily', 1), ('prefix', '')))
|
||||
def test_make_prune_flags_prefers_prefix_to_archive_name_format():
|
||||
storage_config = {'archive_name_format': 'bar-{now}'} # noqa: FS003
|
||||
retention_config = OrderedDict((('keep_daily', 1), ('prefix', 'bar-')))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').never()
|
||||
|
||||
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
||||
result = module.make_prune_flags(storage_config, retention_config, local_borg_version='1.2.3')
|
||||
|
||||
expected = (('--keep-daily', '1'),)
|
||||
expected = (
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--match-archives',
|
||||
'sh:bar-*', # noqa: FS003
|
||||
)
|
||||
|
||||
assert tuple(result) == expected
|
||||
assert result == expected
|
||||
|
||||
|
||||
def test_make_prune_flags_treats_none_prefix_as_no_prefix():
|
||||
def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
|
||||
storage_config = {'archive_name_format': 'bar-{now}'} # noqa: FS003
|
||||
retention_config = OrderedDict((('keep_daily', 1), ('prefix', None)))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
|
||||
result = module.make_prune_flags(retention_config, local_borg_version='1.2.3')
|
||||
result = module.make_prune_flags(storage_config, retention_config, local_borg_version='1.2.3')
|
||||
|
||||
expected = (('--keep-daily', '1'),)
|
||||
expected = (
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--match-archives',
|
||||
'sh:bar-*', # noqa: FS003
|
||||
)
|
||||
|
||||
assert tuple(result) == expected
|
||||
assert result == expected
|
||||
|
||||
|
||||
PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
||||
|
||||
+129
-19
@@ -127,6 +127,9 @@ def test_resolve_archive_name_with_lock_wait_calls_borg_with_lock_wait_parameter
|
||||
def test_make_rlist_command_includes_log_info():
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -134,7 +137,9 @@ def test_make_rlist_command_includes_log_info():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--info', 'repo')
|
||||
@@ -143,6 +148,9 @@ def test_make_rlist_command_includes_log_info():
|
||||
def test_make_rlist_command_includes_json_but_not_info():
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -150,7 +158,9 @@ def test_make_rlist_command_includes_json_but_not_info():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
@@ -159,6 +169,9 @@ def test_make_rlist_command_includes_json_but_not_info():
|
||||
def test_make_rlist_command_includes_log_debug():
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -166,7 +179,9 @@ def test_make_rlist_command_includes_log_debug():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
||||
@@ -175,6 +190,9 @@ def test_make_rlist_command_includes_log_debug():
|
||||
def test_make_rlist_command_includes_json_but_not_debug():
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -182,7 +200,9 @@ def test_make_rlist_command_includes_json_but_not_debug():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
@@ -190,6 +210,9 @@ def test_make_rlist_command_includes_json_but_not_debug():
|
||||
|
||||
def test_make_rlist_command_includes_json():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--json',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -197,7 +220,9 @@ def test_make_rlist_command_includes_json():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=True, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
@@ -207,6 +232,9 @@ def test_make_rlist_command_includes_lock_wait():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
||||
('--lock-wait', '5')
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -214,7 +242,9 @@ def test_make_rlist_command_includes_lock_wait():
|
||||
repository_path='repo',
|
||||
storage_config={'lock_wait': 5},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
||||
@@ -222,6 +252,9 @@ def test_make_rlist_command_includes_lock_wait():
|
||||
|
||||
def test_make_rlist_command_includes_local_path():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -229,7 +262,9 @@ def test_make_rlist_command_includes_local_path():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
@@ -240,6 +275,9 @@ def test_make_rlist_command_includes_remote_path():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(
|
||||
('--remote-path', 'borg2')
|
||||
).and_return(()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -247,7 +285,9 @@ def test_make_rlist_command_includes_remote_path():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
@@ -258,6 +298,9 @@ def test_make_rlist_command_transforms_prefix_into_match_archives():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(()).and_return(
|
||||
('--match-archives', 'sh:foo*')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -271,8 +314,49 @@ def test_make_rlist_command_transforms_prefix_into_match_archives():
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_prefers_prefix_over_archive_name_format():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(()).and_return(
|
||||
('--match-archives', 'sh:foo*')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').never()
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_rlist_command(
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix='foo'),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_transforms_archive_name_format_into_match_archives():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_rlist_command(
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:bar-*', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_includes_short():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--short',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
@@ -280,7 +364,9 @@ def test_make_rlist_command_includes_short():
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix=None, short=True),
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None, short=True
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--short', 'repo')
|
||||
@@ -288,19 +374,13 @@ def test_make_rlist_command_includes_short():
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'argument_name',
|
||||
(
|
||||
'match_archives',
|
||||
'sort_by',
|
||||
'first',
|
||||
'last',
|
||||
'exclude',
|
||||
'exclude_from',
|
||||
'pattern',
|
||||
'patterns_from',
|
||||
),
|
||||
('sort_by', 'first', 'last', 'exclude', 'exclude_from', 'pattern', 'patterns_from',),
|
||||
)
|
||||
def test_make_rlist_command_includes_additional_flags(argument_name):
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
(f"--{argument_name.replace('_', '-')}", 'value')
|
||||
)
|
||||
@@ -315,6 +395,7 @@ def test_make_rlist_command_includes_additional_flags(argument_name):
|
||||
paths=None,
|
||||
json=False,
|
||||
prefix=None,
|
||||
match_archives=None,
|
||||
find_paths=None,
|
||||
format=None,
|
||||
**{argument_name: 'value'},
|
||||
@@ -324,6 +405,35 @@ def test_make_rlist_command_includes_additional_flags(argument_name):
|
||||
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_with_match_archives_calls_borg_with_match_archives_parameters():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'foo-*', None, '1.2.3',
|
||||
).and_return(('--match-archives', 'foo-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_rlist_command(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(
|
||||
archive=None,
|
||||
paths=None,
|
||||
json=False,
|
||||
prefix=None,
|
||||
match_archives='foo-*',
|
||||
find_paths=None,
|
||||
format=None,
|
||||
),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'foo-*', 'repo')
|
||||
|
||||
|
||||
def test_list_repository_calls_borg_with_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
|
||||
@@ -12,6 +12,7 @@ def test_transfer_archives_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -41,6 +42,7 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('dry-run', True).and_return(
|
||||
('--dry-run',)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -67,6 +69,7 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -93,6 +96,7 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -120,8 +124,8 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'match-archives', 'archive'
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'archive', 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'archive'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
@@ -137,7 +141,7 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag():
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive='archive', progress=None, match_archives=None, source_repository=None
|
||||
@@ -149,8 +153,8 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'match-archives', 'sh:foo*'
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'sh:foo*', 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:foo*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
@@ -166,7 +170,7 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives='sh:foo*', source_repository=None
|
||||
@@ -174,10 +178,40 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_archive_name_format_calls_borg_with_match_archives_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '2.3.4' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--match-archives', 'sh:bar-*', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_local_path_calls_borg_via_local_path():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -208,6 +242,7 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'remote-path', 'borg2'
|
||||
).and_return(('--remote-path', 'borg2'))
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
@@ -238,6 +273,7 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('lock-wait', 5).and_return(
|
||||
('--lock-wait', '5')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
storage_config = {'lock_wait': 5}
|
||||
@@ -265,7 +301,8 @@ def test_transfer_archives_with_progress_calls_borg_with_progress_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(('--progress',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
@@ -293,6 +330,7 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flag_name = f"--{argument_name.replace('_', ' ')}"
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
(flag_name, 'value')
|
||||
)
|
||||
@@ -327,6 +365,7 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('other-repo', 'other').and_return(
|
||||
('--other-repo', 'other')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
|
||||
@@ -408,7 +408,7 @@ def test_run_actions_runs_rcreate():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'rcreate': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'rcreate': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -423,6 +423,43 @@ def test_run_actions_runs_rcreate():
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_adds_log_file_to_hook_context():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.command).should_receive('execute_hook')
|
||||
expected = flexmock()
|
||||
flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
|
||||
config_filename=object,
|
||||
repository={'path': 'repo'},
|
||||
location={'repositories': []},
|
||||
storage=object,
|
||||
hooks={},
|
||||
hook_context={'repository': 'repo', 'repositories': '', 'log_file': 'foo'},
|
||||
local_borg_version=object,
|
||||
create_arguments=object,
|
||||
global_arguments=object,
|
||||
dry_run_label='',
|
||||
local_path=object,
|
||||
remote_path=object,
|
||||
).once().and_return(expected)
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
retention=flexmock(),
|
||||
consistency=flexmock(),
|
||||
hooks={},
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo'},
|
||||
)
|
||||
)
|
||||
assert result == (expected,)
|
||||
|
||||
|
||||
def test_run_actions_runs_transfer():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.command).should_receive('execute_hook')
|
||||
@@ -430,7 +467,7 @@ def test_run_actions_runs_transfer():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'transfer': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'transfer': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -453,7 +490,7 @@ def test_run_actions_runs_create():
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'create': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -476,7 +513,7 @@ def test_run_actions_runs_prune():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'prune': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'prune': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -498,7 +535,7 @@ def test_run_actions_runs_compact():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'compact': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'compact': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -521,7 +558,7 @@ def test_run_actions_runs_check_when_repository_enabled_for_checks():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'check': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'check': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -544,7 +581,7 @@ def test_run_actions_skips_check_when_repository_not_enabled_for_checks():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'check': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'check': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -566,7 +603,7 @@ def test_run_actions_runs_extract():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'extract': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'extract': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -588,7 +625,7 @@ def test_run_actions_runs_export_tar():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'export-tar': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'export-tar': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -610,7 +647,7 @@ def test_run_actions_runs_mount():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'mount': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'mount': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -632,7 +669,7 @@ def test_run_actions_runs_restore():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'restore': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'restore': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -655,7 +692,7 @@ def test_run_actions_runs_rlist():
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'rlist': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'rlist': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -679,7 +716,7 @@ def test_run_actions_runs_list():
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'list': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'list': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -703,7 +740,7 @@ def test_run_actions_runs_rinfo():
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'rinfo': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'rinfo': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -727,7 +764,7 @@ def test_run_actions_runs_info():
|
||||
|
||||
result = tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'info': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'info': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -750,7 +787,7 @@ def test_run_actions_runs_break_lock():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'break-lock': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'break-lock': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -772,7 +809,7 @@ def test_run_actions_runs_borg():
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False), 'borg': flexmock()},
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'borg': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
location={'repositories': []},
|
||||
storage=flexmock(),
|
||||
@@ -796,7 +833,7 @@ def test_run_actions_runs_multiple_actions_in_argument_order():
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={
|
||||
'global': flexmock(dry_run=False),
|
||||
'global': flexmock(dry_run=False, log_file='foo'),
|
||||
'borg': flexmock(),
|
||||
'restore': flexmock(),
|
||||
},
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_validation_error_string_contains_errors():
|
||||
assert 'uh oh' in result
|
||||
|
||||
|
||||
def test_apply_locical_validation_raises_if_unknown_repository_in_check_repositories():
|
||||
def test_apply_logical_validation_raises_if_unknown_repository_in_check_repositories():
|
||||
flexmock(module).format_json_error = lambda error: error.message
|
||||
|
||||
with pytest.raises(module.Validation_error):
|
||||
@@ -51,17 +51,33 @@ def test_apply_locical_validation_raises_if_unknown_repository_in_check_reposito
|
||||
)
|
||||
|
||||
|
||||
def test_apply_locical_validation_does_not_raise_if_known_repository_in_check_repositories():
|
||||
def test_apply_logical_validation_does_not_raise_if_known_repository_path_in_check_repositories():
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'location': {'repositories': ['repo.borg', 'other.borg']},
|
||||
'location': {'repositories': [{'path': 'repo.borg'}, {'path': 'other.borg'}]},
|
||||
'retention': {'keep_secondly': 1000},
|
||||
'consistency': {'check_repositories': ['repo.borg']},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_if_known_repository_label_in_check_repositories():
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'location': {
|
||||
'repositories': [
|
||||
{'path': 'repo.borg', 'label': 'my_repo'},
|
||||
{'path': 'other.borg', 'label': 'other_repo'},
|
||||
]
|
||||
},
|
||||
'retention': {'keep_secondly': 1000},
|
||||
'consistency': {'check_repositories': ['my_repo']},
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_if_archive_name_format_and_prefix_present():
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
|
||||
@@ -285,7 +285,7 @@ def test_configure_logging_skips_syslog_if_interactive_console():
|
||||
module.configure_logging(console_log_level=logging.INFO)
|
||||
|
||||
|
||||
def test_configure_logging_to_logfile_instead_of_syslog():
|
||||
def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(
|
||||
@@ -309,7 +309,36 @@ def test_configure_logging_to_logfile_instead_of_syslog():
|
||||
)
|
||||
|
||||
|
||||
def test_configure_logging_skips_logfile_if_argument_is_none():
|
||||
def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module.logging).should_receive('Formatter').with_args(
|
||||
'{message}', style='{' # noqa: FS003
|
||||
).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(
|
||||
flexmock(setFormatter=lambda formatter: None, setLevel=lambda level: None)
|
||||
)
|
||||
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG, handlers=tuple
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/dev/log').and_return(True)
|
||||
flexmock(module.logging.handlers).should_receive('SysLogHandler').never()
|
||||
file_handler = logging.handlers.WatchedFileHandler('/tmp/logfile')
|
||||
flexmock(module.logging.handlers).should_receive('WatchedFileHandler').with_args(
|
||||
'/tmp/logfile'
|
||||
).and_return(file_handler).once()
|
||||
|
||||
module.configure_logging(
|
||||
console_log_level=logging.INFO,
|
||||
log_file_log_level=logging.DEBUG,
|
||||
log_file='/tmp/logfile',
|
||||
log_file_format='{message}', # noqa: FS003
|
||||
)
|
||||
|
||||
|
||||
def test_configure_logging_skips_log_file_if_argument_is_none():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(
|
||||
|
||||
@@ -16,6 +16,7 @@ commands =
|
||||
py38,py39,py310,py311: black --check .
|
||||
isort --check-only --settings-path setup.cfg .
|
||||
flake8 borgmatic tests
|
||||
codespell
|
||||
|
||||
[testenv:black]
|
||||
commands =
|
||||
@@ -35,3 +36,8 @@ commands =
|
||||
deps = {[testenv]deps}
|
||||
commands =
|
||||
isort --settings-path setup.cfg .
|
||||
|
||||
[testenv:codespell]
|
||||
deps = {[testenv]deps}
|
||||
commands =
|
||||
codespell --write-changes
|
||||
|
||||
Reference in New Issue
Block a user