mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-07-26 19:33:02 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1197d6d0f6 | ||
|
|
288a4bf243 | ||
|
|
1fb943e5f1 | ||
|
|
e0298685a1 | ||
|
|
c5633227bf | ||
|
|
6087c12e09 | ||
|
|
9d83f02e24 | ||
|
|
b6ccde6757 | ||
|
|
548aceb3d5 | ||
|
|
2bd63bbdd2 | ||
|
|
9b4fed64a6 | ||
|
|
ff1001a5f5 | ||
|
|
e7f1c3eda5 | ||
|
|
21e343a948 | ||
|
|
4c4fd92013 | ||
|
|
37735e464c | ||
|
|
424cc6b66c | ||
|
|
e128a3e0a9 | ||
|
|
27e7ece2f5 | ||
|
|
d44dc93509 | ||
|
|
31778fd3bf | ||
|
|
4313f90dd8 | ||
|
|
1f82ea2798 | ||
|
|
148536d867 | ||
|
|
197f0a521d | ||
|
|
0d8e352033 | ||
|
|
20a3995977 | ||
|
|
66aa953371 | ||
|
|
ba053de8f7 | ||
|
|
2f844d65d5 | ||
|
|
2dca5e1834 | ||
|
|
36197ce027 | ||
|
|
e9a0226ee0 | ||
|
|
fc3b4a653e | ||
|
|
3673abb01e | ||
|
|
ac4277d36c | ||
|
|
21cbc99d9e | ||
|
|
d080bf2ae9 | ||
|
|
2a1c790655 | ||
|
|
410204a70d | ||
|
|
4a0c167c1c | ||
|
|
593c956d33 | ||
|
|
d18cb89493 | ||
|
|
067c79c606 | ||
|
|
ebde88ccaa | ||
|
|
cc402487d9 | ||
|
|
d108e6102b | ||
|
|
3e60043632 | ||
|
|
a8d691169a | ||
|
|
939c2f6718 | ||
|
|
0837059e21 | ||
|
|
0ee166fdf0 | ||
|
|
b50996b864 | ||
|
|
8f423c7293 | ||
|
|
14ce88e04b | ||
|
|
f97968b72d | ||
|
|
612f867ea8 | ||
|
|
303d6609e4 | ||
|
|
bf7b163ccd | ||
|
|
4bd798f0ad | ||
|
|
52aa7c5d21 | ||
|
|
f5a1dd31c8 | ||
|
|
c41000a4b1 | ||
|
|
c3f8b05a68 | ||
|
|
f4fcf92bd6 | ||
|
|
a2c139245d | ||
|
|
a509cdedd5 | ||
|
|
dcbc30b164 | ||
|
|
5ab99b4cc0 | ||
|
|
27c90b7cf1 | ||
|
|
6eb76454bb | ||
|
|
83bcea98dc | ||
|
|
4db09a73b3 | ||
|
|
45a9e3bfc3 | ||
|
|
bd40015e1c | ||
|
|
7894600408 | ||
|
|
df4668754d | ||
|
|
08d6f83b2e | ||
|
|
c58f510054 | ||
|
|
c2879d054a | ||
|
|
f821d2c909 | ||
|
|
1ef2218919 | ||
|
|
177c958572 | ||
|
|
b5ab1ff0cd | ||
|
|
70a978b83d | ||
|
|
2037810c6b | ||
|
|
de304f83de | ||
|
|
5752373009 | ||
|
|
fecae39fcd | ||
|
|
38bc4fbfe2 | ||
|
|
92ed7573d4 | ||
|
|
80f0e92462 | ||
|
|
5f10b1b2ca | ||
|
|
4f83b1e6b3 | ||
|
|
15d5a687fb | ||
|
|
eb1fce3787 | ||
|
|
7f735cbe59 | ||
|
|
a690ea4016 | ||
|
|
7a110c7acd | ||
|
|
407bb33359 | ||
|
|
4b7f7bba04 | ||
|
|
cfdc0a1f2a | ||
|
|
f926055e67 | ||
|
|
058af95d70 | ||
|
|
54facdc391 | ||
|
|
2e4c0cc7e7 | ||
|
|
cb2fd7c5e8 | ||
|
|
94133cc8b1 | ||
|
|
dcec89be90 | ||
|
|
fefd5d1d0e |
@@ -1,3 +1,54 @@
|
||||
1.8.14
|
||||
* #896: Fix an error in borgmatic rcreate/init on an empty repository directory with Borg 1.4.
|
||||
* #898: Add glob ("*") support to the "--repository" flag. Just quote any values containing
|
||||
globs so your shell doesn't interpret them.
|
||||
* #899: Fix for a "bad character" Borg error in which the "spot" check fed Borg an invalid pattern.
|
||||
* #900: Fix for a potential traceback (TypeError) during the handling of another error.
|
||||
* #904: Clarify the configuration reference about the "spot" check options:
|
||||
https://torsion.org/borgmatic/docs/reference/configuration/
|
||||
* #905: Fix the "source_directories_must_exist" option to work with relative "source_directories"
|
||||
paths when a "working_directory" is set.
|
||||
* #906: Add documentation details for how to run custom database dump commands using binaries from
|
||||
running containers:
|
||||
https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#containers
|
||||
* Fix a regression in which the "color" option had no effect.
|
||||
* Add a recent contributors section to the documentation, because credit where credit's due! See:
|
||||
https://torsion.org/borgmatic/#recent-contributors
|
||||
|
||||
1.8.13
|
||||
* #298: Add "delete" and "rdelete" actions to delete archives or entire repositories.
|
||||
* #785: Add an "only_run_on" option to consistency checks so you can limit a check to running on
|
||||
particular days of the week. See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#check-days
|
||||
* #885: Add an Uptime Kuma monitoring hook. See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#uptime-kuma-hook
|
||||
* #886: Fix a PagerDuty hook traceback with Python < 3.10.
|
||||
* #889: Fix the Healthchecks ping body size limit, restoring it to the documented 100,000 bytes.
|
||||
|
||||
1.8.12
|
||||
* #817: Add a "--max-duration" flag to the "check" action and a "max_duration" option to the
|
||||
repository check configuration. This tells Borg to interrupt a repository check after a certain
|
||||
duration.
|
||||
* #860: Fix interaction between environment variable interpolation in constants and shell escaping.
|
||||
* #863: When color output is disabled (explicitly or implicitly), don't prefix each log line with
|
||||
the log level.
|
||||
* #865: Add an "upload_buffer_size" option to set the size of the upload buffer used in "create"
|
||||
action.
|
||||
* #866: Fix "Argument list too long" error in the "spot" check when checking hundreds of thousands
|
||||
of files at once.
|
||||
* #874: Add the configured repository label as "repository_label" to the interpolated variables
|
||||
passed to before/after command hooks.
|
||||
* #881: Fix "Unrecognized argument" error when the same value is used with different command-line
|
||||
flags.
|
||||
* In the "spot" check, don't try to hash symlinked directories.
|
||||
|
||||
1.8.11
|
||||
* #815: Add optional Healthchecks auto-provisioning via "create_slug" option.
|
||||
* #851: Fix lack of file extraction when using "extract --strip-components all" on a path with a
|
||||
leading slash.
|
||||
* #854: Fix a traceback when the "data" consistency check is used.
|
||||
* #857: Fix a traceback with "check --only spot" when the "spot" check is unconfigured.
|
||||
|
||||
1.8.10
|
||||
* #656 (beta): Add a "spot" consistency check that compares file counts and contents between your
|
||||
source files and the latest archive, ensuring they fall within configured tolerances. This can
|
||||
|
||||
@@ -62,6 +62,7 @@ borgmatic is powered by [Borg Backup](https://www.borgbackup.org/).
|
||||
<a href="https://www.mongodb.com/"><img src="docs/static/mongodb.png" alt="MongoDB" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://sqlite.org/"><img src="docs/static/sqlite.png" alt="SQLite" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://healthchecks.io/"><img src="docs/static/healthchecks.png" alt="Healthchecks" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://uptime.kuma.pet/"><img src="docs/static/uptimekuma.png" alt="Uptime Kuma" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://cronitor.io/"><img src="docs/static/cronitor.png" alt="Cronitor" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://cronhub.io/"><img src="docs/static/cronhub.png" alt="Cronhub" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
<a href="https://www.pagerduty.com/"><img src="docs/static/pagerduty.png" alt="PagerDuty" height="60px" style="margin-bottom:20px; margin-right:20px;"></a>
|
||||
@@ -154,3 +155,7 @@ general, contributions are very welcome. We don't bite!
|
||||
Also, please check out the [borgmatic development
|
||||
how-to](https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/) for
|
||||
info on cloning source code, running tests, etc.
|
||||
|
||||
### Recent contributors
|
||||
|
||||
{% include borgmatic/contributors.html %}
|
||||
|
||||
+91
-29
@@ -1,3 +1,4 @@
|
||||
import calendar
|
||||
import datetime
|
||||
import hashlib
|
||||
import itertools
|
||||
@@ -99,12 +100,17 @@ def parse_frequency(frequency):
|
||||
raise ValueError(f"Could not parse consistency check frequency '{frequency}'")
|
||||
|
||||
|
||||
WEEKDAY_DAYS = calendar.day_name[0:5]
|
||||
WEEKEND_DAYS = calendar.day_name[5:7]
|
||||
|
||||
|
||||
def filter_checks_on_frequency(
|
||||
config,
|
||||
borg_repository_id,
|
||||
checks,
|
||||
force,
|
||||
archives_check_id=None,
|
||||
datetime_now=datetime.datetime.now,
|
||||
):
|
||||
'''
|
||||
Given a configuration dict with a "checks" sequence of dicts, a Borg repository ID, a sequence
|
||||
@@ -143,6 +149,29 @@ def filter_checks_on_frequency(
|
||||
if checks and check not in checks:
|
||||
continue
|
||||
|
||||
only_run_on = check_config.get('only_run_on')
|
||||
if only_run_on:
|
||||
# Use a dict instead of a set to preserve ordering.
|
||||
days = dict.fromkeys(only_run_on)
|
||||
|
||||
if 'weekday' in days:
|
||||
days = {
|
||||
**dict.fromkeys(day for day in days if day != 'weekday'),
|
||||
**dict.fromkeys(WEEKDAY_DAYS),
|
||||
}
|
||||
if 'weekend' in days:
|
||||
days = {
|
||||
**dict.fromkeys(day for day in days if day != 'weekend'),
|
||||
**dict.fromkeys(WEEKEND_DAYS),
|
||||
}
|
||||
|
||||
if calendar.day_name[datetime_now().weekday()] not in days:
|
||||
logger.info(
|
||||
f"Skipping {check} check due to day of the week; check only runs on {'/'.join(days)} (use --force to check anyway)"
|
||||
)
|
||||
filtered_checks.remove(check)
|
||||
continue
|
||||
|
||||
frequency_delta = parse_frequency(check_config.get('frequency'))
|
||||
if not frequency_delta:
|
||||
continue
|
||||
@@ -153,8 +182,8 @@ def filter_checks_on_frequency(
|
||||
|
||||
# If we've not yet reached the time when the frequency dictates we're ready for another
|
||||
# check, skip this check.
|
||||
if datetime.datetime.now() < check_time + frequency_delta:
|
||||
remaining = check_time + frequency_delta - datetime.datetime.now()
|
||||
if datetime_now() < check_time + frequency_delta:
|
||||
remaining = check_time + frequency_delta - datetime_now()
|
||||
logger.info(
|
||||
f'Skipping {check} check due to configured frequency; {remaining} until next check (use --force to check anyway)'
|
||||
)
|
||||
@@ -300,8 +329,7 @@ def collect_spot_check_source_paths(
|
||||
'''
|
||||
Given a repository configuration dict, a configuration dict, the local Borg version, global
|
||||
arguments as an argparse.Namespace instance, the local Borg path, and the remote Borg path,
|
||||
collect the source paths that Borg would use in an actual create (but only include files and
|
||||
symlinks).
|
||||
collect the source paths that Borg would use in an actual create (but only include files).
|
||||
'''
|
||||
stream_processes = any(
|
||||
borgmatic.hooks.dispatch.call_hooks(
|
||||
@@ -349,7 +377,7 @@ def collect_spot_check_source_paths(
|
||||
if path_line and path_line.startswith('- ') or path_line.startswith('+ ')
|
||||
)
|
||||
|
||||
return tuple(path for path in paths if os.path.isfile(path) or os.path.islink(path))
|
||||
return tuple(path for path in paths if os.path.isfile(path))
|
||||
|
||||
|
||||
BORG_DIRECTORY_FILE_TYPE = 'd'
|
||||
@@ -388,6 +416,9 @@ def collect_spot_check_archive_paths(
|
||||
)
|
||||
|
||||
|
||||
SAMPLE_PATHS_SUBSET_COUNT = 10000
|
||||
|
||||
|
||||
def compare_spot_check_hashes(
|
||||
repository,
|
||||
archive,
|
||||
@@ -420,32 +451,57 @@ def compare_spot_check_hashes(
|
||||
f'{log_label}: Sampling {sample_count} source paths (~{spot_check_config["data_sample_percentage"]}%) for spot check'
|
||||
)
|
||||
|
||||
# Hash each file in the sample paths (if it exists).
|
||||
hash_output = borgmatic.execute.execute_command_and_capture_output(
|
||||
(spot_check_config.get('xxh64sum_command', 'xxh64sum'),)
|
||||
+ tuple(path for path in source_sample_paths if path in existing_source_sample_paths)
|
||||
)
|
||||
source_sample_paths_iterator = iter(source_sample_paths)
|
||||
source_hashes = {}
|
||||
archive_hashes = {}
|
||||
|
||||
source_hashes = dict(
|
||||
(reversed(line.split(' ', 1)) for line in hash_output.splitlines()),
|
||||
**{path: '' for path in source_sample_paths if path not in existing_source_sample_paths},
|
||||
)
|
||||
# Only hash a few thousand files at a time (a subset of the total paths) to avoid an "Argument
|
||||
# list too long" shell error.
|
||||
while True:
|
||||
# Hash each file in the sample paths (if it exists).
|
||||
source_sample_paths_subset = tuple(
|
||||
itertools.islice(source_sample_paths_iterator, SAMPLE_PATHS_SUBSET_COUNT)
|
||||
)
|
||||
if not source_sample_paths_subset:
|
||||
break
|
||||
|
||||
archive_hashes = dict(
|
||||
reversed(line.split(' ', 1))
|
||||
for line in borgmatic.borg.list.capture_archive_listing(
|
||||
repository['path'],
|
||||
archive,
|
||||
config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
list_paths=source_sample_paths,
|
||||
path_format='{xxh64} /{path}{NL}', # noqa: FS003
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
hash_output = borgmatic.execute.execute_command_and_capture_output(
|
||||
(spot_check_config.get('xxh64sum_command', 'xxh64sum'),)
|
||||
+ tuple(
|
||||
path for path in source_sample_paths_subset if path in existing_source_sample_paths
|
||||
)
|
||||
)
|
||||
|
||||
source_hashes.update(
|
||||
**dict(
|
||||
(reversed(line.split(' ', 1)) for line in hash_output.splitlines()),
|
||||
# Represent non-existent files as having empty hashes so the comparison below still works.
|
||||
**{
|
||||
path: ''
|
||||
for path in source_sample_paths_subset
|
||||
if path not in existing_source_sample_paths
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
# Get the hash for each file in the archive.
|
||||
archive_hashes.update(
|
||||
**dict(
|
||||
reversed(line.split(' ', 1))
|
||||
for line in borgmatic.borg.list.capture_archive_listing(
|
||||
repository['path'],
|
||||
archive,
|
||||
config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
list_paths=source_sample_paths_subset,
|
||||
path_format='{xxh64} /{path}{NL}', # noqa: FS003
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
if line
|
||||
)
|
||||
)
|
||||
if line
|
||||
)
|
||||
|
||||
# Compare the source hashes with the archive hashes to see how many match.
|
||||
failing_paths = []
|
||||
@@ -480,7 +536,13 @@ def spot_check(
|
||||
'''
|
||||
log_label = f'{repository.get("label", repository["path"])}'
|
||||
logger.debug(f'{log_label}: Running spot check')
|
||||
spot_check_config = next(check for check in config['checks'] if check['name'] == 'spot')
|
||||
|
||||
try:
|
||||
spot_check_config = next(
|
||||
check for check in config.get('checks', ()) if check.get('name') == 'spot'
|
||||
)
|
||||
except StopIteration:
|
||||
raise ValueError('Cannot run spot check because it is unconfigured')
|
||||
|
||||
if spot_check_config['data_tolerance_percentage'] > spot_check_config['data_sample_percentage']:
|
||||
raise ValueError(
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import logging
|
||||
|
||||
import borgmatic.actions.arguments
|
||||
import borgmatic.borg.delete
|
||||
import borgmatic.borg.rdelete
|
||||
import borgmatic.borg.rlist
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_delete(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
delete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "delete" action for the given repository and archive(s).
|
||||
'''
|
||||
if delete_arguments.repository is None or borgmatic.config.validate.repositories_match(
|
||||
repository, delete_arguments.repository
|
||||
):
|
||||
logger.answer(f'{repository.get("label", repository["path"])}: Deleting archives')
|
||||
|
||||
archive_name = (
|
||||
borgmatic.borg.rlist.resolve_archive_name(
|
||||
repository['path'],
|
||||
delete_arguments.archive,
|
||||
config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
if delete_arguments.archive
|
||||
else None
|
||||
)
|
||||
|
||||
borgmatic.borg.delete.delete_archives(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
borgmatic.actions.arguments.update_arguments(delete_arguments, archive=archive_name),
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
@@ -0,0 +1,36 @@
|
||||
import logging
|
||||
|
||||
import borgmatic.borg.rdelete
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run_rdelete(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "rdelete" action for the given repository.
|
||||
'''
|
||||
if rdelete_arguments.repository is None or borgmatic.config.validate.repositories_match(
|
||||
repository, rdelete_arguments.repository
|
||||
):
|
||||
logger.answer(
|
||||
f'{repository.get("label", repository["path"])}: Deleting repository'
|
||||
+ (' cache' if rdelete_arguments.cache_only else '')
|
||||
)
|
||||
|
||||
borgmatic.borg.rdelete.delete_repository(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
@@ -147,7 +147,8 @@ def collect_archive_data_source_names(
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
list_paths=[
|
||||
os.path.expanduser(
|
||||
'sh:'
|
||||
+ os.path.expanduser(
|
||||
borgmatic.hooks.dump.make_data_source_dump_path(borgmatic_source_directory, pattern)
|
||||
)
|
||||
for pattern in ('*_databases/*/*',)
|
||||
|
||||
+26
-9
@@ -50,10 +50,10 @@ def make_archive_filter_flags(local_borg_version, config, checks, check_argument
|
||||
return ()
|
||||
|
||||
|
||||
def make_check_flags(checks, archive_filter_flags):
|
||||
def make_check_name_flags(checks, archive_filter_flags):
|
||||
'''
|
||||
Given a parsed sequence of checks and a sequence of flags to filter archives, transform the
|
||||
checks into tuple of command-line check flags.
|
||||
Given parsed checks set and a sequence of flags to filter archives, transform the checks into
|
||||
tuple of command-line check flags.
|
||||
|
||||
For example, given parsed checks of:
|
||||
|
||||
@@ -68,13 +68,13 @@ def make_check_flags(checks, archive_filter_flags):
|
||||
'''
|
||||
if 'data' in checks:
|
||||
data_flags = ('--verify-data',)
|
||||
checks += ('archives',)
|
||||
checks.update({'archives'})
|
||||
else:
|
||||
data_flags = ()
|
||||
|
||||
common_flags = (archive_filter_flags if 'archives' in checks else ()) + data_flags
|
||||
|
||||
if {'repository', 'archives'}.issubset(set(checks)):
|
||||
if {'repository', 'archives'}.issubset(checks):
|
||||
return common_flags
|
||||
|
||||
return (
|
||||
@@ -134,10 +134,30 @@ def check_archives(
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
|
||||
try:
|
||||
repository_check_config = next(
|
||||
check for check in config.get('checks', ()) if check.get('name') == 'repository'
|
||||
)
|
||||
except StopIteration:
|
||||
repository_check_config = {}
|
||||
|
||||
if check_arguments.max_duration and 'archives' in checks:
|
||||
raise ValueError('The archives check cannot run when the --max-duration flag is used')
|
||||
if repository_check_config.get('max_duration') and 'archives' in checks:
|
||||
raise ValueError(
|
||||
'The archives check cannot run when the repository check has the max_duration option set'
|
||||
)
|
||||
|
||||
max_duration = check_arguments.max_duration or repository_check_config.get('max_duration')
|
||||
|
||||
borg_environment = environment.make_environment(config)
|
||||
borg_exit_codes = config.get('borg_exit_codes')
|
||||
|
||||
full_command = (
|
||||
(local_path, 'check')
|
||||
+ (('--repair',) if check_arguments.repair else ())
|
||||
+ make_check_flags(checks, archive_filter_flags)
|
||||
+ (('--max-duration', str(max_duration)) if max_duration else ())
|
||||
+ make_check_name_flags(checks, archive_filter_flags)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
@@ -147,9 +167,6 @@ def check_archives(
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
)
|
||||
|
||||
borg_environment = environment.make_environment(config)
|
||||
borg_exit_codes = config.get('borg_exit_codes')
|
||||
|
||||
# The Borg repair option triggers an interactive prompt, which won't work when output is
|
||||
# captured. And progress messes with the terminal directly.
|
||||
if check_arguments.repair or check_arguments.progress:
|
||||
|
||||
+24
-10
@@ -306,15 +306,25 @@ def collect_special_file_paths(
|
||||
)
|
||||
|
||||
|
||||
def check_all_source_directories_exist(source_directories):
|
||||
def check_all_source_directories_exist(source_directories, working_directory=None):
|
||||
'''
|
||||
Given a sequence of source directories, check that they all exist. If any do not, raise an
|
||||
exception.
|
||||
Given a sequence of source directories and an optional working directory to serve as a prefix
|
||||
for each (if it's a relative directory), check that the source directories all exist. If any do
|
||||
not, raise an exception.
|
||||
'''
|
||||
missing_directories = [
|
||||
source_directory
|
||||
for source_directory in source_directories
|
||||
if not all([os.path.exists(directory) for directory in expand_directory(source_directory)])
|
||||
if not all(
|
||||
[
|
||||
os.path.exists(directory)
|
||||
for directory in expand_directory(
|
||||
os.path.join(working_directory, source_directory)
|
||||
if working_directory
|
||||
else source_directory
|
||||
)
|
||||
]
|
||||
)
|
||||
]
|
||||
if missing_directories:
|
||||
raise ValueError(f"Source directories do not exist: {', '.join(missing_directories)}")
|
||||
@@ -342,8 +352,15 @@ def make_base_create_command(
|
||||
(base Borg create command flags, Borg create command positional arguments, open pattern file
|
||||
handle, open exclude file handle).
|
||||
'''
|
||||
try:
|
||||
working_directory = os.path.expanduser(config.get('working_directory'))
|
||||
except TypeError:
|
||||
working_directory = None
|
||||
|
||||
if config.get('source_directories_must_exist', False):
|
||||
check_all_source_directories_exist(config.get('source_directories'))
|
||||
check_all_source_directories_exist(
|
||||
config.get('source_directories'), working_directory=working_directory
|
||||
)
|
||||
|
||||
sources = deduplicate_directories(
|
||||
map_directories_to_devices(
|
||||
@@ -371,6 +388,7 @@ def make_base_create_command(
|
||||
chunker_params = config.get('chunker_params', None)
|
||||
compression = config.get('compression', None)
|
||||
upload_rate_limit = config.get('upload_rate_limit', None)
|
||||
upload_buffer_size = config.get('upload_buffer_size', None)
|
||||
umask = config.get('umask', None)
|
||||
lock_wait = config.get('lock_wait', None)
|
||||
list_filter_flags = make_list_filter_flags(local_borg_version, dry_run)
|
||||
@@ -412,6 +430,7 @@ def make_base_create_command(
|
||||
+ (('--chunker-params', chunker_params) if chunker_params else ())
|
||||
+ (('--compression', compression) if compression else ())
|
||||
+ upload_ratelimit_flags
|
||||
+ (('--upload-buffer', str(upload_buffer_size)) if upload_buffer_size else ())
|
||||
+ (('--one-file-system',) if config.get('one_file_system') or stream_processes else ())
|
||||
+ numeric_ids_flags
|
||||
+ atime_flags
|
||||
@@ -443,11 +462,6 @@ def make_base_create_command(
|
||||
logger.warning(
|
||||
f'{repository_path}: Ignoring configured "read_special" value of false, as true is needed for database hooks.'
|
||||
)
|
||||
try:
|
||||
working_directory = os.path.expanduser(config.get('working_directory'))
|
||||
except TypeError:
|
||||
working_directory = None
|
||||
|
||||
borg_environment = environment.make_environment(config)
|
||||
|
||||
logger.debug(f'{repository_path}: Collecting special file paths')
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
import borgmatic.borg.environment
|
||||
import borgmatic.borg.feature
|
||||
import borgmatic.borg.flags
|
||||
import borgmatic.borg.rdelete
|
||||
import borgmatic.execute
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def make_delete_command(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
delete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository dict, a configuration dict, the local Borg version, the
|
||||
arguments to the delete action as an argparse.Namespace, and global arguments, return a command
|
||||
as a tuple to delete archives from the repository.
|
||||
'''
|
||||
return (
|
||||
(local_path, 'delete')
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ borgmatic.borg.flags.make_flags('dry-run', global_arguments.dry_run)
|
||||
+ borgmatic.borg.flags.make_flags('remote-path', remote_path)
|
||||
+ borgmatic.borg.flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ borgmatic.borg.flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ borgmatic.borg.flags.make_flags('list', delete_arguments.list_archives)
|
||||
+ (
|
||||
(('--force',) + (('--force',) if delete_arguments.force >= 2 else ()))
|
||||
if delete_arguments.force
|
||||
else ()
|
||||
)
|
||||
# Ignore match_archives and archive_name_format options from configuration, so the user has
|
||||
# to be explicit on the command-line about the archives they want to delete.
|
||||
+ borgmatic.borg.flags.make_match_archives_flags(
|
||||
delete_arguments.match_archives or delete_arguments.archive,
|
||||
archive_name_format=None,
|
||||
local_borg_version=local_borg_version,
|
||||
default_archive_name_format='*',
|
||||
)
|
||||
+ borgmatic.borg.flags.make_flags_from_arguments(
|
||||
delete_arguments,
|
||||
excludes=('list_archives', 'force', 'match_archives', 'archive', 'repository'),
|
||||
)
|
||||
+ borgmatic.borg.flags.make_repository_flags(repository['path'], local_borg_version)
|
||||
)
|
||||
|
||||
|
||||
ARCHIVE_RELATED_ARGUMENT_NAMES = (
|
||||
'archive',
|
||||
'match_archives',
|
||||
'first',
|
||||
'last',
|
||||
'oldest',
|
||||
'newest',
|
||||
'older',
|
||||
'newer',
|
||||
)
|
||||
|
||||
|
||||
def delete_archives(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
delete_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository dict, a configuration dict, the local Borg version, the
|
||||
arguments to the delete action as an argparse.Namespace, global arguments as an
|
||||
argparse.Namespace, and local and remote Borg paths, delete the selected archives from the
|
||||
repository. If no archives are selected, then delete the entire repository.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
|
||||
if not any(
|
||||
getattr(delete_arguments, argument_name, None)
|
||||
for argument_name in ARCHIVE_RELATED_ARGUMENT_NAMES
|
||||
):
|
||||
if borgmatic.borg.feature.available(
|
||||
borgmatic.borg.feature.Feature.RDELETE, local_borg_version
|
||||
):
|
||||
logger.warning(
|
||||
'Deleting an entire repository with the delete action is deprecated when using Borg 2.x+. Use the rdelete action instead.'
|
||||
)
|
||||
|
||||
rdelete_arguments = argparse.Namespace(
|
||||
repository=repository['path'],
|
||||
list_archives=delete_arguments.list_archives,
|
||||
force=delete_arguments.force,
|
||||
cache_only=delete_arguments.cache_only,
|
||||
keep_security_info=delete_arguments.keep_security_info,
|
||||
)
|
||||
borgmatic.borg.rdelete.delete_repository(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
command = make_delete_command(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
delete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
||||
borgmatic.execute.execute_command(
|
||||
command,
|
||||
output_log_level=logging.ANSWER,
|
||||
extra_environment=borgmatic.borg.environment.make_environment(config),
|
||||
borg_local_path=local_path,
|
||||
borg_exit_codes=config.get('borg_exit_codes'),
|
||||
)
|
||||
@@ -104,8 +104,13 @@ def extract_archive(
|
||||
if not paths:
|
||||
raise ValueError('The --strip-components flag with "all" requires at least one --path')
|
||||
|
||||
# Calculate the maximum number of leading path components of the given paths.
|
||||
strip_components = max(0, *(len(path.split(os.path.sep)) - 1 for path in paths))
|
||||
# Calculate the maximum number of leading path components of the given paths. "if piece"
|
||||
# ignores empty path components, e.g. those resulting from a leading slash. And the "- 1"
|
||||
# is so this doesn't count the final path component, e.g. the filename itself.
|
||||
strip_components = max(
|
||||
0,
|
||||
*(len(tuple(piece for piece in path.split(os.path.sep) if piece)) - 1 for path in paths)
|
||||
)
|
||||
|
||||
full_command = (
|
||||
(local_path, 'extract')
|
||||
|
||||
@@ -13,8 +13,9 @@ class Feature(Enum):
|
||||
RCREATE = 7
|
||||
RLIST = 8
|
||||
RINFO = 9
|
||||
MATCH_ARCHIVES = 10
|
||||
EXCLUDED_FILES_MINUS = 11
|
||||
RDELETE = 10
|
||||
MATCH_ARCHIVES = 11
|
||||
EXCLUDED_FILES_MINUS = 12
|
||||
|
||||
|
||||
FEATURE_TO_MINIMUM_BORG_VERSION = {
|
||||
@@ -27,6 +28,7 @@ FEATURE_TO_MINIMUM_BORG_VERSION = {
|
||||
Feature.RCREATE: parse('2.0.0a2'), # borg rcreate
|
||||
Feature.RLIST: parse('2.0.0a2'), # borg rlist
|
||||
Feature.RINFO: parse('2.0.0a2'), # borg rinfo
|
||||
Feature.RDELETE: parse('2.0.0a2'), # borg rdelete
|
||||
Feature.MATCH_ARCHIVES: parse('2.0.0b3'), # borg --match-archives
|
||||
Feature.EXCLUDED_FILES_MINUS: parse('2.0.0b5'), # --list --filter uses "-" for excludes
|
||||
}
|
||||
|
||||
@@ -66,7 +66,12 @@ def make_repository_archive_flags(repository_path, archive, local_borg_version):
|
||||
DEFAULT_ARCHIVE_NAME_FORMAT = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}' # noqa: FS003
|
||||
|
||||
|
||||
def make_match_archives_flags(match_archives, archive_name_format, local_borg_version):
|
||||
def make_match_archives_flags(
|
||||
match_archives,
|
||||
archive_name_format,
|
||||
local_borg_version,
|
||||
default_archive_name_format=DEFAULT_ARCHIVE_NAME_FORMAT,
|
||||
):
|
||||
'''
|
||||
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 (or default) archive name
|
||||
@@ -83,7 +88,7 @@ def make_match_archives_flags(match_archives, archive_name_format, local_borg_ve
|
||||
return ('--glob-archives', re.sub(r'^sh:', '', match_archives))
|
||||
|
||||
derived_match_archives = re.sub(
|
||||
r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format or DEFAULT_ARCHIVE_NAME_FORMAT
|
||||
r'\{(now|utcnow|pid)([:%\w\.-]*)\}', '*', archive_name_format or default_archive_name_format
|
||||
)
|
||||
|
||||
if derived_match_archives == '*':
|
||||
|
||||
+12
-11
@@ -100,10 +100,11 @@ def capture_archive_listing(
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, an archive name, a configuration dict, the local Borg
|
||||
version, global arguments as an argparse.Namespace, the archive paths in which to list files,
|
||||
the Borg path format to use for the output, and local and remote Borg paths, capture the output
|
||||
of listing that archive and return it as a list of file paths.
|
||||
Given a local or remote repository path, an archive name, a configuration
|
||||
dict, the local Borg version, global arguments as an argparse.Namespace,
|
||||
the archive paths (or Borg patterns) in which to list files, the Borg path
|
||||
format to use for the output, and local and remote Borg paths, capture the
|
||||
output of listing that archive and return it as a list of file paths.
|
||||
'''
|
||||
borg_environment = environment.make_environment(config)
|
||||
|
||||
@@ -116,7 +117,7 @@ def capture_archive_listing(
|
||||
argparse.Namespace(
|
||||
repository=repository_path,
|
||||
archive=archive,
|
||||
paths=[f'sh:{path}' for path in list_paths] if list_paths else None,
|
||||
paths=[path for path in list_paths] if list_paths else None,
|
||||
find_paths=None,
|
||||
json=None,
|
||||
format=path_format or '{path}{NL}', # noqa: FS003
|
||||
@@ -144,12 +145,12 @@ def list_archive(
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a configuration dict, the local Borg version, global
|
||||
arguments as an argparse.Namespace, the arguments to the list action as an argparse.Namespace,
|
||||
and local and remote Borg paths, display the output of listing the files of a Borg archive (or
|
||||
return JSON output). If list_arguments.find_paths are given, list the files by searching across
|
||||
multiple archives. If neither find_paths nor archive name are given, instead list the archives
|
||||
in the given repository.
|
||||
Given a local or remote repository path, a configuration dict, the local Borg version, the
|
||||
arguments to the list action as an argparse.Namespace, global arguments as an
|
||||
argparse.Namespace, and local and remote Borg paths, display the output of listing the files of
|
||||
a Borg archive (or return JSON output). If list_arguments.find_paths are given, list the files
|
||||
by searching across multiple archives. If neither find_paths nor archive name are given, instead
|
||||
list the archives in the given repository.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from borgmatic.execute import DO_NOT_CAPTURE, execute_command
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
RINFO_REPOSITORY_NOT_FOUND_EXIT_CODES = {2, 13}
|
||||
RINFO_REPOSITORY_NOT_FOUND_EXIT_CODES = {2, 13, 15}
|
||||
|
||||
|
||||
def create_repository(
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
import logging
|
||||
|
||||
import borgmatic.borg.environment
|
||||
import borgmatic.borg.feature
|
||||
import borgmatic.borg.flags
|
||||
import borgmatic.execute
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def make_rdelete_command(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository dict, a configuration dict, the local Borg version, the
|
||||
arguments to the rdelete action as an argparse.Namespace, and global arguments, return a command
|
||||
as a tuple to rdelete the entire repository.
|
||||
'''
|
||||
return (
|
||||
(local_path,)
|
||||
+ (
|
||||
('rdelete',)
|
||||
if borgmatic.borg.feature.available(
|
||||
borgmatic.borg.feature.Feature.RDELETE, local_borg_version
|
||||
)
|
||||
else ('delete',)
|
||||
)
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ borgmatic.borg.flags.make_flags('dry-run', global_arguments.dry_run)
|
||||
+ borgmatic.borg.flags.make_flags('remote-path', remote_path)
|
||||
+ borgmatic.borg.flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ borgmatic.borg.flags.make_flags('lock-wait', config.get('lock_wait'))
|
||||
+ borgmatic.borg.flags.make_flags('list', rdelete_arguments.list_archives)
|
||||
+ (
|
||||
(('--force',) + (('--force',) if rdelete_arguments.force >= 2 else ()))
|
||||
if rdelete_arguments.force
|
||||
else ()
|
||||
)
|
||||
+ borgmatic.borg.flags.make_flags_from_arguments(
|
||||
rdelete_arguments, excludes=('list_archives', 'force', 'repository')
|
||||
)
|
||||
+ borgmatic.borg.flags.make_repository_flags(repository['path'], local_borg_version)
|
||||
)
|
||||
|
||||
|
||||
def delete_repository(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository dict, a configuration dict, the local Borg version, the
|
||||
arguments to the rdelete action as an argparse.Namespace, global arguments as an
|
||||
argparse.Namespace, and local and remote Borg paths, rdelete the entire repository.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
|
||||
command = make_rdelete_command(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
rdelete_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
||||
borgmatic.execute.execute_command(
|
||||
command,
|
||||
output_log_level=logging.ANSWER,
|
||||
# Don't capture output when Borg is expected to prompt for interactive confirmation, or the
|
||||
# prompt won't work.
|
||||
output_file=(
|
||||
None
|
||||
if rdelete_arguments.force or rdelete_arguments.cache_only
|
||||
else borgmatic.execute.DO_NOT_CAPTURE
|
||||
),
|
||||
extra_environment=borgmatic.borg.environment.make_environment(config),
|
||||
borg_local_path=local_path,
|
||||
borg_exit_codes=config.get('borg_exit_codes'),
|
||||
)
|
||||
+216
-24
@@ -12,11 +12,13 @@ ACTION_ALIASES = {
|
||||
'create': ['-C'],
|
||||
'check': ['-k'],
|
||||
'config': [],
|
||||
'delete': [],
|
||||
'extract': ['-x'],
|
||||
'export-tar': [],
|
||||
'mount': ['-m'],
|
||||
'umount': ['-u'],
|
||||
'restore': ['-r'],
|
||||
'rdelete': [],
|
||||
'rlist': [],
|
||||
'list': ['-l'],
|
||||
'rinfo': [],
|
||||
@@ -113,6 +115,54 @@ def parse_and_record_action_arguments(
|
||||
return tuple(argument for argument in remaining if argument != action_name)
|
||||
|
||||
|
||||
def argument_is_flag(argument):
|
||||
'''
|
||||
Return True if the given argument looks like a flag, e.g. '--some-flag', as opposed to a
|
||||
non-flag value.
|
||||
'''
|
||||
return isinstance(argument, str) and argument.startswith('--')
|
||||
|
||||
|
||||
def group_arguments_with_values(arguments):
|
||||
'''
|
||||
Given a sequence of arguments, return a sequence of tuples where each one contains either a
|
||||
single argument (such as for a stand-alone flag) or a flag argument and its corresponding value.
|
||||
|
||||
For instance, given the following arguments sequence as input:
|
||||
|
||||
('--foo', '--bar', '33', '--baz')
|
||||
|
||||
... return the following output:
|
||||
|
||||
(('--foo',), ('--bar', '33'), ('--baz',))
|
||||
'''
|
||||
grouped_arguments = []
|
||||
index = 0
|
||||
|
||||
while index < len(arguments):
|
||||
this_argument = arguments[index]
|
||||
|
||||
try:
|
||||
next_argument = arguments[index + 1]
|
||||
except IndexError:
|
||||
grouped_arguments.append((this_argument,))
|
||||
break
|
||||
|
||||
if (
|
||||
argument_is_flag(this_argument)
|
||||
and not argument_is_flag(next_argument)
|
||||
and next_argument not in ACTION_ALIASES
|
||||
):
|
||||
grouped_arguments.append((this_argument, next_argument))
|
||||
index += 2
|
||||
continue
|
||||
|
||||
grouped_arguments.append((this_argument,))
|
||||
index += 1
|
||||
|
||||
return tuple(grouped_arguments)
|
||||
|
||||
|
||||
def get_unparsable_arguments(remaining_action_arguments):
|
||||
'''
|
||||
Given a sequence of argument tuples (one per action parser that parsed arguments), determine the
|
||||
@@ -121,12 +171,21 @@ def get_unparsable_arguments(remaining_action_arguments):
|
||||
if not remaining_action_arguments:
|
||||
return ()
|
||||
|
||||
grouped_action_arguments = tuple(
|
||||
group_arguments_with_values(action_arguments)
|
||||
for action_arguments in remaining_action_arguments
|
||||
)
|
||||
|
||||
return tuple(
|
||||
argument
|
||||
for argument in dict.fromkeys(
|
||||
itertools.chain.from_iterable(remaining_action_arguments)
|
||||
).keys()
|
||||
if all(argument in action_arguments for action_arguments in remaining_action_arguments)
|
||||
itertools.chain.from_iterable(
|
||||
argument_group
|
||||
for argument_group in dict.fromkeys(
|
||||
itertools.chain.from_iterable(grouped_action_arguments)
|
||||
).keys()
|
||||
if all(
|
||||
argument_group in action_arguments for action_arguments in grouped_action_arguments
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -366,7 +425,7 @@ def make_parsers():
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of the new repository to create (must be already specified in a borgmatic configuration file), defaults to the configured repository if there is only one',
|
||||
help='Path of the new repository to create (must be already specified in a borgmatic configuration file), defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--copy-crypt-key',
|
||||
@@ -401,7 +460,7 @@ def make_parsers():
|
||||
transfer_group = transfer_parser.add_argument_group('transfer arguments')
|
||||
transfer_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of existing destination repository to transfer archives to, defaults to the configured repository if there is only one',
|
||||
help='Path of existing destination repository to transfer archives to, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--source-repository',
|
||||
@@ -474,14 +533,14 @@ def make_parsers():
|
||||
prune_group = prune_parser.add_argument_group('prune arguments')
|
||||
prune_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of specific existing repository to prune (must be already specified in a borgmatic configuration file)',
|
||||
help='Path of specific existing repository to prune (must be already specified in a borgmatic configuration file), quoted globs supported',
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--stats',
|
||||
dest='stats',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Display statistics of archive',
|
||||
help='Display statistics of the pruned archive',
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--list', dest='list_archives', action='store_true', help='List archives kept/pruned'
|
||||
@@ -518,7 +577,7 @@ def make_parsers():
|
||||
compact_group = compact_parser.add_argument_group('compact arguments')
|
||||
compact_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of specific existing repository to compact (must be already specified in a borgmatic configuration file)',
|
||||
help='Path of specific existing repository to compact (must be already specified in a borgmatic configuration file), quoted globs supported',
|
||||
)
|
||||
compact_group.add_argument(
|
||||
'--progress',
|
||||
@@ -554,7 +613,7 @@ def make_parsers():
|
||||
create_group = create_parser.add_argument_group('create arguments')
|
||||
create_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of specific existing repository to backup to (must be already specified in a borgmatic configuration file)',
|
||||
help='Path of specific existing repository to backup to (must be already specified in a borgmatic configuration file), quoted globs supported',
|
||||
)
|
||||
create_group.add_argument(
|
||||
'--progress',
|
||||
@@ -588,7 +647,7 @@ def make_parsers():
|
||||
check_group = check_parser.add_argument_group('check arguments')
|
||||
check_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of specific existing repository to check (must be already specified in a borgmatic configuration file)',
|
||||
help='Path of specific existing repository to check (must be already specified in a borgmatic configuration file), quoted globs supported',
|
||||
)
|
||||
check_group.add_argument(
|
||||
'--progress',
|
||||
@@ -604,6 +663,11 @@ def make_parsers():
|
||||
action='store_true',
|
||||
help='Attempt to repair any inconsistencies found (for interactive use)',
|
||||
)
|
||||
check_group.add_argument(
|
||||
'--max-duration',
|
||||
metavar='SECONDS',
|
||||
help='How long to check the repository before interrupting the check, defaults to no interruption',
|
||||
)
|
||||
check_group.add_argument(
|
||||
'-a',
|
||||
'--match-archives',
|
||||
@@ -627,6 +691,97 @@ def make_parsers():
|
||||
)
|
||||
check_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
delete_parser = action_parsers.add_parser(
|
||||
'delete',
|
||||
aliases=ACTION_ALIASES['delete'],
|
||||
help='Delete an archive from a repository or delete an entire repository (with Borg 1.2+, you must run compact afterwards to actually free space)',
|
||||
description='Delete an archive from a repository or delete an entire repository (with Borg 1.2+, you must run compact afterwards to actually free space)',
|
||||
add_help=False,
|
||||
)
|
||||
delete_group = delete_parser.add_argument_group('delete arguments')
|
||||
delete_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to delete or delete archives from, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--archive',
|
||||
help='Archive to delete',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--list',
|
||||
dest='list_archives',
|
||||
action='store_true',
|
||||
help='Show details for the deleted archives',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--stats',
|
||||
action='store_true',
|
||||
help='Display statistics for the deleted archives',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--cache-only',
|
||||
action='store_true',
|
||||
help='Delete only the local cache for the given repository',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--force',
|
||||
action='count',
|
||||
help='Force deletion of corrupted archives, can be given twice if once does not work',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--keep-security-info',
|
||||
action='store_true',
|
||||
help='Do not delete the local security info when deleting a repository',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--save-space',
|
||||
action='store_true',
|
||||
help='Work slower, but using less space [Not supported in Borg 2.x+]',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--checkpoint-interval',
|
||||
type=int,
|
||||
metavar='SECONDS',
|
||||
help='Write a checkpoint at the given interval, defaults to 1800 seconds (30 minutes)',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'-a',
|
||||
'--match-archives',
|
||||
'--glob-archives',
|
||||
metavar='PATTERN',
|
||||
help='Only delete archives matching this pattern',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--sort-by', metavar='KEYS', help='Comma-separated list of sorting keys'
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--first', metavar='N', help='Delete first N archives after other filters are applied'
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--last', metavar='N', help='Delete last N archives after other filters are applied'
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='Delete archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='Delete archives within a time range that ends at timestamp of the newest archive and starts a specified time range ago (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='Delete archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
delete_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='Delete archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
delete_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
extract_parser = action_parsers.add_parser(
|
||||
'extract',
|
||||
aliases=ACTION_ALIASES['extract'],
|
||||
@@ -637,7 +792,7 @@ def make_parsers():
|
||||
extract_group = extract_parser.add_argument_group('extract arguments')
|
||||
extract_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to extract, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to extract, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
extract_group.add_argument(
|
||||
'--archive', help='Name of archive to extract (or "latest")', required=True
|
||||
@@ -699,7 +854,7 @@ def make_parsers():
|
||||
)
|
||||
config_bootstrap_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to extract config files from',
|
||||
help='Path of repository to extract config files from, quoted globs supported',
|
||||
required=True,
|
||||
)
|
||||
config_bootstrap_group.add_argument(
|
||||
@@ -797,7 +952,7 @@ def make_parsers():
|
||||
export_tar_group = export_tar_parser.add_argument_group('export-tar arguments')
|
||||
export_tar_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to export from, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to export from, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
export_tar_group.add_argument(
|
||||
'--archive', help='Name of archive to export (or "latest")', required=True
|
||||
@@ -843,7 +998,7 @@ def make_parsers():
|
||||
mount_group = mount_parser.add_argument_group('mount arguments')
|
||||
mount_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to use, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to use, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
mount_group.add_argument('--archive', help='Name of archive to mount (or "latest")')
|
||||
mount_group.add_argument(
|
||||
@@ -915,6 +1070,43 @@ def make_parsers():
|
||||
)
|
||||
umount_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
rdelete_parser = action_parsers.add_parser(
|
||||
'rdelete',
|
||||
aliases=ACTION_ALIASES['rdelete'],
|
||||
help='Delete an entire repository (with Borg 1.2+, you must run compact afterwards to actually free space)',
|
||||
description='Delete an entire repository (with Borg 1.2+, you must run compact afterwards to actually free space)',
|
||||
add_help=False,
|
||||
)
|
||||
rdelete_group = rdelete_parser.add_argument_group('delete arguments')
|
||||
rdelete_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to delete, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
rdelete_group.add_argument(
|
||||
'--list',
|
||||
dest='list_archives',
|
||||
action='store_true',
|
||||
help='Show details for the archives in the given repository',
|
||||
)
|
||||
rdelete_group.add_argument(
|
||||
'--force',
|
||||
action='count',
|
||||
help='Force deletion of corrupted archives, can be given twice if once does not work',
|
||||
)
|
||||
rdelete_group.add_argument(
|
||||
'--cache-only',
|
||||
action='store_true',
|
||||
help='Delete only the local cache for the given repository',
|
||||
)
|
||||
rdelete_group.add_argument(
|
||||
'--keep-security-info',
|
||||
action='store_true',
|
||||
help='Do not delete the local security info when deleting a repository',
|
||||
)
|
||||
rdelete_group.add_argument(
|
||||
'-h', '--help', action='help', help='Show this help message and exit'
|
||||
)
|
||||
|
||||
restore_parser = action_parsers.add_parser(
|
||||
'restore',
|
||||
aliases=ACTION_ALIASES['restore'],
|
||||
@@ -925,7 +1117,7 @@ def make_parsers():
|
||||
restore_group = restore_parser.add_argument_group('restore arguments')
|
||||
restore_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to restore from, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to restore from, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
restore_group.add_argument(
|
||||
'--archive', help='Name of archive to restore from (or "latest")', required=True
|
||||
@@ -979,7 +1171,7 @@ def make_parsers():
|
||||
rlist_group = rlist_parser.add_argument_group('rlist arguments')
|
||||
rlist_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to list, defaults to the configured repositories',
|
||||
help='Path of repository to list, defaults to the configured repositories, quoted globs supported',
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--short', default=False, action='store_true', help='Output only archive names'
|
||||
@@ -1039,7 +1231,7 @@ def make_parsers():
|
||||
list_group = list_parser.add_argument_group('list arguments')
|
||||
list_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository containing archive to list, defaults to the configured repositories',
|
||||
help='Path of repository containing archive to list, defaults to the configured repositories, quoted globs supported',
|
||||
)
|
||||
list_group.add_argument('--archive', help='Name of the archive to list (or "latest")')
|
||||
list_group.add_argument(
|
||||
@@ -1106,7 +1298,7 @@ def make_parsers():
|
||||
rinfo_group = rinfo_parser.add_argument_group('rinfo arguments')
|
||||
rinfo_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to show info for, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to show info for, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
rinfo_group.add_argument(
|
||||
'--json', dest='json', default=False, action='store_true', help='Output results as JSON'
|
||||
@@ -1123,7 +1315,7 @@ def make_parsers():
|
||||
info_group = info_parser.add_argument_group('info arguments')
|
||||
info_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository containing archive to show info for, defaults to the configured repository if there is only one',
|
||||
help='Path of repository containing archive to show info for, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
info_group.add_argument('--archive', help='Name of archive to show info for (or "latest")')
|
||||
info_group.add_argument(
|
||||
@@ -1184,7 +1376,7 @@ def make_parsers():
|
||||
break_lock_group = break_lock_parser.add_argument_group('break-lock arguments')
|
||||
break_lock_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to break the lock for, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to break the lock for, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
break_lock_group.add_argument(
|
||||
'-h', '--help', action='help', help='Show this help message and exit'
|
||||
@@ -1224,7 +1416,7 @@ def make_parsers():
|
||||
)
|
||||
key_export_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to export the key for, defaults to the configured repository if there is only one',
|
||||
help='Path of repository to export the key for, defaults to the configured repository if there is only one, quoted globs supported',
|
||||
)
|
||||
key_export_group.add_argument(
|
||||
'--path',
|
||||
@@ -1245,7 +1437,7 @@ def make_parsers():
|
||||
borg_group = borg_parser.add_argument_group('borg arguments')
|
||||
borg_group.add_argument(
|
||||
'--repository',
|
||||
help='Path of repository to pass to Borg, defaults to the configured repositories',
|
||||
help='Path of repository to pass to Borg, defaults to the configured repositories, quoted globs supported',
|
||||
)
|
||||
borg_group.add_argument('--archive', help='Name of archive to pass to Borg (or "latest")')
|
||||
borg_group.add_argument(
|
||||
|
||||
@@ -18,6 +18,7 @@ import borgmatic.actions.config.bootstrap
|
||||
import borgmatic.actions.config.generate
|
||||
import borgmatic.actions.config.validate
|
||||
import borgmatic.actions.create
|
||||
import borgmatic.actions.delete
|
||||
import borgmatic.actions.export_key
|
||||
import borgmatic.actions.export_tar
|
||||
import borgmatic.actions.extract
|
||||
@@ -26,6 +27,7 @@ import borgmatic.actions.list
|
||||
import borgmatic.actions.mount
|
||||
import borgmatic.actions.prune
|
||||
import borgmatic.actions.rcreate
|
||||
import borgmatic.actions.rdelete
|
||||
import borgmatic.actions.restore
|
||||
import borgmatic.actions.rinfo
|
||||
import borgmatic.actions.rlist
|
||||
@@ -286,10 +288,11 @@ def run_actions(
|
||||
global_arguments = arguments['global']
|
||||
dry_run_label = ' (dry run; not making any changes)' if global_arguments.dry_run else ''
|
||||
hook_context = {
|
||||
'repository': repository_path,
|
||||
'repository_label': repository.get('label', ''),
|
||||
'log_file': global_arguments.log_file if global_arguments.log_file else '',
|
||||
# Deprecated: For backwards compatibility with borgmatic < 1.6.0.
|
||||
'repositories': ','.join([repo['path'] for repo in config['repositories']]),
|
||||
'log_file': global_arguments.log_file if global_arguments.log_file else '',
|
||||
'repository': repository_path,
|
||||
}
|
||||
skip_actions = set(get_skip_actions(config, arguments))
|
||||
|
||||
@@ -478,6 +481,26 @@ def run_actions(
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'delete' and action_name not in skip_actions:
|
||||
borgmatic.actions.delete.run_delete(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'rdelete' and action_name not in skip_actions:
|
||||
borgmatic.actions.rdelete.run_rdelete(
|
||||
repository,
|
||||
config,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'borg' and action_name not in skip_actions:
|
||||
borgmatic.actions.borg.run_borg(
|
||||
repository,
|
||||
@@ -556,7 +579,7 @@ def load_configurations(config_filenames, overrides=None, resolve_env=True):
|
||||
)
|
||||
),
|
||||
logging.makeLogRecord(
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=error)
|
||||
dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg=str(error))
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -591,13 +614,13 @@ def log_error_records(
|
||||
level_name = logging._levelToName[levelno]
|
||||
|
||||
if not error:
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=message)
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=str(message))
|
||||
return
|
||||
|
||||
try:
|
||||
raise error
|
||||
except CalledProcessError as error:
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=message)
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=str(message))
|
||||
|
||||
if error.output:
|
||||
try:
|
||||
@@ -616,10 +639,10 @@ def log_error_records(
|
||||
suppress_log=True,
|
||||
)
|
||||
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=error)
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=str(error))
|
||||
except (ValueError, OSError) as error:
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=message)
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=error)
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=str(message))
|
||||
yield log_record(levelno=levelno, levelname=level_name, msg=str(error))
|
||||
except: # noqa: E722
|
||||
# Raising above only as a means of determining the error type. Swallow the exception here
|
||||
# because we don't want the exception to propagate out of this function.
|
||||
|
||||
@@ -50,12 +50,15 @@ def apply_constants(value, constants, shell_escape=False):
|
||||
value[index] = apply_constants(list_value, constants, shell_escape)
|
||||
elif isinstance(value, dict):
|
||||
for option_name, option_value in value.items():
|
||||
shell_escape = (
|
||||
shell_escape
|
||||
or option_name.startswith('before_')
|
||||
or option_name.startswith('after_')
|
||||
or option_name == 'on_error'
|
||||
value[option_name] = apply_constants(
|
||||
option_value,
|
||||
constants,
|
||||
shell_escape=(
|
||||
shell_escape
|
||||
or option_name.startswith('before_')
|
||||
or option_name.startswith('after_')
|
||||
or option_name == 'on_error'
|
||||
),
|
||||
)
|
||||
value[option_name] = apply_constants(option_value, constants, shell_escape)
|
||||
|
||||
return value
|
||||
|
||||
+187
-37
@@ -269,7 +269,8 @@ properties:
|
||||
compression:
|
||||
type: string
|
||||
description: |
|
||||
Type of compression to use when creating archives. See
|
||||
Type of compression to use when creating archives. (Compression
|
||||
level can be added separated with a comma, like "zstd,7".) See
|
||||
http://borgbackup.readthedocs.io/en/stable/usage/create.html for
|
||||
details. Defaults to "lz4".
|
||||
example: lz4
|
||||
@@ -279,6 +280,11 @@ properties:
|
||||
Remote network upload rate limit in kiBytes/second. Defaults to
|
||||
unlimited.
|
||||
example: 100
|
||||
upload_buffer_size:
|
||||
type: integer
|
||||
description: |
|
||||
Size of network upload buffer in MiB. Defaults to no buffer.
|
||||
example: 160
|
||||
retries:
|
||||
type: integer
|
||||
description: |
|
||||
@@ -510,24 +516,25 @@ properties:
|
||||
name:
|
||||
type: string
|
||||
enum:
|
||||
- repository
|
||||
- archives
|
||||
- data
|
||||
- extract
|
||||
- disabled
|
||||
description: |
|
||||
Name of consistency check to run: "repository",
|
||||
"archives", "data", "spot", and/or "extract".
|
||||
"repository" checks the consistency of the
|
||||
repository, "archives" checks all of the
|
||||
archives, "data" verifies the integrity of the
|
||||
data within the archives, "spot" checks that
|
||||
some percentage of source files are found in the
|
||||
most recent archive (with identical contents),
|
||||
and "extract" does an extraction dry-run of the
|
||||
most recent archive. Note that "data" implies
|
||||
"archives". See "skip_actions" for disabling
|
||||
checks altogether.
|
||||
Name of the consistency check to run:
|
||||
* "repository" checks the consistency of the
|
||||
repository.
|
||||
* "archives" checks all of the archives.
|
||||
* "data" verifies the integrity of the data
|
||||
within the archives and implies the "archives"
|
||||
check as well.
|
||||
* "spot" checks that some percentage of source
|
||||
files are found in the most recent archive (with
|
||||
identical contents).
|
||||
* "extract" does an extraction dry-run of the
|
||||
most recent archive.
|
||||
* See "skip_actions" for disabling checks
|
||||
altogether.
|
||||
example: spot
|
||||
frequency:
|
||||
type: string
|
||||
@@ -541,6 +548,80 @@ properties:
|
||||
"always": running this check every time checks
|
||||
are run.
|
||||
example: 2 weeks
|
||||
only_run_on:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: |
|
||||
After the "frequency" duration has elapsed, only
|
||||
run this check if the current day of the week
|
||||
matches one of these values (the name of a day of
|
||||
the week in the current locale). "weekday" and
|
||||
"weekend" are also accepted. Defaults to running
|
||||
the check on any day of the week.
|
||||
example:
|
||||
- Saturday
|
||||
- Sunday
|
||||
- required: [name]
|
||||
additionalProperties: false
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
enum:
|
||||
- repository
|
||||
description: |
|
||||
Name of the consistency check to run:
|
||||
* "repository" checks the consistency of the
|
||||
repository.
|
||||
* "archives" checks all of the archives.
|
||||
* "data" verifies the integrity of the data
|
||||
within the archives and implies the "archives"
|
||||
check as well.
|
||||
* "spot" checks that some percentage of source
|
||||
files are found in the most recent archive (with
|
||||
identical contents).
|
||||
* "extract" does an extraction dry-run of the
|
||||
most recent archive.
|
||||
* See "skip_actions" for disabling checks
|
||||
altogether.
|
||||
example: spot
|
||||
frequency:
|
||||
type: string
|
||||
description: |
|
||||
How frequently to run this type of consistency
|
||||
check (as a best effort). The value is a number
|
||||
followed by a unit of time. E.g., "2 weeks" to
|
||||
run this consistency check no more than every
|
||||
two weeks for a given repository or "1 month" to
|
||||
run it no more than monthly. Defaults to
|
||||
"always": running this check every time checks
|
||||
are run.
|
||||
example: 2 weeks
|
||||
only_run_on:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: |
|
||||
After the "frequency" duration has elapsed, only
|
||||
run this check if the current day of the week
|
||||
matches one of these values (the name of a day of
|
||||
the week in the current locale). "weekday" and
|
||||
"weekend" are also accepted. Defaults to running
|
||||
the check on any day of the week.
|
||||
example:
|
||||
- Saturday
|
||||
- Sunday
|
||||
max_duration:
|
||||
type: integer
|
||||
description: |
|
||||
How many seconds to check the repository before
|
||||
interrupting the check. Useful for splitting a
|
||||
long-running repository check into multiple
|
||||
partial checks. Defaults to no interruption. Only
|
||||
applies to the "repository" check, does not check
|
||||
the repository index, and is not compatible with a
|
||||
simultaneous "archives" check or "--repair" flag.
|
||||
example: 3600
|
||||
- required:
|
||||
- name
|
||||
- count_tolerance_percentage
|
||||
@@ -553,18 +634,20 @@ properties:
|
||||
enum:
|
||||
- spot
|
||||
description: |
|
||||
Name of consistency check to run: "repository",
|
||||
"archives", "data", "spot", and/or "extract".
|
||||
"repository" checks the consistency of the
|
||||
repository, "archives" checks all of the
|
||||
archives, "data" verifies the integrity of the
|
||||
data within the archives, "spot" checks that
|
||||
some percentage of source files are found in the
|
||||
most recent archive (with identical contents),
|
||||
and "extract" does an extraction dry-run of the
|
||||
most recent archive. Note that "data" implies
|
||||
"archives". See "skip_actions" for disabling
|
||||
checks altogether.
|
||||
Name of the consistency check to run:
|
||||
* "repository" checks the consistency of the
|
||||
repository.
|
||||
* "archives" checks all of the archives.
|
||||
* "data" verifies the integrity of the data
|
||||
within the archives and implies the "archives"
|
||||
check as well.
|
||||
* "spot" checks that some percentage of source
|
||||
files are found in the most recent archive (with
|
||||
identical contents).
|
||||
* "extract" does an extraction dry-run of the
|
||||
most recent archive.
|
||||
* See "skip_actions" for disabling checks
|
||||
altogether.
|
||||
example: repository
|
||||
frequency:
|
||||
type: string
|
||||
@@ -578,6 +661,20 @@ properties:
|
||||
"always": running this check every time checks
|
||||
are run.
|
||||
example: 2 weeks
|
||||
only_run_on:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: |
|
||||
After the "frequency" duration has elapsed, only
|
||||
run this check if the current day of the week
|
||||
matches one of these values (the name of a day of
|
||||
the week in the current locale). "weekday" and
|
||||
"weekend" are also accepted. Defaults to running
|
||||
the check on any day of the week.
|
||||
example:
|
||||
- Saturday
|
||||
- Sunday
|
||||
count_tolerance_percentage:
|
||||
type: number
|
||||
description: |
|
||||
@@ -586,7 +683,8 @@ properties:
|
||||
archive file count that is allowed before the
|
||||
entire consistency check fails. This can catch
|
||||
problems like incorrect excludes, inadvertent
|
||||
deletes, etc. Only applies to the "spot" check.
|
||||
deletes, etc. Required (and only valid) for the
|
||||
"spot" check.
|
||||
example: 10
|
||||
data_sample_percentage:
|
||||
type: number
|
||||
@@ -594,7 +692,8 @@ properties:
|
||||
The percentage of total files in the source
|
||||
directories to randomly sample and compare to
|
||||
their corresponding files in the most recent
|
||||
backup archive. Only applies to the "spot" check.
|
||||
backup archive. Required (and only valid) for the
|
||||
"spot" check.
|
||||
example: 1
|
||||
data_tolerance_percentage:
|
||||
type: number
|
||||
@@ -606,7 +705,7 @@ properties:
|
||||
been bulk-changed by malware, backups that have
|
||||
been tampered with, etc. The value must be lower
|
||||
than or equal to the "contents_sample_percentage".
|
||||
Only applies to the "spot" check.
|
||||
Required (and only valid) for the "spot" check.
|
||||
example: 0.5
|
||||
xxh64sum_command:
|
||||
type: string
|
||||
@@ -615,7 +714,7 @@ properties:
|
||||
source files, usually found in an OS package named
|
||||
"xxhash". Do not substitute with a different hash
|
||||
type (SHA, MD5, etc.) or the check will never
|
||||
succeed. Only applies to the "spot" check.
|
||||
succeed. Only valid for the "spot" check.
|
||||
example: /usr/local/bin/xxh64sum
|
||||
description: |
|
||||
List of one or more consistency checks to run on a periodic basis
|
||||
@@ -656,11 +755,13 @@ properties:
|
||||
- compact
|
||||
- create
|
||||
- check
|
||||
- delete
|
||||
- extract
|
||||
- config
|
||||
- export-tar
|
||||
- mount
|
||||
- umount
|
||||
- rdelete
|
||||
- restore
|
||||
- rlist
|
||||
- list
|
||||
@@ -943,9 +1044,12 @@ properties:
|
||||
description: |
|
||||
Command to use instead of "pg_dump" or "pg_dumpall".
|
||||
This can be used to run a specific pg_dump version
|
||||
(e.g., one inside a running container). Defaults to
|
||||
"pg_dump" for single database dump or "pg_dumpall" to
|
||||
dump all databases.
|
||||
(e.g., one inside a running container). If you run it
|
||||
from within a container, make sure to mount your
|
||||
host's ".borgmatic" folder into the container using
|
||||
the same directory structure. Defaults to "pg_dump"
|
||||
for single database dump or "pg_dumpall" to dump all
|
||||
databases.
|
||||
example: docker exec my_pg_container pg_dump
|
||||
pg_restore_command:
|
||||
type: string
|
||||
@@ -1059,7 +1163,10 @@ properties:
|
||||
description: |
|
||||
Command to use instead of "mariadb-dump". This can be
|
||||
used to run a specific mariadb_dump version (e.g., one
|
||||
inside a running container). Defaults to "mariadb-dump".
|
||||
inside a running container). If you run it from within
|
||||
a container, make sure to mount your host's
|
||||
".borgmatic" folder into the container using the same
|
||||
directory structure. Defaults to "mariadb-dump".
|
||||
example: docker exec mariadb_container mariadb-dump
|
||||
mariadb_command:
|
||||
type: string
|
||||
@@ -1187,9 +1294,12 @@ properties:
|
||||
mysql_dump_command:
|
||||
type: string
|
||||
description: |
|
||||
Command to use instead of "mysqldump". This can be used
|
||||
to run a specific mysql_dump version (e.g., one inside a
|
||||
running container). Defaults to "mysqldump".
|
||||
Command to use instead of "mysqldump". This can be
|
||||
used to run a specific mysql_dump version (e.g., one
|
||||
inside a running container). If you run it from within
|
||||
a container, make sure to mount your host's
|
||||
".borgmatic" folder into the container using the same
|
||||
directory structure. Defaults to "mysqldump".
|
||||
example: docker exec mysql_container mysqldump
|
||||
mysql_command:
|
||||
type: string
|
||||
@@ -1662,11 +1772,51 @@ properties:
|
||||
states.
|
||||
example:
|
||||
- finish
|
||||
create_slug:
|
||||
type: boolean
|
||||
description: |
|
||||
Create the check if it does not exist. Only works with
|
||||
the slug URL scheme (https://hc-ping.com/<ping-key>/<slug>
|
||||
as opposed to https://hc-ping.com/<uuid>).
|
||||
Defaults to false.
|
||||
example: true
|
||||
description: |
|
||||
Configuration for a monitoring integration with Healthchecks. Create
|
||||
an account at https://healthchecks.io (or self-host Healthchecks) if
|
||||
you'd like to use this service. See borgmatic monitoring
|
||||
documentation for details.
|
||||
uptime_kuma:
|
||||
type: object
|
||||
required: ['push_url']
|
||||
additionalProperties: false
|
||||
properties:
|
||||
push_url:
|
||||
type: string
|
||||
description: |
|
||||
Uptime Kuma push URL without query string (do not include the
|
||||
question mark or anything after it).
|
||||
example: https://example.uptime.kuma/api/push/abcd1234
|
||||
states:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
enum:
|
||||
- start
|
||||
- finish
|
||||
- fail
|
||||
uniqueItems: true
|
||||
description: |
|
||||
List of one or more monitoring states to push for: "start",
|
||||
"finish", and/or "fail". Defaults to pushing for all
|
||||
states.
|
||||
example:
|
||||
- start
|
||||
- finish
|
||||
- fail
|
||||
description: |
|
||||
Configuration for a monitoring integration with Uptime Kuma using
|
||||
the Push monitor type.
|
||||
See more information here: https://uptime.kuma.pet
|
||||
cronitor:
|
||||
type: object
|
||||
required: ['ping_url']
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import fnmatch
|
||||
import os
|
||||
|
||||
import jsonschema
|
||||
@@ -149,18 +150,30 @@ def normalize_repository_path(repository):
|
||||
return repository
|
||||
|
||||
|
||||
def glob_match(first, second):
|
||||
'''
|
||||
Given two strings, return whether the first matches the second. Globs are
|
||||
supported.
|
||||
'''
|
||||
if first is None or second is None:
|
||||
return False
|
||||
|
||||
return fnmatch.fnmatch(first, second) or fnmatch.fnmatch(second, first)
|
||||
|
||||
|
||||
def repositories_match(first, second):
|
||||
'''
|
||||
Given two repository dicts with keys 'path' (relative and/or absolute),
|
||||
and 'label', or two repository paths, return whether they match.
|
||||
Given two repository dicts with keys "path" (relative and/or absolute),
|
||||
and "label", two repository paths as strings, or a mix of the two formats,
|
||||
return whether they match. Globs are supported.
|
||||
'''
|
||||
if isinstance(first, str):
|
||||
first = {'path': first, 'label': first}
|
||||
if isinstance(second, str):
|
||||
second = {'path': second, 'label': second}
|
||||
return (first.get('label') == second.get('label')) or (
|
||||
normalize_repository_path(first.get('path'))
|
||||
== normalize_repository_path(second.get('path'))
|
||||
|
||||
return glob_match(first.get('label'), second.get('label')) or glob_match(
|
||||
normalize_repository_path(first.get('path')), normalize_repository_path(second.get('path'))
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ from borgmatic.hooks import (
|
||||
pagerduty,
|
||||
postgresql,
|
||||
sqlite,
|
||||
uptimekuma,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -22,6 +23,7 @@ HOOK_NAME_TO_MODULE = {
|
||||
'cronhub': cronhub,
|
||||
'cronitor': cronitor,
|
||||
'healthchecks': healthchecks,
|
||||
'loki': loki,
|
||||
'mariadb_databases': mariadb,
|
||||
'mongodb_databases': mongodb,
|
||||
'mysql_databases': mysql,
|
||||
@@ -29,7 +31,7 @@ HOOK_NAME_TO_MODULE = {
|
||||
'pagerduty': pagerduty,
|
||||
'postgresql_databases': postgresql,
|
||||
'sqlite_databases': sqlite,
|
||||
'loki': loki,
|
||||
'uptime_kuma': uptimekuma,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
import requests
|
||||
|
||||
@@ -14,7 +15,7 @@ MONITOR_STATE_TO_HEALTHCHECKS = {
|
||||
monitor.State.LOG: 'log',
|
||||
}
|
||||
|
||||
DEFAULT_PING_BODY_LIMIT_BYTES = 1500
|
||||
DEFAULT_PING_BODY_LIMIT_BYTES = 100000
|
||||
HANDLER_IDENTIFIER = 'healthchecks'
|
||||
|
||||
|
||||
@@ -59,10 +60,20 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
||||
)
|
||||
return
|
||||
|
||||
ping_url_is_uuid = re.search(r'\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$', ping_url)
|
||||
|
||||
healthchecks_state = MONITOR_STATE_TO_HEALTHCHECKS.get(state)
|
||||
if healthchecks_state:
|
||||
ping_url = f'{ping_url}/{healthchecks_state}'
|
||||
|
||||
if hook_config.get('create_slug'):
|
||||
if ping_url_is_uuid:
|
||||
logger.warning(
|
||||
f'{config_filename}: Healthchecks UUIDs do not support auto provisionning; ignoring'
|
||||
)
|
||||
else:
|
||||
ping_url = f'{ping_url}?create=1'
|
||||
|
||||
logger.info(f'{config_filename}: Pinging Healthchecks {state.name.lower()}{dry_run_label}')
|
||||
logger.debug(f'{config_filename}: Using Healthchecks ping URL {ping_url}')
|
||||
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
from enum import Enum
|
||||
|
||||
MONITOR_HOOK_NAMES = ('apprise', 'healthchecks', 'cronitor', 'cronhub', 'pagerduty', 'ntfy', 'loki')
|
||||
MONITOR_HOOK_NAMES = (
|
||||
'apprise',
|
||||
'cronhub',
|
||||
'cronitor',
|
||||
'healthchecks',
|
||||
'loki',
|
||||
'ntfy',
|
||||
'pagerduty',
|
||||
'uptime_kuma',
|
||||
)
|
||||
|
||||
|
||||
class State(Enum):
|
||||
|
||||
@@ -40,9 +40,7 @@ def ping_monitor(hook_config, config, config_filename, state, monitoring_log_lev
|
||||
return
|
||||
|
||||
hostname = platform.node()
|
||||
local_timestamp = (
|
||||
datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).astimezone().isoformat()
|
||||
)
|
||||
local_timestamp = datetime.datetime.now(datetime.timezone.utc).astimezone().isoformat()
|
||||
payload = json.dumps(
|
||||
{
|
||||
'routing_key': hook_config['integration_key'],
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def initialize_monitor(
|
||||
push_url, config, config_filename, monitoring_log_level, dry_run
|
||||
): # pragma: no cover
|
||||
'''
|
||||
No initialization is necessary for this monitor.
|
||||
'''
|
||||
pass
|
||||
|
||||
|
||||
def ping_monitor(hook_config, config, config_filename, state, monitoring_log_level, dry_run):
|
||||
'''
|
||||
Make a get request to the configured Uptime Kuma push_url. Use the given configuration filename
|
||||
in any log entries. If this is a dry run, then don't actually push anything.
|
||||
'''
|
||||
run_states = hook_config.get('states', ['start', 'finish', 'fail'])
|
||||
|
||||
if state.name.lower() not in run_states:
|
||||
return
|
||||
|
||||
dry_run_label = ' (dry run; not actually pushing)' if dry_run else ''
|
||||
status = 'down' if state.name.lower() == 'fail' else 'up'
|
||||
push_url = hook_config.get('push_url', 'https://example.uptime.kuma/api/push/abcd1234')
|
||||
query = f'status={status}&msg={state.name.lower()}'
|
||||
logger.info(
|
||||
f'{config_filename}: Pushing Uptime Kuma push_url {push_url}?{query} {dry_run_label}'
|
||||
)
|
||||
logger.debug(f'{config_filename}: Full Uptime Kuma state URL {push_url}?{query}')
|
||||
|
||||
if dry_run:
|
||||
return
|
||||
|
||||
logging.getLogger('urllib3').setLevel(logging.ERROR)
|
||||
|
||||
try:
|
||||
response = requests.get(f'{push_url}?{query}')
|
||||
if not response.ok:
|
||||
response.raise_for_status()
|
||||
except requests.exceptions.RequestException as error:
|
||||
logger.warning(f'{config_filename}: Uptime Kuma error: {error}')
|
||||
|
||||
|
||||
def destroy_monitor(
|
||||
push_url_or_uuid, config, config_filename, monitoring_log_level, dry_run
|
||||
): # pragma: no cover
|
||||
'''
|
||||
No destruction is necessary for this monitor.
|
||||
'''
|
||||
pass
|
||||
+8
-1
@@ -38,7 +38,7 @@ def should_do_markup(no_color, configs):
|
||||
if no_color:
|
||||
return False
|
||||
|
||||
if any(config.get('output', {}).get('color') is False for config in configs.values()):
|
||||
if any(config.get('color', True) is False for config in configs.values()):
|
||||
return False
|
||||
|
||||
if os.environ.get('NO_COLOR', None):
|
||||
@@ -88,6 +88,11 @@ class Multi_stream_handler(logging.Handler):
|
||||
handler.setLevel(level)
|
||||
|
||||
|
||||
class Console_no_color_formatter(logging.Formatter):
|
||||
def format(self, record): # pragma: no cover
|
||||
return record.msg
|
||||
|
||||
|
||||
class Console_color_formatter(logging.Formatter):
|
||||
def format(self, record):
|
||||
add_custom_log_levels()
|
||||
@@ -198,6 +203,8 @@ def configure_logging(
|
||||
|
||||
if color_enabled:
|
||||
console_handler.setFormatter(Console_color_formatter())
|
||||
else:
|
||||
console_handler.setFormatter(Console_no_color_formatter())
|
||||
|
||||
console_handler.setLevel(console_log_level)
|
||||
|
||||
|
||||
+7
-5
@@ -1,14 +1,15 @@
|
||||
FROM docker.io/alpine:3.17.1 as borgmatic
|
||||
FROM docker.io/alpine:3.20.1 AS borgmatic
|
||||
|
||||
COPY . /app
|
||||
RUN apk add --no-cache py3-pip py3-ruamel.yaml py3-ruamel.yaml.clib
|
||||
RUN pip install --no-cache /app && generate-borgmatic-config && chmod +r /etc/borgmatic/config.yaml
|
||||
RUN pip install --break-system-packages --no-cache /app && generate-borgmatic-config && chmod +r /etc/borgmatic/config.yaml
|
||||
RUN borgmatic --help > /command-line.txt \
|
||||
&& for action in rcreate transfer create prune compact check extract config "config bootstrap" "config generate" "config validate" export-tar mount umount restore rlist list rinfo info break-lock borg; do \
|
||||
&& for action in rcreate transfer create prune compact check delete extract config "config bootstrap" "config generate" "config validate" export-tar mount umount rdelete restore rlist list rinfo info break-lock borg; do \
|
||||
echo -e "\n--------------------------------------------------------------------------------\n" >> /command-line.txt \
|
||||
&& borgmatic $action --help >> /command-line.txt; done
|
||||
RUN /app/docs/fetch-contributors >> /contributors.html
|
||||
|
||||
FROM docker.io/node:19.5.0-alpine as html
|
||||
FROM docker.io/node:22.4.0-alpine AS html
|
||||
|
||||
ARG ENVIRONMENT=production
|
||||
|
||||
@@ -24,11 +25,12 @@ RUN npm install @11ty/eleventy \
|
||||
markdown-it-replace-link
|
||||
COPY --from=borgmatic /etc/borgmatic/config.yaml /source/docs/_includes/borgmatic/config.yaml
|
||||
COPY --from=borgmatic /command-line.txt /source/docs/_includes/borgmatic/command-line.txt
|
||||
COPY --from=borgmatic /contributors.html /source/docs/_includes/borgmatic/contributors.html
|
||||
COPY . /source
|
||||
RUN NODE_ENV=${ENVIRONMENT} npx eleventy --input=/source/docs --output=/output/docs \
|
||||
&& mv /output/docs/index.html /output/index.html
|
||||
|
||||
FROM docker.io/nginx:1.22.1-alpine
|
||||
FROM docker.io/nginx:1.26.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
|
||||
|
||||
@@ -167,12 +167,11 @@ li {
|
||||
padding: .25em 0;
|
||||
}
|
||||
li ul {
|
||||
margin: .5em 0;
|
||||
padding-left: 1em;
|
||||
list-style-type: disc;
|
||||
padding-left: 2em;
|
||||
}
|
||||
li li {
|
||||
padding-top: .1em;
|
||||
padding-bottom: .1em;
|
||||
li li:last-child {
|
||||
padding-bottom: 0em;
|
||||
}
|
||||
|
||||
/* Syntax highlighting and Code blocks */
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
version: '3'
|
||||
services:
|
||||
docs:
|
||||
image: borgmatic-docs
|
||||
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
'''
|
||||
A script to fetch recent contributors to borgmatic, used during documentation generation.
|
||||
'''
|
||||
|
||||
import datetime
|
||||
import itertools
|
||||
import operator
|
||||
import subprocess
|
||||
|
||||
import requests
|
||||
|
||||
|
||||
def list_merged_pulls(url):
|
||||
'''
|
||||
Given a Gitea or GitHub API endpoint URL for pull requests, fetch and return the corresponding
|
||||
JSON for all such merged pull requests.
|
||||
'''
|
||||
response = requests.get(f'{url}?state=closed', headers={'Accept': 'application/json', 'Content-Type': 'application/json'})
|
||||
|
||||
if not response.ok:
|
||||
response.raise_for_status()
|
||||
|
||||
return tuple(pull for pull in response.json() if pull.get('merged_at'))
|
||||
|
||||
|
||||
API_ENDPOINT_URLS = (
|
||||
'https://projects.torsion.org/api/v1/repos/borgmatic-collective/borgmatic/pulls',
|
||||
'https://api.github.com/repos/borgmatic-collective/borgmatic/pulls',
|
||||
)
|
||||
RECENT_CONTRIBUTORS_CUTOFF_DAYS = 365
|
||||
|
||||
|
||||
def print_contributors():
|
||||
'''
|
||||
Display the recent contributors as a row of avatars in an HTML fragment.
|
||||
'''
|
||||
pulls = tuple(itertools.chain.from_iterable(list_merged_pulls(url) for url in API_ENDPOINT_URLS))
|
||||
seen_user_ids = set()
|
||||
|
||||
print('<p>')
|
||||
|
||||
for pull in sorted(pulls, key=operator.itemgetter('merged_at'), reverse=True):
|
||||
merged_at = pull.get('merged_at')
|
||||
user = pull.get('user')
|
||||
|
||||
if not merged_at or not user:
|
||||
continue
|
||||
|
||||
user_id = user.get('id')
|
||||
|
||||
if not user_id or user_id in seen_user_ids:
|
||||
continue
|
||||
|
||||
if datetime.datetime.fromisoformat(merged_at) < datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=RECENT_CONTRIBUTORS_CUTOFF_DAYS):
|
||||
continue
|
||||
|
||||
seen_user_ids.add(user_id)
|
||||
print(
|
||||
f'''<a href="{user.get('html_url')}?tab=activity"><img src="{user.get('avatar_url')}" width="50" height="50" title="{user.get('full_name') or user.get('login')}" /></a>'''
|
||||
)
|
||||
|
||||
print('</p>')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print_contributors()
|
||||
@@ -84,6 +84,9 @@ variables you can use here:
|
||||
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
|
||||
* `repository_label` <span class="minilink minilink-addedin">New in version
|
||||
1.8.12</span>: label of the current repository as configured in the current
|
||||
borgmatic configuration file
|
||||
|
||||
Note that you can also interpolate in [arbitrary environment
|
||||
variables](https://torsion.org/borgmatic/docs/how-to/provide-your-passwords/).
|
||||
|
||||
@@ -229,7 +229,20 @@ hooks:
|
||||
|
||||
... where `my_pg_container` is the name of your database container. In this
|
||||
example, you'd also need to set the `pg_restore_command` and `psql_command`
|
||||
options.
|
||||
options. If you choose to use the `pg_dump` command within the container
|
||||
though, note that it will output the database dump to a file inside the
|
||||
container. So you'll have to mount the `.borgmatic` folder from your host's
|
||||
home folder into the container using the same directory structure.
|
||||
|
||||
See the following Docker compose file an as example:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
volumes:
|
||||
- /home/USERNAME/.borgmatic:/home/USERNAME/.borgmatic
|
||||
```
|
||||
|
||||
Similar command override options are available for (some of) the other
|
||||
supported database types as well. See the [configuration
|
||||
@@ -437,19 +450,28 @@ borgmatic's own configuration file. So include your configuration file in
|
||||
backups to avoid getting caught without a way to restore a database.
|
||||
3. borgmatic does not currently support backing up or restoring multiple
|
||||
databases that share the exact same name on different hosts.
|
||||
4. Because database hooks implicitly enable the `read_special` configuration,
|
||||
any special files are excluded from backups (named pipes, block devices,
|
||||
character devices, and sockets) to prevent hanging. Try a command like `find
|
||||
/your/source/path -type b -or -type c -or -type p -or -type s` to find such
|
||||
files. Common directories to exclude are `/dev` and `/run`, but that may not
|
||||
be exhaustive. <span class="minilink minilink-addedin">New in version
|
||||
1.7.3</span> When database hooks are enabled, borgmatic automatically excludes
|
||||
special files (and symlinks to special files) that may cause Borg to hang, so
|
||||
generally you no longer need to manually exclude them. There are potential
|
||||
edge cases though in which applications on your system create new special files
|
||||
*after* borgmatic constructs its exclude list, resulting in Borg hangs. If that
|
||||
occurs, you can resort to the manual excludes described above. And to opt out
|
||||
of the auto-exclude feature entirely, explicitly set `read_special` to true.
|
||||
4. When database hooks are enabled, borgmatic instructs Borg to consume
|
||||
special files (via `--read-special`) to support database dump
|
||||
streaming—regardless of the value of your `read_special` configuration option.
|
||||
And because this can cause Borg to hang, borgmatic also automatically excludes
|
||||
special files (and symlinks to them) that Borg may get stuck on. Even so,
|
||||
there are still potential edge cases in which applications on your system
|
||||
create new special files *after* borgmatic constructs its exclude list,
|
||||
resulting in Borg hangs. If that occurs, you can resort to manually excluding
|
||||
those files. And if you explicitly set the `read-special` option to `true`,
|
||||
borgmatic will opt you out of the auto-exclude feature entirely, but will
|
||||
still instruct Borg to consume special files—you will just be on your own to
|
||||
exclude them. <span class="minilink minilink-addedin">Prior to version
|
||||
1.7.3</span>Special files were not auto-excluded, and you were responsible for
|
||||
excluding them yourself. Common directories to exclude are `/dev` and `/run`,
|
||||
but that may not be exhaustive.
|
||||
5. Database hooks also implicitly enable the `one_file_system` option, which
|
||||
means Borg won't cross filesystem boundaries when looking for files to backup.
|
||||
This is especially important when running borgmatic in a container, as
|
||||
container volumes are mounted as separate filesystems. One work-around is to
|
||||
explicitly add each mounted volume you'd like to backup to
|
||||
`source_directories` instead of relying on Borg to include them implicitly via
|
||||
a parent directory.
|
||||
|
||||
|
||||
### Manual restoration
|
||||
|
||||
@@ -48,7 +48,7 @@ support for [more granular exit
|
||||
codes](https://borgbackup.readthedocs.io/en/1.4-maint/usage/general.html#return-codes)
|
||||
means that you can configure borgmatic to respond to specific Borg conditions.
|
||||
See the full list of [Borg 1.4 error and warning exit
|
||||
codes](https://borgbackup.readthedocs.io/en/1.4.0b1/internals/frontends.html#message-ids).
|
||||
codes](https://borgbackup.readthedocs.io/en/stable/internals/frontends.html#message-ids).
|
||||
The `rc:` numeric value there tells you the exit code for each.
|
||||
|
||||
For instance, this borgmatic configuration elevates all Borg backup file
|
||||
|
||||
@@ -20,7 +20,7 @@ default action ordering was `prune`, `compact`, `create`, and `check`.
|
||||
### A la carte actions
|
||||
|
||||
If you find yourself wanting to customize the actions, you have some options.
|
||||
First, you can run borgmatic's `prune`, `compact`, `create`, or `check`
|
||||
First, you can run borgmatic's `create`, `prune`, `compact`, or `check`
|
||||
actions separately. For instance, the following optional actions are
|
||||
available (among others):
|
||||
|
||||
@@ -121,7 +121,7 @@ incorrect excludes, inadvertent deletes, files changed by malware, etc.
|
||||
|
||||
However, because an exhaustive comparison of all source files against the
|
||||
latest archive might be too slow, the spot check supports *sampling* a
|
||||
percentage of your source files for the comparison, ensuring it falls within
|
||||
percentage of your source files for the comparison, ensuring they fall within
|
||||
configured tolerances.
|
||||
|
||||
Here's how it works. Start by installing the `xxhash` OS package if you don't
|
||||
@@ -149,17 +149,17 @@ fail.)
|
||||
The `data_sample_percentage` is the percentage of total files in the source
|
||||
directories to randomly sample and compare to their corresponding files in the
|
||||
latest backup archive. A higher value allows a more accurate check—and a
|
||||
slower one. The comparison is performed by hashing the selected files in each
|
||||
of the source paths and counting hashes that don't match the latest archive.
|
||||
For instance, if you have 1,000 source files and your sample percentage is 1%,
|
||||
then only 10 source files will be compared against the latest archive. These
|
||||
sampled files are selected randomly each time, so in effect the spot check is
|
||||
probabilistic.
|
||||
slower one. The comparison is performed by hashing the selected source files
|
||||
and counting hashes that don't match the latest archive. For instance, if you
|
||||
have 1,000 source files and your sample percentage is 1%, then only 10 source
|
||||
files will be compared against the latest archive. These sampled files are
|
||||
selected randomly each time, so in effect the spot check is probabilistic.
|
||||
|
||||
The `data_tolerance_percentage` is the percentage of total files in the source
|
||||
directories that can fail a spot check data comparison without failing the
|
||||
entire consistency check. The value must be lower than or equal to the
|
||||
`contents_sample_percentage`.
|
||||
`data_sample_percentage`, because `data_tolerance_percentage` only looks at
|
||||
at the sampled files as determined by `data_sample_percentage`.
|
||||
|
||||
All three options are required when using the spot check. And because the
|
||||
check relies on these configured tolerances, it may not be a
|
||||
@@ -175,6 +175,11 @@ want the spot check to fail the next time it's run? Run `borgmatic create` to
|
||||
create a new backup, thereby allowing the next spot check to run against an
|
||||
archive that contains your recent changes.
|
||||
|
||||
Because the spot check only looks at the most recent archive, you may not want
|
||||
to run it immediately after a `create` action (borgmatic's default behavior).
|
||||
Instead, it may make more sense to run the spot check on a separate schedule
|
||||
from `create`.
|
||||
|
||||
As long as the spot check feature is in beta, it may be subject to breaking
|
||||
changes. But feel free to use it in production if you're okay with that
|
||||
caveat, and please [provide any
|
||||
@@ -237,6 +242,57 @@ check --force` runs `check` even if it's specified in the `skip_actions`
|
||||
option.
|
||||
|
||||
|
||||
### Check days
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.8.13</span> You can
|
||||
optionally configure checks to only run on particular days of the week. For
|
||||
instance:
|
||||
|
||||
```yaml
|
||||
checks:
|
||||
- name: repository
|
||||
only_run_on:
|
||||
- Saturday
|
||||
- Sunday
|
||||
- name: archives
|
||||
only_run_on:
|
||||
- weekday
|
||||
- name: spot
|
||||
only_run_on:
|
||||
- Friday
|
||||
- weekend
|
||||
```
|
||||
|
||||
Each day of the week is specified in the current locale (system
|
||||
language/country settings). `weekend` and `weekday` are also accepted.
|
||||
|
||||
Just like with `frequency`, borgmatic only makes a best effort to run checks
|
||||
on the given day of the week. For instance, if you run `borgmatic check`
|
||||
daily, then every day borgmatic will have an opportunity to determine whether
|
||||
your checks are configured to run on that day. If they are, then the checks
|
||||
run. If not, they are skipped.
|
||||
|
||||
For instance, with the above configuration, if borgmatic is run on a Saturday,
|
||||
the `repository` check will run. But on a Monday? The repository check will
|
||||
get skipped. And if borgmatic is never run on a Saturday or a Sunday, that
|
||||
check will never get a chance to run.
|
||||
|
||||
Also, the day of the week configuration applies *after* any configured
|
||||
`frequency` for a check. So for instance, imagine the following configuration:
|
||||
|
||||
```yaml
|
||||
checks:
|
||||
- name: repository
|
||||
frequency: 2 weeks
|
||||
only_run_on:
|
||||
- Monday
|
||||
```
|
||||
|
||||
If you run borgmatic daily with that configuration, then borgmatic will first
|
||||
wait two weeks after the previous check before running the check again—on the
|
||||
first Monday after the `frequency` duration elapses.
|
||||
|
||||
|
||||
### Running only checks
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.1</span> If you
|
||||
|
||||
@@ -102,9 +102,9 @@ and depend on containers for runtime dependencies. These tests do run on the
|
||||
continuous integration (CI) server, and running them on your developer machine
|
||||
is the closest thing to dev-CI parity.
|
||||
|
||||
If you would like to run the full test suite, first install Docker (or Podman;
|
||||
see below) and [Docker Compose](https://docs.docker.com/compose/install/).
|
||||
Then run:
|
||||
If you would like to run the end-to-end tests, first install Docker (or
|
||||
Podman; see below) and [Docker
|
||||
Compose](https://docs.docker.com/compose/install/). Then run:
|
||||
|
||||
```bash
|
||||
scripts/run-end-to-end-tests
|
||||
@@ -152,12 +152,21 @@ the following deviations from it:
|
||||
* In general, spell out words in variable names instead of shortening them.
|
||||
So, think `index` instead of `idx`. There are some notable exceptions to
|
||||
this though (like `config`).
|
||||
* Favor blank lines around logical code groupings, `if` statements,
|
||||
`return`s, etc. Readability is more important than packing code tightly.
|
||||
* Import fully qualified Python modules instead of importing individual
|
||||
functions, classes, or constants. E.g., do `import os.path` instead of
|
||||
`from os import path`. (Some exceptions to this are made in tests.)
|
||||
* Only use classes and OOP as a last resort, such as when integrating with
|
||||
Python libraries that require it.
|
||||
* Prefer functional code where it makes sense, e.g. when constructing a
|
||||
command (to subsequently execute imperatively).
|
||||
|
||||
borgmatic code uses the [Black](https://black.readthedocs.io/en/stable/) code
|
||||
borgmatic uses the [Black](https://black.readthedocs.io/en/stable/) code
|
||||
formatter, the [Flake8](http://flake8.pycqa.org/en/latest/) code checker, and
|
||||
the [isort](https://github.com/timothycrosley/isort) import orderer, so
|
||||
certain code style requirements will be enforced when running automated tests.
|
||||
See the Black, Flake8, and isort documentation for more information.
|
||||
certain code style requirements are enforced when running automated tests. See
|
||||
the Black, Flake8, and isort documentation for more information.
|
||||
|
||||
|
||||
## Continuous integration
|
||||
|
||||
@@ -133,7 +133,7 @@ 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).
|
||||
documentation](https://borgbackup.readthedocs.io/en/2.0.0b8/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`
|
||||
|
||||
@@ -39,13 +39,14 @@ below for how to configure this.
|
||||
borgmatic integrates with these monitoring services and libraries, pinging
|
||||
them as backups happen:
|
||||
|
||||
* [Healthchecks](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#healthchecks-hook)
|
||||
* [Cronitor](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronitor-hook)
|
||||
* [Cronhub](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronhub-hook)
|
||||
* [PagerDuty](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#pagerduty-hook)
|
||||
* [ntfy](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#ntfy-hook)
|
||||
* [Grafana Loki](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#loki-hook)
|
||||
* [Apprise](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#apprise-hook)
|
||||
* [Cronhub](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronhub-hook)
|
||||
* [Cronitor](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#cronitor-hook)
|
||||
* [Grafana Loki](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#loki-hook)
|
||||
* [Healthchecks](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#healthchecks-hook)
|
||||
* [ntfy](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#ntfy-hook)
|
||||
* [PagerDuty](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#pagerduty-hook)
|
||||
* [Uptime Kuma](https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#uptime-kuma-hook)
|
||||
|
||||
The idea is that you'll receive an alert when something goes wrong or when the
|
||||
service doesn't hear from borgmatic for a configured interval (if supported).
|
||||
@@ -208,8 +209,8 @@ cronitor:
|
||||
this option in the `hooks:` section of your configuration.
|
||||
|
||||
With this configuration, borgmatic pings your Cronitor monitor when a backup
|
||||
begins, ends, or errors, but only when any of the `prune`, `compact`,
|
||||
`create`, or `check` actions are run. Then, if the actions complete
|
||||
begins, ends, or errors, but only when any of the `create`, `prune`,
|
||||
`compact`, or `check` actions are run. Then, if the actions complete
|
||||
successfully or errors, borgmatic notifies Cronitor accordingly.
|
||||
|
||||
You can configure Cronitor to notify you by a [variety of
|
||||
@@ -235,8 +236,8 @@ cronhub:
|
||||
this option in the `hooks:` section of your configuration.
|
||||
|
||||
With this configuration, borgmatic pings your Cronhub monitor when a backup
|
||||
begins, ends, or errors, but only when any of the `prune`, `compact`,
|
||||
`create`, or `check` actions are run. Then, if the actions complete
|
||||
begins, ends, or errors, but only when any of the `create`, `prune`,
|
||||
`compact`, or `check` actions are run. Then, if the actions complete
|
||||
successfully or errors, borgmatic notifies Cronhub accordingly.
|
||||
|
||||
Note that even though you configure borgmatic with the "start" variant of the
|
||||
@@ -368,7 +369,7 @@ loki:
|
||||
```
|
||||
|
||||
With this configuration, borgmatic sends its logs to your Loki instance as any
|
||||
of the `prune`, `compact`, `create`, or `check` actions are run. Then, after
|
||||
of the `create`, `prune`, `compact`, or `check` actions are run. Then, after
|
||||
the actions complete, borgmatic notifies Loki of success or failure.
|
||||
|
||||
This hook supports sending arbitrary labels to Loki. For instance:
|
||||
@@ -420,7 +421,8 @@ pipx](https://torsion.org/borgmatic/docs/how-to/set-up-backups/#installation),
|
||||
run the following to install Apprise so borgmatic can use it:
|
||||
|
||||
```bash
|
||||
sudo pipx install --force borgmatic[Apprise]
|
||||
sudo pipx uninstall borgmatic
|
||||
sudo pipx install borgmatic[Apprise]
|
||||
```
|
||||
|
||||
Omit `sudo` if borgmatic is installed as a non-root user.
|
||||
@@ -435,11 +437,16 @@ apprise:
|
||||
label: gotify
|
||||
- url: mastodons://access_key@hostname/@user
|
||||
label: mastodon
|
||||
states:
|
||||
- start
|
||||
- finish
|
||||
- fail
|
||||
```
|
||||
|
||||
With this configuration, borgmatic pings each of the configured Apprise
|
||||
services when a backup begins, ends, or errors, but only when any of the
|
||||
`prune`, `compact`, `create`, or `check` actions are run.
|
||||
`create`, `prune`, `compact`, or `check` actions are run. (By default, if
|
||||
`states` is not specified, Apprise services are only pinged on error.)
|
||||
|
||||
You can optionally customize the contents of the default messages sent to
|
||||
these services:
|
||||
@@ -499,6 +506,62 @@ See the [configuration
|
||||
reference](https://torsion.org/borgmatic/docs/reference/configuration/) for
|
||||
details.
|
||||
|
||||
## Uptime Kuma hook
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.8.13</span> [Uptime
|
||||
Kuma](https://uptime.kuma.pet) is an easy-to-use, self-hosted monitoring tool
|
||||
and can provide a Push monitor type to accept HTTP `GET` requests from a
|
||||
service instead of contacting it directly.
|
||||
|
||||
Uptime Kuma allows you to see a history of monitor states and can in turn
|
||||
alert via ntfy, Gotify, Matrix, Apprise, Email, and many more.
|
||||
|
||||
An example configuration is shown here with all the available options:
|
||||
|
||||
```yaml
|
||||
uptime_kuma:
|
||||
push_url: https://kuma.my-domain.com/api/push/abcd1234
|
||||
states:
|
||||
- start
|
||||
- finish
|
||||
- fail
|
||||
```
|
||||
|
||||
The `push_url` is provided to your from your Uptime Kuma service and
|
||||
originally includes a query string—the text including and after the question
|
||||
mark (`?`). But please do not include the query string in the `push_url`
|
||||
configuration; borgmatic will add this automatically depending on the state of
|
||||
your backup.
|
||||
|
||||
Using `start`, `finish` and `fail` states means you will get two "up beats" in
|
||||
Uptime Kuma for successful backups and the ability to see failures if and when
|
||||
the backup started (was there a `start` beat?).
|
||||
|
||||
A reasonable base-level configuration for an Uptime Kuma Monitor for a backup
|
||||
is below:
|
||||
|
||||
```ini
|
||||
# These are to be entered into Uptime Kuma and not into your borgmatic
|
||||
# configuration.
|
||||
|
||||
# Push monitors wait for the client to contact Uptime Kuma instead of Uptime
|
||||
# Kuma contacting the client. This is perfect for backup monitoring.
|
||||
Monitor Type = Push
|
||||
|
||||
Heartbeat Interval = 90000 # = 25 hours = 1 day + 1 hour
|
||||
|
||||
# Wait 6 times the Heartbeat Retry (below) before logging a heartbeat missed.
|
||||
Retries = 6
|
||||
|
||||
# Multiplied by Retries this gives a grace period within which the monitor
|
||||
# goes into the "Pending" state.
|
||||
Heartbeat Retry = 360 # = 10 minutes
|
||||
|
||||
# For each Heartbeat Interval if the backup fails repeatedly, a notification
|
||||
# is sent each time.
|
||||
Resend Notification every X times = 1
|
||||
```
|
||||
|
||||
|
||||
## Scripting borgmatic
|
||||
|
||||
|
||||
@@ -133,6 +133,8 @@ borgmatic's `borg` action is not without limitations:
|
||||
borgmatic action. In this case, only the Borg command is run.
|
||||
* Unlike normal borgmatic actions that support JSON, the `borg` action will
|
||||
not disable certain borgmatic logs to avoid interfering with JSON output.
|
||||
* The `borg` action bypasses most of borgmatic's machinery, so for instance
|
||||
monitoring hooks will not get triggered when running `borgmatic borg create`.
|
||||
* <span class="minilink minilink-addedin">Prior to version 1.8.0</span>
|
||||
borgmatic implicitly injected the repository/archive arguments on the Borg
|
||||
command-line for you (based on your borgmatic configuration or the
|
||||
|
||||
@@ -151,7 +151,7 @@ borgmatic rcreate --verbosity 1 --encryption repokey-aes-ocb \
|
||||
```
|
||||
|
||||
Read about [Borg encryption
|
||||
modes](https://borgbackup.readthedocs.io/en/2.0.0b5/usage/rcreate.html#encryption-mode-tldr)
|
||||
modes](https://borgbackup.readthedocs.io/en/2.0.0b8/usage/rcreate.html#encryption-mode-tldr)
|
||||
for more details.
|
||||
|
||||
To transfer data from your original Borg 1 repository to your newly created
|
||||
@@ -174,7 +174,7 @@ confirmation of success—or tells you if something hasn't been transferred yet.
|
||||
Note that by omitting the `--upgrader` flag, you can also do archive transfers
|
||||
between related Borg 2 repositories without upgrading, even down to individual
|
||||
archives. For more on that functionality, see the [Borg transfer
|
||||
documentation](https://borgbackup.readthedocs.io/en/2.0.0b5/usage/transfer.html).
|
||||
documentation](https://borgbackup.readthedocs.io/en/2.0.0b8/usage/transfer.html).
|
||||
|
||||
That's it! Now you can use your new Borg 2 repository as normal with
|
||||
borgmatic. If you've got multiple repositories, repeat the above process for
|
||||
|
||||
@@ -10,20 +10,17 @@ eleventyNavigation:
|
||||
If case you're interested in [developing on
|
||||
borgmatic](https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/),
|
||||
here's an abridged primer on how its Python source code is organized to help
|
||||
you get started. At the top level we have:
|
||||
you get started. Starting at the top level, we have:
|
||||
|
||||
* [borgmatic](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic): The main borgmatic source module. Most of the code is here.
|
||||
* [borgmatic](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic): The main borgmatic source module. Most of the code is here. Within that:
|
||||
* [actions](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/actions): borgmatic-specific logic for running each action (create, list, check, etc.).
|
||||
* [borg](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/borg): Lower-level code that's responsible for interacting with Borg to run each action.
|
||||
* [commands](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/commands): Looking to add a new flag or action? Start here. This contains borgmatic's entry point, argument parsing, and shell completion.
|
||||
* [config](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/config): Code responsible for loading, normalizing, and validating borgmatic's configuration.
|
||||
* [hooks](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/hooks): Looking to add a new database or monitoring integration? Start here.
|
||||
* [docs](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/docs): How-to and reference documentation, including the document you're reading now.
|
||||
* [sample](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/sample): Example configurations for cron and systemd.
|
||||
* [scripts](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/scripts): Dev-facing scripts for things like building documentation and running end-to-end tests.
|
||||
* [tests](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/tests): Automated tests organized by: end-to-end, integration, and unit.
|
||||
|
||||
Within the `borgmatic` directory you'll find:
|
||||
|
||||
* [actions](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/actions): Mid-level code for running each borgmatic action (create, list, check, etc.).
|
||||
* [borg](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/borg): Lower-level code that actually shells out to Borg for each action.
|
||||
* [commands](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/commands): Looking to add a new flag or action? Start here. This contains borgmatic's entry point, argument parsing, and shell completion.
|
||||
* [config](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/config): Code responsible for loading, normalizing, and validating borgmatic's configuration.
|
||||
* [hooks](https://projects.torsion.org/borgmatic-collective/borgmatic/src/branch/main/borgmatic/hooks): Looking to add a new database or monitoring integration? Start here.
|
||||
|
||||
So, broadly speaking, the control flow goes: `commands` → `config` followed by `commands` → `actions` → `borg` and `hooks`.
|
||||
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -21,7 +21,7 @@ apk add --no-cache python3 py3-pip borgbackup postgresql-client mariadb-client m
|
||||
py3-ruamel.yaml py3-ruamel.yaml.clib py3-yaml bash sqlite fish
|
||||
# If certain dependencies of black are available in this version of Alpine, install them.
|
||||
apk add --no-cache py3-typed-ast py3-regex || true
|
||||
python3 -m pip install --no-cache --upgrade pip==22.2.2 setuptools==64.0.1
|
||||
python3 -m pip install --no-cache --upgrade pip==24.2 setuptools==72.1.0
|
||||
pip3 install --ignore-installed tox==4.11.3
|
||||
export COVERAGE_FILE=/tmp/.coverage
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
VERSION = '1.8.10'
|
||||
VERSION = '1.8.14'
|
||||
|
||||
|
||||
setup(
|
||||
|
||||
+23
-23
@@ -1,34 +1,34 @@
|
||||
appdirs==1.4.4
|
||||
apprise==1.3.0
|
||||
attrs==22.2.0
|
||||
black==24.3.0
|
||||
certifi==2023.7.22
|
||||
chardet==5.1.0
|
||||
click==8.1.3
|
||||
codespell==2.2.4
|
||||
apprise==1.8.0
|
||||
attrs==23.2.0
|
||||
black==24.4.2
|
||||
certifi==2024.7.4
|
||||
chardet==5.2.0
|
||||
click==8.1.7
|
||||
codespell==2.2.6
|
||||
colorama==0.4.6
|
||||
coverage==7.2.3
|
||||
flake8==6.0.0
|
||||
flake8-quotes==3.3.2
|
||||
coverage==7.5.1
|
||||
flake8==7.0.0
|
||||
flake8-quotes==3.4.0
|
||||
flake8-use-fstring==1.4
|
||||
flake8-variables-names==0.0.5
|
||||
flexmock==0.11.3
|
||||
flake8-variables-names==0.0.6
|
||||
flexmock==0.12.1
|
||||
idna==3.7
|
||||
isort==5.12.0
|
||||
jsonschema==4.17.3
|
||||
Markdown==3.4.1
|
||||
isort==5.13.2
|
||||
jsonschema==4.22.0
|
||||
Markdown==3.6
|
||||
mccabe==0.7.0
|
||||
packaging==23.1
|
||||
pathspec==0.11.1
|
||||
pluggy==1.0.0
|
||||
packaging==24.0
|
||||
pathspec==0.12.1
|
||||
pluggy==1.5.0
|
||||
py==1.11.0
|
||||
pycodestyle==2.10.0
|
||||
pyflakes==3.0.1
|
||||
pytest==7.3.0
|
||||
pytest-cov==4.0.0
|
||||
pycodestyle==2.11.1
|
||||
pyflakes==3.2.0
|
||||
pytest==8.2.1
|
||||
pytest-cov==5.0.0
|
||||
PyYAML>5.0.0
|
||||
regex
|
||||
requests==2.31.0
|
||||
requests==2.32.2
|
||||
ruamel.yaml>0.15.0
|
||||
toml==0.10.2
|
||||
typed-ast
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
version: '3'
|
||||
services:
|
||||
postgresql:
|
||||
image: docker.io/postgres:13.1-alpine
|
||||
|
||||
@@ -9,7 +9,7 @@ def test_validate_config_command_with_valid_configuration_succeeds():
|
||||
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||
|
||||
subprocess.check_call(f'borgmatic config generate --destination {config_path}'.split(' '))
|
||||
exit_code = subprocess.call(f'validate-borgmatic-config --config {config_path}'.split(' '))
|
||||
exit_code = subprocess.call(f'borgmatic config validate --config {config_path}'.split(' '))
|
||||
|
||||
assert exit_code == 0
|
||||
|
||||
@@ -24,7 +24,7 @@ def test_validate_config_command_with_invalid_configuration_fails():
|
||||
config_file.write(config)
|
||||
config_file.close()
|
||||
|
||||
exit_code = subprocess.call(f'validate-borgmatic-config --config {config_path}'.split(' '))
|
||||
exit_code = subprocess.call(f'borgmatic config validate --config {config_path}'.split(' '))
|
||||
|
||||
assert exit_code == 1
|
||||
|
||||
@@ -35,7 +35,7 @@ def test_validate_config_command_with_show_flag_displays_configuration():
|
||||
|
||||
subprocess.check_call(f'borgmatic config generate --destination {config_path}'.split(' '))
|
||||
output = subprocess.check_output(
|
||||
f'validate-borgmatic-config --config {config_path} --show'.split(' ')
|
||||
f'borgmatic config validate --config {config_path} --show'.split(' ')
|
||||
).decode(sys.stdout.encoding)
|
||||
|
||||
assert 'repositories:' in output
|
||||
|
||||
@@ -113,6 +113,74 @@ def test_filter_checks_on_frequency_retains_check_without_frequency():
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_retains_check_with_empty_only_run_on():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'only_run_on': []}]},
|
||||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
datetime_now=flexmock(weekday=lambda: 0),
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_retains_check_with_only_run_on_matching_today():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'only_run_on': [module.calendar.day_name[0]]}]},
|
||||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
datetime_now=flexmock(weekday=lambda: 0),
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_retains_check_with_only_run_on_matching_today_via_weekday_value():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'only_run_on': ['weekday']}]},
|
||||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
datetime_now=flexmock(weekday=lambda: 0),
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_retains_check_with_only_run_on_matching_today_via_weekend_value():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'only_run_on': ['weekend']}]},
|
||||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
datetime_now=flexmock(weekday=lambda: 6),
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_skips_check_with_only_run_on_not_matching_today():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(None)
|
||||
|
||||
assert (
|
||||
module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'only_run_on': [module.calendar.day_name[5]]}]},
|
||||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
datetime_now=flexmock(weekday=lambda: 0),
|
||||
)
|
||||
== ()
|
||||
)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_retains_check_with_elapsed_frequency():
|
||||
flexmock(module).should_receive('parse_frequency').and_return(
|
||||
module.datetime.timedelta(hours=1)
|
||||
@@ -168,7 +236,7 @@ def test_filter_checks_on_frequency_skips_check_with_unelapsed_frequency():
|
||||
)
|
||||
|
||||
|
||||
def test_filter_checks_on_frequency_restains_check_with_unelapsed_frequency_and_force():
|
||||
def test_filter_checks_on_frequency_retains_check_with_unelapsed_frequency_and_force():
|
||||
assert module.filter_checks_on_frequency(
|
||||
config={'checks': [{'name': 'archives', 'frequency': '1 hour'}]},
|
||||
borg_repository_id='repo',
|
||||
@@ -520,7 +588,7 @@ def test_collect_spot_check_source_paths_without_working_directory_parses_borg_o
|
||||
) == ('/etc/path', '/etc/other')
|
||||
|
||||
|
||||
def test_collect_spot_check_source_paths_includes_symlinks_but_skips_directories():
|
||||
def test_collect_spot_check_source_paths_skips_directories():
|
||||
flexmock(module.borgmatic.hooks.dispatch).should_receive('call_hooks').and_return(
|
||||
{'hook1': False, 'hook2': True}
|
||||
)
|
||||
@@ -546,18 +614,19 @@ def test_collect_spot_check_source_paths_includes_symlinks_but_skips_directories
|
||||
'warning: stuff\n- /etc/path\n+ /etc/dir\n? /nope',
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args('/etc/path').and_return(False)
|
||||
flexmock(module.os.path).should_receive('islink').with_args('/etc/path').and_return(True)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args('/etc/dir').and_return(False)
|
||||
flexmock(module.os.path).should_receive('islink').with_args('/etc/dir').and_return(False)
|
||||
|
||||
assert module.collect_spot_check_source_paths(
|
||||
repository={'path': 'repo'},
|
||||
config={'working_directory': '/'},
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
) == ('/etc/path',)
|
||||
assert (
|
||||
module.collect_spot_check_source_paths(
|
||||
repository={'path': 'repo'},
|
||||
config={'working_directory': '/'},
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
== ()
|
||||
)
|
||||
|
||||
|
||||
def test_collect_spot_check_archive_paths_excludes_directories():
|
||||
@@ -769,6 +838,76 @@ def test_compare_spot_check_hashes_considers_non_existent_path_as_not_matching()
|
||||
) == ('/bar',)
|
||||
|
||||
|
||||
def test_compare_spot_check_hashes_with_too_many_paths_feeds_them_to_commands_in_chunks():
|
||||
flexmock(module).SAMPLE_PATHS_SUBSET_COUNT = 2
|
||||
flexmock(module.random).should_receive('sample').replace_with(
|
||||
lambda population, count: population[:count]
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
flexmock(module.borgmatic.execute).should_receive(
|
||||
'execute_command_and_capture_output'
|
||||
).with_args(('xxh64sum', '/foo', '/bar')).and_return('hash1 /foo\nhash2 /bar')
|
||||
flexmock(module.borgmatic.execute).should_receive(
|
||||
'execute_command_and_capture_output'
|
||||
).with_args(('xxh64sum', '/baz', '/quux')).and_return('hash3 /baz\nhash4 /quux')
|
||||
flexmock(module.borgmatic.borg.list).should_receive('capture_archive_listing').and_return(
|
||||
['hash1 /foo', 'hash2 /bar']
|
||||
).and_return(['hash3 /baz', 'nothash4 /quux'])
|
||||
|
||||
assert module.compare_spot_check_hashes(
|
||||
repository={'path': 'repo'},
|
||||
archive='archive',
|
||||
config={
|
||||
'checks': [
|
||||
{
|
||||
'name': 'archives',
|
||||
'frequency': '2 weeks',
|
||||
},
|
||||
{
|
||||
'name': 'spot',
|
||||
'data_sample_percentage': 100,
|
||||
},
|
||||
]
|
||||
},
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
log_label='repo',
|
||||
source_paths=('/foo', '/bar', '/baz', '/quux'),
|
||||
) == ('/quux',)
|
||||
|
||||
|
||||
def test_spot_check_without_spot_configuration_errors():
|
||||
with pytest.raises(ValueError):
|
||||
module.spot_check(
|
||||
repository={'path': 'repo'},
|
||||
config={
|
||||
'checks': [
|
||||
{
|
||||
'name': 'archives',
|
||||
},
|
||||
]
|
||||
},
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_spot_check_without_any_configuration_errors():
|
||||
with pytest.raises(ValueError):
|
||||
module.spot_check(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_spot_check_data_tolerance_percenatge_greater_than_data_sample_percentage_errors():
|
||||
with pytest.raises(ValueError):
|
||||
module.spot_check(
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.actions import delete as module
|
||||
|
||||
|
||||
def test_run_delete_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name')
|
||||
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.borg.delete).should_receive('delete_archives')
|
||||
|
||||
module.run_delete(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
delete_arguments=flexmock(repository=flexmock(), archive=flexmock()),
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
|
||||
def test_run_delete_without_archive_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.borg.rlist).should_receive('resolve_archive_name')
|
||||
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.borg.delete).should_receive('delete_archives')
|
||||
|
||||
module.run_delete(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
delete_arguments=flexmock(repository=flexmock(), archive=None),
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.actions import rdelete as module
|
||||
|
||||
|
||||
def test_run_rdelete_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository')
|
||||
|
||||
module.run_rdelete(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
rdelete_arguments=flexmock(repository=flexmock(), cache_only=False),
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
|
||||
def test_run_rdelete_with_cache_only_does_not_raise():
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
flexmock(module.borgmatic.config.validate).should_receive('repositories_match').and_return(True)
|
||||
flexmock(module.borgmatic.actions.arguments).should_receive('update_arguments').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository')
|
||||
|
||||
module.run_rdelete(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=None,
|
||||
rdelete_arguments=flexmock(repository=flexmock(), cache_only=True),
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
+245
-44
@@ -222,35 +222,35 @@ def test_make_archive_filter_flags_with_default_checks_and_prefix_includes_match
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_returns_flag():
|
||||
flags = module.make_check_flags(('repository',), ())
|
||||
def test_make_check_name_flags_with_repository_check_returns_flag():
|
||||
flags = module.make_check_name_flags({'repository'}, ())
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_returns_flag():
|
||||
flags = module.make_check_flags(('archives',), ())
|
||||
def test_make_check_name_flags_with_archives_check_returns_flag():
|
||||
flags = module.make_check_name_flags({'archives'}, ())
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_archive_filter_flags_includes_those_flags():
|
||||
flags = module.make_check_flags(('archives',), ('--match-archives', 'sh:foo-*'))
|
||||
def test_make_check_name_flags_with_archives_check_and_archive_filter_flags_includes_those_flags():
|
||||
flags = module.make_check_name_flags({'archives'}, ('--match-archives', 'sh:foo-*'))
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_check_flags_without_archives_check_and_with_archive_filter_flags_includes_those_flags():
|
||||
flags = module.make_check_flags(('repository',), ('--match-archives', 'sh:foo-*'))
|
||||
def test_make_check_name_flags_without_archives_check_and_with_archive_filter_flags_includes_those_flags():
|
||||
flags = module.make_check_name_flags({'repository'}, ('--match-archives', 'sh:foo-*'))
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_returns_flag_and_implies_archives():
|
||||
def test_make_check_name_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(('data',), ())
|
||||
flags = module.make_check_name_flags({'data'}, ())
|
||||
|
||||
assert flags == (
|
||||
'--archives-only',
|
||||
@@ -258,24 +258,24 @@ def test_make_check_flags_with_data_check_returns_flag_and_implies_archives():
|
||||
)
|
||||
|
||||
|
||||
def test_make_check_flags_with_extract_omits_extract_flag():
|
||||
def test_make_check_name_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(('extract',), ())
|
||||
flags = module.make_check_name_flags({'extract'}, ())
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_and_data_checks_does_not_return_repository_only():
|
||||
def test_make_check_name_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(
|
||||
(
|
||||
flags = module.make_check_name_flags(
|
||||
{
|
||||
'repository',
|
||||
'data',
|
||||
),
|
||||
},
|
||||
(),
|
||||
)
|
||||
|
||||
@@ -332,8 +332,7 @@ def test_get_repository_id_with_missing_json_keys_raises():
|
||||
|
||||
def test_check_archives_with_progress_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
@@ -349,7 +348,12 @@ def test_check_archives_with_progress_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=True, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=True,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
@@ -359,8 +363,7 @@ def test_check_archives_with_progress_passes_through_to_borg():
|
||||
|
||||
def test_check_archives_with_repair_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
@@ -376,7 +379,148 @@ def test_check_archives_with_repair_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=True, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=True,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_flag_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '33', 'repo'),
|
||||
extra_environment=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=33,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_flag_and_archives_check_errors():
|
||||
config = {}
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=33,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository', 'archives'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_option_passes_through_to_borg():
|
||||
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '33', 'repo'),
|
||||
extra_environment=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_option_and_archives_check_errors():
|
||||
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository', 'archives'},
|
||||
archive_filter_flags=(),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_max_duration_flag_overrides_max_duration_option():
|
||||
config = {'checks': [{'name': 'repository', 'max_duration': 33}]}
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'check', '--max-duration', '44', 'repo'),
|
||||
extra_environment=None,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=44,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
@@ -395,7 +539,7 @@ def test_check_archives_with_repair_passes_through_to_borg():
|
||||
)
|
||||
def test_check_archives_calls_borg_with_parameters(checks):
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
|
||||
@@ -404,7 +548,12 @@ def test_check_archives_calls_borg_with_parameters(checks):
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -414,7 +563,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
|
||||
|
||||
def test_check_archives_with_log_info_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
insert_execute_command_mock(('borg', 'check', '--info', 'repo'))
|
||||
@@ -424,7 +573,12 @@ def test_check_archives_with_log_info_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
@@ -434,7 +588,7 @@ def test_check_archives_with_log_info_passes_through_to_borg():
|
||||
|
||||
def test_check_archives_with_log_debug_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
insert_execute_command_mock(('borg', 'check', '--debug', '--show-rc', 'repo'))
|
||||
@@ -444,7 +598,12 @@ def test_check_archives_with_log_debug_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
@@ -455,7 +614,7 @@ def test_check_archives_with_log_debug_passes_through_to_borg():
|
||||
def test_check_archives_with_local_path_calls_borg_via_local_path():
|
||||
checks = {'repository'}
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
||||
|
||||
@@ -464,7 +623,12 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -477,7 +641,7 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
|
||||
checks = {'repository'}
|
||||
borg_exit_codes = flexmock()
|
||||
config = {'borg_exit_codes': borg_exit_codes}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'), borg_exit_codes=borg_exit_codes)
|
||||
|
||||
@@ -486,7 +650,12 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -497,7 +666,7 @@ def test_check_archives_with_exit_codes_calls_borg_using_them():
|
||||
def test_check_archives_with_remote_path_passes_through_to_borg():
|
||||
checks = {'repository'}
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--remote-path', 'borg1', 'repo'))
|
||||
|
||||
@@ -506,7 +675,12 @@ def test_check_archives_with_remote_path_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -518,7 +692,7 @@ def test_check_archives_with_remote_path_passes_through_to_borg():
|
||||
def test_check_archives_with_log_json_passes_through_to_borg():
|
||||
checks = {'repository'}
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--log-json', 'repo'))
|
||||
|
||||
@@ -527,7 +701,12 @@ def test_check_archives_with_log_json_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
checks=checks,
|
||||
@@ -538,7 +717,7 @@ def test_check_archives_with_log_json_passes_through_to_borg():
|
||||
def test_check_archives_with_lock_wait_passes_through_to_borg():
|
||||
checks = {'repository'}
|
||||
config = {'lock_wait': 5}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--lock-wait', '5', 'repo'))
|
||||
|
||||
@@ -547,7 +726,12 @@ def test_check_archives_with_lock_wait_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -559,7 +743,7 @@ def test_check_archives_with_retention_prefix():
|
||||
checks = {'repository'}
|
||||
prefix = 'foo-'
|
||||
config = {'prefix': prefix}
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
|
||||
@@ -568,7 +752,12 @@ def test_check_archives_with_retention_prefix():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks=checks,
|
||||
@@ -578,7 +767,7 @@ def test_check_archives_with_retention_prefix():
|
||||
|
||||
def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
||||
config = {'extra_borg_options': {'check': '--extra --options'}}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--extra', '--options', 'repo'))
|
||||
|
||||
@@ -587,7 +776,12 @@ def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives=None
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives=None,
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'repository'},
|
||||
@@ -597,7 +791,9 @@ def test_check_archives_with_extra_borg_options_passes_through_to_borg():
|
||||
|
||||
def test_check_archives_with_match_archives_passes_through_to_borg():
|
||||
config = {}
|
||||
flexmock(module).should_receive('make_check_flags').and_return(('--match-archives', 'foo-*'))
|
||||
flexmock(module).should_receive('make_check_name_flags').and_return(
|
||||
('--match-archives', 'foo-*')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
@@ -612,7 +808,12 @@ def test_check_archives_with_match_archives_passes_through_to_borg():
|
||||
config=config,
|
||||
local_borg_version='1.2.3',
|
||||
check_arguments=flexmock(
|
||||
progress=None, repair=None, only_checks=None, force=None, match_archives='foo-*'
|
||||
progress=None,
|
||||
repair=None,
|
||||
only_checks=None,
|
||||
force=None,
|
||||
match_archives='foo-*',
|
||||
max_duration=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
checks={'archives'},
|
||||
|
||||
@@ -693,6 +693,7 @@ def test_make_base_create_command_includes_exclude_patterns_in_borg_command():
|
||||
('one_file_system', True, True, ('--one-file-system',)),
|
||||
('upload_rate_limit', 100, True, ('--upload-ratelimit', '100')),
|
||||
('upload_rate_limit', 100, False, ('--remote-ratelimit', '100')),
|
||||
('upload_buffer_size', 160, True, ('--upload-buffer', '160')),
|
||||
('numeric_ids', True, True, ('--numeric-ids',)),
|
||||
('numeric_ids', True, False, ('--numeric-owner',)),
|
||||
('read_special', True, True, ('--read-special',)),
|
||||
@@ -1890,3 +1891,18 @@ def test_check_all_source_directories_exist_with_non_existent_directory_raises()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_all_source_directories_exist(['foo'])
|
||||
|
||||
|
||||
def test_check_all_source_directories_exist_with_working_directory_applies_to_relative_source_directories():
|
||||
flexmock(module).should_receive('expand_directory').with_args('/tmp/foo*').and_return(
|
||||
('/tmp/foo', '/tmp/food')
|
||||
)
|
||||
flexmock(module).should_receive('expand_directory').with_args('/root/bar').and_return(
|
||||
('/root/bar',)
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/tmp/foo').and_return(True)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/tmp/food').and_return(True)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('/root/bar').and_return(True)
|
||||
|
||||
module.check_all_source_directories_exist(['foo*', '/root/bar'], working_directory='/tmp')
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import delete as module
|
||||
|
||||
from ..test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def test_make_delete_command_includes_log_info():
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--info', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_log_debug():
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--debug', '--show-rc', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_dry_run():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'dry-run', True
|
||||
).and_return(('--dry-run',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=True, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--dry-run', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_remote_path():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'remote-path', 'borg1'
|
||||
).and_return(('--remote-path', 'borg1'))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--remote-path', 'borg1', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_log_json():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'log-json', True
|
||||
).and_return(('--log-json',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=True),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_lock_wait():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'lock-wait', 5
|
||||
).and_return(('--lock-wait', '5'))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={'lock_wait': 5},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--lock-wait', '5', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_list():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'list', True
|
||||
).and_return(('--list',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=True, force=0, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--list', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_force():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=1, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_force_twice():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(list_archives=False, force=2, match_archives=None, archive=None),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--force', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_archive():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(
|
||||
('--match-archives', 'archive')
|
||||
)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(
|
||||
list_archives=False, force=0, match_archives=None, archive='archive'
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--match-archives', 'archive', 'repo')
|
||||
|
||||
|
||||
def test_make_delete_command_includes_match_archives():
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_match_archives_flags').and_return(
|
||||
('--match-archives', 'sh:foo*')
|
||||
)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_delete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
delete_arguments=flexmock(
|
||||
list_archives=False, force=0, match_archives='sh:foo*', archive='archive'
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
||||
|
||||
def test_delete_archives_with_archive_calls_borg_delete():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository').never()
|
||||
flexmock(module).should_receive('make_delete_command').and_return(flexmock())
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').once()
|
||||
|
||||
module.delete_archives(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
delete_arguments=flexmock(archive='archive'),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_delete_archives_with_match_archives_calls_borg_delete():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository').never()
|
||||
flexmock(module).should_receive('make_delete_command').and_return(flexmock())
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').once()
|
||||
|
||||
module.delete_archives(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
delete_arguments=flexmock(match_archives='sh:foo*'),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('argument_name', module.ARCHIVE_RELATED_ARGUMENT_NAMES[2:])
|
||||
def test_delete_archives_with_archive_related_argument_calls_borg_delete(argument_name):
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository').never()
|
||||
flexmock(module).should_receive('make_delete_command').and_return(flexmock())
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').once()
|
||||
|
||||
module.delete_archives(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
delete_arguments=flexmock(archive='archive', **{argument_name: 'value'}),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
|
||||
|
||||
def test_delete_archives_without_archive_related_argument_calls_borg_rdelete():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.rdelete).should_receive('delete_repository').once()
|
||||
flexmock(module).should_receive('make_delete_command').never()
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').never()
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').never()
|
||||
|
||||
module.delete_archives(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
delete_arguments=flexmock(
|
||||
list_archives=True, force=False, cache_only=False, keep_security_info=False
|
||||
),
|
||||
global_arguments=flexmock(),
|
||||
)
|
||||
@@ -507,6 +507,39 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_strip_components_calculated_from_all_with_leading_slash():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(
|
||||
(
|
||||
'borg',
|
||||
'extract',
|
||||
'--strip-components',
|
||||
'2',
|
||||
'repo::archive',
|
||||
'/foo/bar/baz.txt',
|
||||
'/foo/bar.txt',
|
||||
)
|
||||
)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',)
|
||||
)
|
||||
flexmock(module.borgmatic.config.validate).should_receive(
|
||||
'normalize_repository_path'
|
||||
).and_return('repo')
|
||||
|
||||
module.extract_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
paths=['/foo/bar/baz.txt', '/foo/bar.txt'],
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
strip_components='all',
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_with_strip_components_all_and_no_paths_raises():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
|
||||
@@ -190,6 +190,20 @@ def test_make_match_archives_flags_makes_flags_with_globs(
|
||||
)
|
||||
|
||||
|
||||
def test_make_match_archives_flags_accepts_default_archive_name_format():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
|
||||
assert (
|
||||
module.make_match_archives_flags(
|
||||
match_archives=None,
|
||||
archive_name_format=None,
|
||||
local_borg_version=flexmock(),
|
||||
default_archive_name_format='*',
|
||||
)
|
||||
== ()
|
||||
)
|
||||
|
||||
|
||||
def test_warn_for_aggressive_archive_flags_without_archive_flags_bails():
|
||||
flexmock(module.logger).should_receive('warning').never()
|
||||
|
||||
|
||||
@@ -0,0 +1,336 @@
|
||||
import logging
|
||||
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.borg import rdelete as module
|
||||
|
||||
from ..test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def test_make_rdelete_command_with_feature_available_runs_borg_rdelete():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_without_feature_available_runs_borg_delete():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'delete', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_log_info():
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--info', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_log_debug():
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--debug', '--show-rc', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_dry_run():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'dry-run', True
|
||||
).and_return(('--dry-run',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=True, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--dry-run', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_remote_path():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'remote-path', 'borg1'
|
||||
).and_return(('--remote-path', 'borg1'))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--remote-path', 'borg1', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_log_json():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'log-json', True
|
||||
).and_return(('--log-json',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=True),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_lock_wait():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'lock-wait', 5
|
||||
).and_return(('--lock-wait', '5'))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={'lock_wait': 5},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--lock-wait', '5', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_list():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').with_args(
|
||||
'list', True
|
||||
).and_return(('--list',))
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=True, force=0),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--list', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_force():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=1),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--force', 'repo')
|
||||
|
||||
|
||||
def test_make_rdelete_command_includes_force_twice():
|
||||
flexmock(module.borgmatic.borg.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.borgmatic.borg.flags).should_receive('make_repository_flags').and_return(
|
||||
('repo',)
|
||||
)
|
||||
|
||||
command = module.make_rdelete_command(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version='1.2.3',
|
||||
rdelete_arguments=flexmock(list_archives=False, force=2),
|
||||
global_arguments=flexmock(dry_run=False, log_json=False),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
assert command == ('borg', 'rdelete', '--force', '--force', 'repo')
|
||||
|
||||
|
||||
def test_delete_repository_with_defaults_does_not_capture_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_rdelete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
||||
command,
|
||||
output_log_level=module.logging.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
extra_environment=object,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.delete_repository(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
rdelete_arguments=flexmock(force=False, cache_only=False),
|
||||
global_arguments=flexmock(),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
|
||||
def test_delete_repository_with_force_captures_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_rdelete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
||||
command,
|
||||
output_log_level=module.logging.ANSWER,
|
||||
output_file=None,
|
||||
extra_environment=object,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.delete_repository(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
rdelete_arguments=flexmock(force=True, cache_only=False),
|
||||
global_arguments=flexmock(),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
|
||||
|
||||
def test_delete_repository_with_cache_only_captures_output():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
command = flexmock()
|
||||
flexmock(module).should_receive('make_rdelete_command').and_return(command)
|
||||
flexmock(module.borgmatic.borg.environment).should_receive('make_environment').and_return(
|
||||
flexmock()
|
||||
)
|
||||
flexmock(module.borgmatic.execute).should_receive('execute_command').with_args(
|
||||
command,
|
||||
output_log_level=module.logging.ANSWER,
|
||||
output_file=None,
|
||||
extra_environment=object,
|
||||
borg_local_path='borg',
|
||||
borg_exit_codes=None,
|
||||
).once()
|
||||
|
||||
module.delete_repository(
|
||||
repository={'path': 'repo'},
|
||||
config={},
|
||||
local_borg_version=flexmock(),
|
||||
rdelete_arguments=flexmock(force=False, cache_only=True),
|
||||
global_arguments=flexmock(),
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
)
|
||||
@@ -130,36 +130,175 @@ def test_parse_and_record_action_arguments_with_borg_action_consumes_arguments_a
|
||||
assert borg_parsed_arguments.options == ('list',)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'argument, expected',
|
||||
[
|
||||
('--foo', True),
|
||||
('foo', False),
|
||||
(33, False),
|
||||
],
|
||||
)
|
||||
def test_argument_is_flag_only_for_string_starting_with_double_dash(argument, expected):
|
||||
assert module.argument_is_flag(argument) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'arguments, expected',
|
||||
[
|
||||
# A global flag remaining from each parsed action.
|
||||
# Ending with a valueless flag.
|
||||
(
|
||||
('--foo', '--bar', 33, '--baz'),
|
||||
(
|
||||
('--latest', 'archive', 'prune', 'extract', 'list', '--test-flag'),
|
||||
('--latest', 'archive', 'check', 'extract', 'list', '--test-flag'),
|
||||
('prune', 'check', 'list', '--test-flag'),
|
||||
('prune', 'check', 'extract', '--test-flag'),
|
||||
('--foo',),
|
||||
('--bar', 33),
|
||||
('--baz',),
|
||||
),
|
||||
('--test-flag',),
|
||||
),
|
||||
# No global flags remaining.
|
||||
# Ending with a flag and its corresponding value.
|
||||
(
|
||||
('--foo', '--bar', 33, '--baz', '--quux', 'thing'),
|
||||
(('--foo',), ('--bar', 33), ('--baz',), ('--quux', 'thing')),
|
||||
),
|
||||
# Starting with an action name.
|
||||
(
|
||||
('check', '--foo', '--bar', 33, '--baz'),
|
||||
(
|
||||
('check',),
|
||||
('--foo',),
|
||||
('--bar', 33),
|
||||
('--baz',),
|
||||
),
|
||||
),
|
||||
# Action name that one could mistake for a flag value.
|
||||
(('--progress', 'list'), (('--progress',), ('list',))),
|
||||
# No arguments.
|
||||
((), ()),
|
||||
],
|
||||
)
|
||||
def test_group_arguments_with_values_returns_flags_with_corresponding_values(arguments, expected):
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('--foo').and_return(True)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('--bar').and_return(True)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('--baz').and_return(True)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('--quux').and_return(True)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('--progress').and_return(True)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args(33).and_return(False)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('thing').and_return(False)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('check').and_return(False)
|
||||
flexmock(module).should_receive('argument_is_flag').with_args('list').and_return(False)
|
||||
|
||||
assert module.group_arguments_with_values(arguments) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'arguments, grouped_arguments, expected',
|
||||
[
|
||||
# An unparsable flag remaining from each parsed action.
|
||||
(
|
||||
(
|
||||
('--latest', 'archive', 'prune', 'extract', 'list'),
|
||||
('--latest', 'archive', 'check', 'extract', 'list'),
|
||||
('--latest', 'archive', 'prune', 'extract', 'list', '--flag'),
|
||||
('--latest', 'archive', 'check', 'extract', 'list', '--flag'),
|
||||
('prune', 'check', 'list', '--flag'),
|
||||
('prune', 'check', 'extract', '--flag'),
|
||||
),
|
||||
(
|
||||
(
|
||||
('--latest',),
|
||||
('archive',),
|
||||
('prune',),
|
||||
('extract',),
|
||||
('list',),
|
||||
('--flag',),
|
||||
),
|
||||
(
|
||||
('--latest',),
|
||||
('archive',),
|
||||
('check',),
|
||||
('extract',),
|
||||
('list',),
|
||||
('--flag',),
|
||||
),
|
||||
(('prune',), ('check',), ('list',), ('--flag',)),
|
||||
(('prune',), ('check',), ('extract',), ('--flag',)),
|
||||
),
|
||||
('--flag',),
|
||||
),
|
||||
# No unparsable flags remaining.
|
||||
(
|
||||
(
|
||||
('--archive', 'archive', 'prune', 'extract', 'list'),
|
||||
('--archive', 'archive', 'check', 'extract', 'list'),
|
||||
('prune', 'check', 'list'),
|
||||
('prune', 'check', 'extract'),
|
||||
),
|
||||
(
|
||||
(
|
||||
(
|
||||
'--archive',
|
||||
'archive',
|
||||
),
|
||||
('prune',),
|
||||
('extract',),
|
||||
('list',),
|
||||
),
|
||||
(
|
||||
(
|
||||
'--archive',
|
||||
'archive',
|
||||
),
|
||||
('check',),
|
||||
('extract',),
|
||||
('list',),
|
||||
),
|
||||
(('prune',), ('check',), ('list',)),
|
||||
(('prune',), ('check',), ('extract',)),
|
||||
),
|
||||
(),
|
||||
),
|
||||
# No unparsable flags remaining, but some values in common.
|
||||
(
|
||||
(
|
||||
('--verbosity', '5', 'archive', 'prune', 'extract', 'list'),
|
||||
('--last', '5', 'archive', 'check', 'extract', 'list'),
|
||||
('prune', 'check', 'list', '--last', '5'),
|
||||
('prune', 'check', '--verbosity', '5', 'extract'),
|
||||
),
|
||||
(
|
||||
(('--verbosity', '5'), ('archive',), ('prune',), ('extract',), ('list',)),
|
||||
(
|
||||
(
|
||||
'--last',
|
||||
'5',
|
||||
),
|
||||
('archive',),
|
||||
('check',),
|
||||
('extract',),
|
||||
('list',),
|
||||
),
|
||||
(('prune',), ('check',), ('list',), ('--last', '5')),
|
||||
(
|
||||
('prune',),
|
||||
('check',),
|
||||
(
|
||||
'--verbosity',
|
||||
'5',
|
||||
),
|
||||
('extract',),
|
||||
),
|
||||
),
|
||||
(),
|
||||
),
|
||||
# No flags.
|
||||
((), ()),
|
||||
((), (), ()),
|
||||
],
|
||||
)
|
||||
def test_get_unparsable_arguments_returns_remaining_arguments_that_no_action_can_parse(
|
||||
arguments, expected
|
||||
arguments, grouped_arguments, expected
|
||||
):
|
||||
for action_arguments, grouped_action_arguments in zip(arguments, grouped_arguments):
|
||||
flexmock(module).should_receive('group_arguments_with_values').with_args(
|
||||
action_arguments
|
||||
).and_return(grouped_action_arguments)
|
||||
|
||||
assert module.get_unparsable_arguments(arguments) == expected
|
||||
|
||||
|
||||
|
||||
@@ -487,6 +487,45 @@ def test_run_actions_runs_rcreate():
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_adds_label_file_to_hook_context():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
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', 'label': 'my repo'},
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
hook_context={
|
||||
'repository_label': 'my repo',
|
||||
'log_file': '',
|
||||
'repositories': '',
|
||||
'repository': 'repo',
|
||||
},
|
||||
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=None), 'create': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo', 'label': 'my repo'},
|
||||
)
|
||||
)
|
||||
assert result == (expected,)
|
||||
|
||||
|
||||
def test_run_actions_adds_log_file_to_hook_context():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
@@ -497,7 +536,12 @@ def test_run_actions_adds_log_file_to_hook_context():
|
||||
repository={'path': 'repo'},
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
hook_context={'repository': 'repo', 'repositories': '', 'log_file': 'foo'},
|
||||
hook_context={
|
||||
'repository_label': '',
|
||||
'log_file': 'foo',
|
||||
'repositories': '',
|
||||
'repository': 'repo',
|
||||
},
|
||||
local_borg_version=object,
|
||||
create_arguments=object,
|
||||
global_arguments=object,
|
||||
@@ -934,6 +978,46 @@ def test_run_actions_runs_export_key():
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_runs_delete():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
flexmock(module.command).should_receive('execute_hook')
|
||||
flexmock(borgmatic.actions.delete).should_receive('run_delete').once()
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'delete': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo'},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_runs_rdelete():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
flexmock(module.command).should_receive('execute_hook')
|
||||
flexmock(borgmatic.actions.rdelete).should_receive('run_rdelete').once()
|
||||
|
||||
tuple(
|
||||
module.run_actions(
|
||||
arguments={'global': flexmock(dry_run=False, log_file='foo'), 'rdelete': flexmock()},
|
||||
config_filename=flexmock(),
|
||||
config={'repositories': []},
|
||||
config_paths=[],
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
repository={'path': 'repo'},
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_run_actions_runs_borg():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module).should_receive('get_skip_actions').and_return([])
|
||||
|
||||
@@ -50,6 +50,16 @@ def test_apply_constants_with_empty_constants_passes_through_value():
|
||||
({'before_backup': '{inject}'}, {'before_backup': "'echo hi; naughty-command'"}),
|
||||
({'after_backup': '{inject}'}, {'after_backup': "'echo hi; naughty-command'"}),
|
||||
({'on_error': '{inject}'}, {'on_error': "'echo hi; naughty-command'"}),
|
||||
(
|
||||
{
|
||||
'before_backup': '{env_pass}',
|
||||
'postgresql_databases': [{'name': 'users', 'password': '{env_pass}'}],
|
||||
},
|
||||
{
|
||||
'before_backup': "'${PASS}'",
|
||||
'postgresql_databases': [{'name': 'users', 'password': '${PASS}'}],
|
||||
},
|
||||
),
|
||||
(3, 3),
|
||||
(True, True),
|
||||
(False, False),
|
||||
@@ -63,6 +73,7 @@ def test_apply_constants_makes_string_substitutions(value, expected_value):
|
||||
'int': 3,
|
||||
'bool': True,
|
||||
'inject': 'echo hi; naughty-command',
|
||||
'env_pass': '${PASS}',
|
||||
}
|
||||
|
||||
assert module.apply_constants(value, constants) == expected_value
|
||||
|
||||
@@ -62,7 +62,7 @@ def test_validation_error_string_contains_errors():
|
||||
|
||||
|
||||
def test_apply_logical_validation_raises_if_unknown_repository_in_check_repositories():
|
||||
flexmock(module).format_json_error = lambda error: error.message
|
||||
flexmock(module).should_receive('repositories_match').and_return(False)
|
||||
|
||||
with pytest.raises(module.Validation_error):
|
||||
module.apply_logical_validation(
|
||||
@@ -75,7 +75,9 @@ def test_apply_logical_validation_raises_if_unknown_repository_in_check_reposito
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_if_known_repository_path_in_check_repositories():
|
||||
def test_apply_logical_validation_does_not_raise_if_known_repository_in_check_repositories():
|
||||
flexmock(module).should_receive('repositories_match').and_return(True)
|
||||
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
@@ -86,35 +88,6 @@ def test_apply_logical_validation_does_not_raise_if_known_repository_path_in_che
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_if_known_repository_label_in_check_repositories():
|
||||
module.apply_logical_validation(
|
||||
'config.yaml',
|
||||
{
|
||||
'repositories': [
|
||||
{'path': 'repo.borg', 'label': 'my_repo'},
|
||||
{'path': 'other.borg', 'label': 'other_repo'},
|
||||
],
|
||||
'keep_secondly': 1000,
|
||||
'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',
|
||||
{
|
||||
'archive_name_format': '{hostname}-{now}', # noqa: FS003
|
||||
'prefix': '{hostname}-', # noqa: FS003
|
||||
'prefix': '{hostname}-', # noqa: FS003
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def test_apply_logical_validation_does_not_raise_otherwise():
|
||||
module.apply_logical_validation('config.yaml', {'keep_secondly': 1000})
|
||||
|
||||
|
||||
def test_normalize_repository_path_passes_through_remote_repository():
|
||||
repository = 'example.org:test.borg'
|
||||
|
||||
@@ -143,39 +116,94 @@ def test_normalize_repository_path_resolves_relative_repository():
|
||||
module.normalize_repository_path(repository) == absolute
|
||||
|
||||
|
||||
def test_repositories_match_does_not_raise():
|
||||
@pytest.mark.parametrize(
|
||||
'first,second,expected_result',
|
||||
(
|
||||
(None, None, False),
|
||||
('foo', None, False),
|
||||
(None, 'bar', False),
|
||||
('foo', 'foo', True),
|
||||
('foo', 'bar', False),
|
||||
('foo*', 'foof', True),
|
||||
('barf', 'bar*', True),
|
||||
('foo*', 'bar*', False),
|
||||
),
|
||||
)
|
||||
def test_glob_match_matches_globs(first, second, expected_result):
|
||||
assert module.glob_match(first=first, second=second) is expected_result
|
||||
|
||||
|
||||
def test_repositories_match_matches_on_path():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
|
||||
module.repositories_match('foo', 'bar')
|
||||
|
||||
|
||||
def test_guard_configuration_contains_repository_does_not_raise_when_repository_in_config():
|
||||
flexmock(module).should_receive('repositories_match').replace_with(
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.guard_configuration_contains_repository(
|
||||
repository='repo', configurations={'config.yaml': {'repositories': ['repo']}}
|
||||
module.repositories_match(
|
||||
{'path': 'foo', 'label': 'my repo'}, {'path': 'foo', 'label': 'other repo'}
|
||||
) is True
|
||||
|
||||
|
||||
def test_repositories_match_matches_on_label():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.repositories_match(
|
||||
{'path': 'foo', 'label': 'my repo'}, {'path': 'bar', 'label': 'my repo'}
|
||||
) is True
|
||||
|
||||
|
||||
def test_repositories_match_with_different_paths_and_labels_does_not_match():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.repositories_match(
|
||||
{'path': 'foo', 'label': 'my repo'}, {'path': 'bar', 'label': 'other repo'}
|
||||
) is False
|
||||
|
||||
|
||||
def test_repositories_match_matches_on_string_repository():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.repositories_match('foo', 'foo') is True
|
||||
|
||||
|
||||
def test_repositories_match_with_different_string_repositories_does_not_match():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.repositories_match('foo', 'bar') is False
|
||||
|
||||
|
||||
def test_repositories_match_supports_mixed_repositories():
|
||||
flexmock(module).should_receive('normalize_repository_path')
|
||||
flexmock(module).should_receive('glob_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
|
||||
module.repositories_match({'path': 'foo', 'label': 'my foo'}, 'bar') is False
|
||||
|
||||
|
||||
def test_guard_configuration_contains_repository_does_not_raise_when_repository_matches():
|
||||
flexmock(module).should_receive('repositories_match').and_return(True)
|
||||
|
||||
def test_guard_configuration_contains_repository_does_not_raise_when_repository_label_in_config():
|
||||
module.guard_configuration_contains_repository(
|
||||
repository='repo',
|
||||
configurations={'config.yaml': {'repositories': [{'path': 'foo/bar', 'label': 'repo'}]}},
|
||||
)
|
||||
|
||||
|
||||
def test_guard_configuration_contains_repository_does_not_raise_when_repository_not_given():
|
||||
module.guard_configuration_contains_repository(
|
||||
repository=None, configurations={'config.yaml': {'repositories': ['repo']}}
|
||||
)
|
||||
|
||||
|
||||
def test_guard_configuration_contains_repository_errors_when_repository_missing_from_config():
|
||||
flexmock(module).should_receive('repositories_match').replace_with(
|
||||
lambda first, second: first == second
|
||||
)
|
||||
def test_guard_configuration_contains_repository_errors_when_repository_does_not_match():
|
||||
flexmock(module).should_receive('repositories_match').and_return(False)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.guard_configuration_contains_repository(
|
||||
|
||||
@@ -264,6 +264,75 @@ def test_ping_monitor_hits_ping_url_when_states_matching():
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_adds_create_query_parameter_when_create_slug_true():
|
||||
flexmock(module.borgmatic.hooks.logs).should_receive('Forgetful_buffering_handler').never()
|
||||
hook_config = {'ping_url': 'https://example.com', 'create_slug': True}
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
'https://example.com/start?create=1', data=''.encode('utf-8'), verify=True
|
||||
).and_return(flexmock(ok=True))
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
state=module.monitor.State.START,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_does_not_add_create_query_parameter_when_create_slug_false():
|
||||
flexmock(module.borgmatic.hooks.logs).should_receive('Forgetful_buffering_handler').never()
|
||||
hook_config = {'ping_url': 'https://example.com', 'create_slug': False}
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
'https://example.com/start', data=''.encode('utf-8'), verify=True
|
||||
).and_return(flexmock(ok=True))
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
state=module.monitor.State.START,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_does_not_add_create_query_parameter_when_ping_url_is_uuid():
|
||||
hook_config = {'ping_url': 'b3611b24-df9c-4d36-9203-fa292820bf2a', 'create_slug': True}
|
||||
flexmock(module.requests).should_receive('post').with_args(
|
||||
f"https://hc-ping.com/{hook_config['ping_url']}",
|
||||
data=''.encode('utf-8'),
|
||||
verify=True,
|
||||
).and_return(flexmock(ok=True))
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
state=module.monitor.State.FINISH,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_issues_warning_when_ping_url_is_uuid_and_create_slug_true():
|
||||
hook_config = {'ping_url': 'b3611b24-df9c-4d36-9203-fa292820bf2a', 'create_slug': True}
|
||||
|
||||
flexmock(module.requests).should_receive('post').and_return(flexmock(ok=True))
|
||||
|
||||
flexmock(module.logger).should_receive('warning').once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
state=module.monitor.State.FINISH,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_with_connection_error_logs_warning():
|
||||
flexmock(module.borgmatic.hooks.logs).should_receive('Forgetful_buffering_handler').never()
|
||||
hook_config = {'ping_url': 'https://example.com'}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
from flexmock import flexmock
|
||||
|
||||
import borgmatic.hooks.monitor
|
||||
from borgmatic.hooks import uptimekuma as module
|
||||
|
||||
DEFAULT_PUSH_URL = 'https://example.uptime.kuma/api/push/abcd1234'
|
||||
CUSTOM_PUSH_URL = 'https://uptime.example.com/api/push/efgh5678'
|
||||
|
||||
|
||||
def test_ping_monitor_hits_default_uptimekuma_on_fail():
|
||||
hook_config = {}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{DEFAULT_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_hits_custom_uptimekuma_on_fail():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_custom_uptimekuma_on_start():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_PUSH_URL}?status=up&msg=start'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.START,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_custom_uptimekuma_on_finish():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_PUSH_URL}?status=up&msg=finish'
|
||||
).and_return(flexmock(ok=True)).once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FINISH,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_fail_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=True,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_start_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.START,
|
||||
monitoring_log_level=1,
|
||||
dry_run=True,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_does_not_hit_custom_uptimekuma_on_finish_dry_run():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FINISH,
|
||||
monitoring_log_level=1,
|
||||
dry_run=True,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_with_connection_error_logs_warning():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_raise(module.requests.exceptions.ConnectionError)
|
||||
flexmock(module.logger).should_receive('warning').once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_with_other_error_logs_warning():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
response = flexmock(ok=False)
|
||||
response.should_receive('raise_for_status').and_raise(
|
||||
module.requests.exceptions.RequestException
|
||||
)
|
||||
flexmock(module.requests).should_receive('get').with_args(
|
||||
f'{CUSTOM_PUSH_URL}?status=down&msg=fail'
|
||||
).and_return(response)
|
||||
flexmock(module.logger).should_receive('warning').once()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.FAIL,
|
||||
monitoring_log_level=1,
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
def test_ping_monitor_with_invalid_run_state():
|
||||
hook_config = {'push_url': CUSTOM_PUSH_URL}
|
||||
flexmock(module.requests).should_receive('get').never()
|
||||
|
||||
module.ping_monitor(
|
||||
hook_config,
|
||||
{},
|
||||
'config.yaml',
|
||||
borgmatic.hooks.monitor.State.LOG,
|
||||
monitoring_log_level=1,
|
||||
dry_run=True,
|
||||
)
|
||||
+54
-31
@@ -45,23 +45,27 @@ def test_interactive_console_true_when_isatty_and_TERM_is_not_dumb(capsys):
|
||||
|
||||
|
||||
def test_should_do_markup_respects_no_color_value():
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
assert module.should_do_markup(no_color=True, configs={}) is False
|
||||
|
||||
|
||||
def test_should_do_markup_respects_config_value():
|
||||
assert (
|
||||
module.should_do_markup(no_color=False, configs={'foo.yaml': {'output': {'color': False}}})
|
||||
is False
|
||||
)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': False}}) is False
|
||||
|
||||
flexmock(module).should_receive('interactive_console').and_return(True).once()
|
||||
assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': True}}) is True
|
||||
|
||||
|
||||
def test_should_do_markup_prefers_any_false_config_value():
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert (
|
||||
module.should_do_markup(
|
||||
no_color=False,
|
||||
configs={
|
||||
'foo.yaml': {'output': {'color': True}},
|
||||
'bar.yaml': {'output': {'color': False}},
|
||||
'foo.yaml': {'color': True},
|
||||
'bar.yaml': {'color': False},
|
||||
},
|
||||
)
|
||||
is False
|
||||
@@ -80,25 +84,23 @@ def test_should_do_markup_respects_PY_COLORS_environment_variable():
|
||||
|
||||
|
||||
def test_should_do_markup_prefers_no_color_value_to_config_value():
|
||||
assert (
|
||||
module.should_do_markup(no_color=True, configs={'foo.yaml': {'output': {'color': True}}})
|
||||
is False
|
||||
)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert module.should_do_markup(no_color=True, configs={'foo.yaml': {'color': True}}) is False
|
||||
|
||||
|
||||
def test_should_do_markup_prefers_config_value_to_environment_variables():
|
||||
flexmock(module.os.environ).should_receive('get').and_return('True')
|
||||
flexmock(module).should_receive('to_bool').and_return(True)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert (
|
||||
module.should_do_markup(no_color=False, configs={'foo.yaml': {'output': {'color': False}}})
|
||||
is False
|
||||
)
|
||||
assert module.should_do_markup(no_color=False, configs={'foo.yaml': {'color': False}}) is False
|
||||
|
||||
|
||||
def test_should_do_markup_prefers_no_color_value_to_environment_variables():
|
||||
flexmock(module.os.environ).should_receive('get').and_return('True')
|
||||
flexmock(module).should_receive('to_bool').and_return(True)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert module.should_do_markup(no_color=True, configs={}) is False
|
||||
|
||||
@@ -124,6 +126,7 @@ def test_should_do_markup_prefers_PY_COLORS_to_interactive_console_value():
|
||||
def test_should_do_markup_prefers_NO_COLOR_to_interactive_console_value():
|
||||
flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(None)
|
||||
flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True')
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert module.should_do_markup(no_color=False, configs={}) is False
|
||||
|
||||
@@ -131,6 +134,7 @@ def test_should_do_markup_prefers_NO_COLOR_to_interactive_console_value():
|
||||
def test_should_do_markup_respects_NO_COLOR_environment_variable():
|
||||
flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return('True')
|
||||
flexmock(module.os.environ).should_receive('get').with_args('PY_COLORS', None).and_return(None)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert module.should_do_markup(no_color=False, configs={}) is False
|
||||
|
||||
@@ -150,6 +154,7 @@ def test_should_do_markup_prefers_NO_COLOR_to_PY_COLORS():
|
||||
flexmock(module.os.environ).should_receive('get').with_args('NO_COLOR', None).and_return(
|
||||
'SomeValue'
|
||||
)
|
||||
flexmock(module).should_receive('interactive_console').never()
|
||||
|
||||
assert module.should_do_markup(no_color=False, configs={}) is False
|
||||
|
||||
@@ -217,10 +222,11 @@ def test_add_logging_level_skips_global_setting_if_already_set():
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_linux():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG, handlers=list
|
||||
@@ -237,10 +243,11 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_linux(
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_macos():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG, handlers=list
|
||||
@@ -258,10 +265,11 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_macos(
|
||||
def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_freebsd():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.DEBUG, handlers=list
|
||||
@@ -280,10 +288,11 @@ def test_configure_logging_with_syslog_log_level_probes_for_log_socket_on_freebs
|
||||
def test_configure_logging_without_syslog_log_level_skips_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO, handlers=list
|
||||
)
|
||||
@@ -296,10 +305,11 @@ def test_configure_logging_without_syslog_log_level_skips_syslog():
|
||||
def test_configure_logging_skips_syslog_if_not_found():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
flexmock(module).should_receive('Console_color_formatter')
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
level=logging.INFO, handlers=list
|
||||
)
|
||||
@@ -312,8 +322,10 @@ def test_configure_logging_skips_syslog_if_not_found():
|
||||
def test_configure_logging_skips_log_file_if_log_file_logging_is_disabled():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).DISABLED = module.DISABLED
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
@@ -331,8 +343,10 @@ def test_configure_logging_skips_log_file_if_log_file_logging_is_disabled():
|
||||
def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
@@ -356,8 +370,10 @@ def test_configure_logging_to_log_file_instead_of_syslog():
|
||||
def test_configure_logging_to_both_log_file_and_syslog():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
@@ -387,8 +403,10 @@ def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
flexmock(module.logging).should_receive('Formatter').with_args(
|
||||
'{message}', style='{' # noqa: FS003
|
||||
).once()
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module).should_receive('interactive_console').and_return(False)
|
||||
@@ -413,8 +431,10 @@ def test_configure_logging_to_log_file_formats_with_custom_log_format():
|
||||
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
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').once()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
@@ -426,11 +446,14 @@ def test_configure_logging_skips_log_file_if_argument_is_none():
|
||||
module.configure_logging(console_log_level=logging.INFO, log_file=None)
|
||||
|
||||
|
||||
def test_configure_logging_skips_console_color_formatter_if_color_disabled():
|
||||
def test_configure_logging_uses_console_no_color_formatter_if_color_disabled():
|
||||
flexmock(module).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.ANSWER
|
||||
fake_formatter = flexmock()
|
||||
flexmock(module).should_receive('Console_color_formatter').never()
|
||||
flexmock(module).should_receive('Console_no_color_formatter').and_return(fake_formatter)
|
||||
multi_stream_handler = flexmock(setLevel=lambda level: None, level=logging.INFO)
|
||||
multi_stream_handler.should_receive('setFormatter').never()
|
||||
multi_stream_handler.should_receive('setFormatter').with_args(fake_formatter).once()
|
||||
flexmock(module).should_receive('Multi_stream_handler').and_return(multi_stream_handler)
|
||||
|
||||
flexmock(module.logging).should_receive('basicConfig').with_args(
|
||||
|
||||
Reference in New Issue
Block a user