forked from borgmatic-collective/borgmatic
Compare commits
151 Commits
Author | SHA1 | Date |
---|---|---|
Dan Helfman | 84c21b062f | |
Dan Helfman | 76138faaf3 | |
Dan Helfman | 9299841a5b | |
Dan Helfman | 35b5c62ca6 | |
Dan Helfman | 05b989347c | |
Chirag Aggarwal | 00e9bb011a | |
Dan Helfman | 833796d1c4 | |
Dan Helfman | e3425f48be | |
Dan Helfman | 79b094d035 | |
Dan Helfman | b45e45f161 | |
Dan Helfman | ba845d4008 | |
Dan Helfman | 645d29b040 | |
Dan Helfman | e66e449c3b | |
Dan Helfman | 8eb05b840a | |
Dan Helfman | f0fc638284 | |
ennui | c6126a9226 | |
ennui | 62b11ba16b | |
Dan Helfman | 403ae0f698 | |
Dan Helfman | 92a2230a07 | |
Dan Helfman | b3b08ee6d7 | |
Dan Helfman | 15ef37d89f | |
Dan Helfman | e84bac29e5 | |
Dan Helfman | 1a956e8b05 | |
Dan Helfman | 4aae7968b8 | |
Isaac | 66964f613c | |
Isaac | 614c1bf2e4 | |
Isaac | aa770b98f9 | |
Isaac | 453b78c852 | |
Isaac | 0657106893 | |
Isaac | 43c532bc57 | |
Isaac | efb81fc2c1 | |
Isaac | c8f4344f89 | |
Isaac | a047f856a1 | |
Isaac | d732059979 | |
Isaac | ccfdd6806f | |
Isaac | aa564ac5fe | |
Isaac | 77dbb5c499 | |
Isaac | e623f401b9 | |
Isaac | 372622fbb1 | |
Isaac | 469e0ccace | |
Isaac | 59a6ce1462 | |
Isaac | 5a7a1747f2 | |
Isaac | b557d635fd | |
Isaac | d59b9b817f | |
Isaac | 16ac4824a5 | |
Isaac | 3592ec3ddf | |
Isaac | 8f3039be23 | |
Isaac | b4a38d8be9 | |
Isaac | d962376a9d | |
Isaac | 193731a017 | |
Isaac | bbc3e9d717 | |
Isaac | 639e88262e | |
Isaac | f12a10d888 | |
Isaac | 28efc85660 | |
Isaac | f1fd2e88dd | |
Isaac | 700f8e9d9c | |
Isaac | f04036e4a7 | |
Isaac | 062453af51 | |
Isaac | b7fe2a5031 | |
Isaac | ca689505e5 | |
Isaac | 9ff5ea5240 | |
Dan Helfman | 359afe5318 | |
Dan Helfman | 0b397a5bf9 | |
Dan Helfman | a60d7fd173 | |
Isaac | f7e4024fca | |
Isaac | 98e3a81fcf | |
Isaac | 9c77ebb016 | |
Isaac | 23f478ce74 | |
Isaac | d265b6ed6f | |
Dan Helfman | 77c3161c77 | |
Isaac | 2e658cfa56 | |
Isaac | 412d18f218 | |
Isaac | 8060586d8b | |
Isaac | 25b3db72a0 | |
Isaac | 5678f3a96e | |
Isaac | 28b152aedd | |
Isaac | 0009471f67 | |
jetchirag | a62ac42cca | |
Chirag Aggarwal | 68ee9687f5 | |
Chirag Aggarwal | 32395e47f9 | |
Chirag Aggarwal | 8aaba9bb0a | |
Chirag Aggarwal | 96aca4f446 | |
Dan Helfman | 22b84a2fea | |
Dan Helfman | 5962fd473e | |
Dan Helfman | 7e64f415ba | |
Dan Helfman | ae12ccd8e6 | |
Dan Helfman | 3cefeaa229 | |
Dan Helfman | 71b75800cd | |
Dan Helfman | 9ca31530a0 | |
Dan Helfman | b555fcb956 | |
Dan Helfman | 5829196b70 | |
Jesse Johnson | a14870ce48 | |
Dan Helfman | ee5c25f3bd | |
Dan Helfman | da0f5a34f2 | |
Dan Helfman | 065be1d9d4 | |
Dan Helfman | f2f6fb537a | |
Dan Helfman | 7ff994a964 | |
Dan Helfman | 08edecacae | |
Dan Helfman | 1e03046d9a | |
Dan Helfman | c9bf52ee45 | |
Dan Helfman | f947525fca | |
Dan Helfman | 7f7b89d79c | |
Dan Helfman | 499e42df35 | |
Dan Helfman | 4302a07c9b | |
Dan Helfman | 1721c05d2e | |
Dan Helfman | 8a31c27078 | |
Dan Helfman | d6e1cef356 | |
Dan Helfman | f82bf619ff | |
Dan Helfman | 02eeca1fc2 | |
Dan Helfman | 4e78cf1b95 | |
Dan Helfman | 9e9a7c50e5 | |
Dan Helfman | 51bc53e5ca | |
Dan Helfman | b85538c54c | |
Dan Helfman | bb5028e484 | |
Dan Helfman | 53ee0fcfad | |
Dan Helfman | 5f8c79dd16 | |
Dan Helfman | 0a6f5452f4 | |
Dan Helfman | 269fac074b | |
Dan Helfman | 3b21ce4ce8 | |
Dan Helfman | 8bb7631f50 | |
Dan Helfman | 9f5769f87b | |
Dan Helfman | 991e08f16d | |
Chirag Aggarwal | 1ee56805f1 | |
Dan Helfman | 25506b8d2c | |
Dan Helfman | 28e62d824b | |
Dan Helfman | 7ee37a890e | |
Dan Helfman | 8cb5a42a9e | |
Dan Helfman | 5dbb71709c | |
Dan Helfman | 1c67db5d62 | |
Dan Helfman | 96d4a8ee45 | |
Dan Helfman | 81e167959b | |
Divyansh Singh | f273e82d74 | |
Jakub Jirutka | 17f122bfe5 | |
Jakub Jirutka | f0f43174c6 | |
Jakub Jirutka | dfccc1b94a | |
Jakub Jirutka | 195024e505 | |
Jakub Jirutka | 19a00371f5 | |
Jakub Jirutka | 874fba7672 | |
Dan Helfman | 50b0a9ce38 | |
Dan Helfman | 8802f6888e | |
polyzen | ebe5c5e839 | |
Dan Helfman | 613f6c602c | |
Dan Helfman | 4a94c2c9bf | |
Divyansh Singh | 2fea429d78 | |
Divyansh Singh | 264cebd2b1 | |
Divyansh Singh | 9bc2322f9a | |
Chirag Aggarwal | 98c6aa6443 | |
Chirag Aggarwal | edd79ed86c | |
Chirag Aggarwal | 4fa4fccab7 | |
jetchirag | ff1f4dc09c | |
jetchirag | 141474ff07 |
32
.drone.yml
32
.drone.yml
|
@ -1,19 +1,20 @@
|
|||
---
|
||||
kind: pipeline
|
||||
name: python-3-8-alpine-3-13
|
||||
|
||||
services:
|
||||
- name: postgresql
|
||||
image: postgres:13.1-alpine
|
||||
image: docker.io/postgres:13.1-alpine
|
||||
environment:
|
||||
POSTGRES_PASSWORD: test
|
||||
POSTGRES_DB: test
|
||||
- name: mysql
|
||||
image: mariadb:10.5
|
||||
image: docker.io/mariadb:10.5
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: test
|
||||
MYSQL_DATABASE: test
|
||||
- name: mongodb
|
||||
image: mongo:5.0.5
|
||||
image: docker.io/mongo:5.0.5
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: root
|
||||
MONGO_INITDB_ROOT_PASSWORD: test
|
||||
|
@ -23,7 +24,7 @@ clone:
|
|||
|
||||
steps:
|
||||
- name: build
|
||||
image: alpine:3.13
|
||||
image: docker.io/alpine:3.13
|
||||
environment:
|
||||
TEST_CONTAINER: true
|
||||
pull: always
|
||||
|
@ -32,27 +33,32 @@ steps:
|
|||
---
|
||||
kind: pipeline
|
||||
name: documentation
|
||||
type: exec
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
clone:
|
||||
skip_verify: true
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
environment:
|
||||
USERNAME:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
PASSWORD:
|
||||
from_secret: docker_password
|
||||
registry: projects.torsion.org
|
||||
repo: projects.torsion.org/borgmatic-collective/borgmatic
|
||||
tags: docs
|
||||
dockerfile: docs/Dockerfile
|
||||
IMAGE_NAME: projects.torsion.org/borgmatic-collective/borgmatic:docs
|
||||
commands:
|
||||
- podman login --username "$USERNAME" --password "$PASSWORD" projects.torsion.org
|
||||
- podman build --tag "$IMAGE_NAME" --file docs/Dockerfile --storage-opt "overlay.mount_program=/usr/bin/fuse-overlayfs" .
|
||||
- podman push "$IMAGE_NAME"
|
||||
|
||||
trigger:
|
||||
repo:
|
||||
- borgmatic-collective/borgmatic
|
||||
branch:
|
||||
- master
|
||||
- main
|
||||
event:
|
||||
- push
|
||||
|
|
37
NEWS
37
NEWS
|
@ -1,4 +1,34 @@
|
|||
1.7.12.dev0
|
||||
1.7.14.dev0
|
||||
* #688: Tweak archive check probing logic to use the newest timestamp found when multiple exist.
|
||||
* #659: Add Borg 2 date-based matching flags to various actions for archive selection.
|
||||
|
||||
1.7.13
|
||||
* #375: Restore particular PostgreSQL schemas from a database dump via "borgmatic restore --schema"
|
||||
flag. See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/backup-your-databases/#restore-particular-schemas
|
||||
* #678: Fix error from PostgreSQL when dumping a database with a "format" of "plain".
|
||||
* #678: Fix PostgreSQL hook to support "psql_command" and "pg_restore_command" options containing
|
||||
commands with arguments.
|
||||
* #678: Fix calls to psql in PostgreSQL hook to ignore "~/.psqlrc", whose settings can break
|
||||
database dumping.
|
||||
* #680: Add support for logging each log line as a JSON object via global "--log-json" flag.
|
||||
* #682: Fix "source_directories_must_exist" option to expand globs and tildes in source directories.
|
||||
* #684: Rename "master" development branch to "main" to use more inclusive language. You'll need to
|
||||
update your development checkouts accordingly.
|
||||
* #686: Add fish shell completion script so you can tab-complete on the borgmatic command-line. See
|
||||
the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/set-up-backups/#shell-completion
|
||||
* #687: Fix borgmatic error when not finding the configuration schema for certain "pip install
|
||||
--editable" development installs.
|
||||
* #688: Fix archive checks being skipped even when particular archives haven't been checked
|
||||
recently. This occurred when using multiple borgmatic configuration files with different
|
||||
"archive_name_format"s, for instance.
|
||||
* #691: Fix error in "borgmatic restore" action when the configured repository path is relative
|
||||
instead of absolute.
|
||||
* #694: Run "borgmatic borg" action without capturing output so interactive prompts and flags like
|
||||
"--progress" still work.
|
||||
|
||||
1.7.12
|
||||
* #413: Add "log_file" context to command hooks so your scripts can consume the borgmatic log file.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/add-preparation-and-cleanup-steps-to-backups/
|
||||
|
@ -10,6 +40,9 @@
|
|||
* #672: Selectively shallow merge certain mappings or sequences when including configuration files.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#shallow-merge
|
||||
* #672: Selectively omit list values when including configuration files. See the documentation for
|
||||
more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#list-merge
|
||||
* #673: View the results of configuration file merging via "validate-borgmatic-config --show" flag.
|
||||
See the documentation for more information:
|
||||
https://torsion.org/borgmatic/docs/how-to/make-per-application-backups/#debugging-includes
|
||||
|
@ -359,7 +392,7 @@
|
|||
* #398: Clarify canonical home of borgmatic in documentation.
|
||||
* #406: Clarify that spaces in path names should not be backslashed in path names.
|
||||
* #423: Fix error handling to error loudly when Borg gets killed due to running out of memory!
|
||||
* Fix build so as not to attempt to build and push documentation for a non-master branch.
|
||||
* Fix build so as not to attempt to build and push documentation for a non-main branch.
|
||||
* "Fix" build failure with Alpine Edge by switching from Edge to Alpine 3.13.
|
||||
* Move #borgmatic IRC channel from Freenode to Libera Chat due to Freenode takeover drama.
|
||||
IRC connection info: https://torsion.org/borgmatic/#issues
|
||||
|
|
|
@ -11,7 +11,7 @@ borgmatic is simple, configuration-driven backup software for servers and
|
|||
workstations. Protect your files with client-side encryption. Backup your
|
||||
databases too. Monitor it all with integrated third-party services.
|
||||
|
||||
The canonical home of borgmatic is at <a href="https://torsion.org/borgmatic">https://torsion.org/borgmatic</a>.
|
||||
The canonical home of borgmatic is at <a href="https://torsion.org/borgmatic">https://torsion.org/borgmatic/</a>
|
||||
|
||||
Here's an example configuration file:
|
||||
|
||||
|
@ -165,5 +165,5 @@ 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.
|
||||
|
||||
<a href="https://build.torsion.org/borgmatic-collective/borgmatic" alt="build status">![Build Status](https://build.torsion.org/api/badges/borgmatic-collective/borgmatic/status.svg?ref=refs/heads/master)</a>
|
||||
<a href="https://build.torsion.org/borgmatic-collective/borgmatic" alt="build status">![Build Status](https://build.torsion.org/api/badges/borgmatic-collective/borgmatic/status.svg?ref=refs/heads/main)</a>
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ permalink: security-policy/index.html
|
|||
|
||||
While we want to hear about security vulnerabilities in all versions of
|
||||
borgmatic, security fixes are only made to the most recently released version.
|
||||
It's simply not practical for our small volunteer effort to maintain multiple
|
||||
release branches and put out separate security patches for each.
|
||||
It's not practical for our small volunteer effort to maintain multiple release
|
||||
branches and put out separate security patches for each.
|
||||
|
||||
## Reporting a vulnerability
|
||||
|
||||
|
|
|
@ -8,7 +8,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_borg(
|
||||
repository, storage, local_borg_version, borg_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
borg_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "borg" action for the given repository.
|
||||
|
@ -16,12 +22,15 @@ def run_borg(
|
|||
if borg_arguments.repository is None or borgmatic.config.validate.repositories_match(
|
||||
repository, borg_arguments.repository
|
||||
):
|
||||
logger.info(f'{repository["path"]}: Running arbitrary Borg command')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Running arbitrary Borg command'
|
||||
)
|
||||
archive_name = borgmatic.borg.rlist.resolve_archive_name(
|
||||
repository['path'],
|
||||
borg_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
|
|
@ -7,7 +7,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_break_lock(
|
||||
repository, storage, local_borg_version, break_lock_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
break_lock_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "break-lock" action for the given repository.
|
||||
|
@ -15,11 +21,14 @@ def run_break_lock(
|
|||
if break_lock_arguments.repository is None or borgmatic.config.validate.repositories_match(
|
||||
repository, break_lock_arguments.repository
|
||||
):
|
||||
logger.info(f'{repository["path"]}: Breaking repository and cache locks')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Breaking repository and cache locks'
|
||||
)
|
||||
borgmatic.borg.break_lock.break_lock(
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
|
|
|
@ -37,13 +37,14 @@ def run_check(
|
|||
global_arguments.dry_run,
|
||||
**hook_context,
|
||||
)
|
||||
logger.info(f'{repository["path"]}: Running consistency checks')
|
||||
logger.info(f'{repository.get("label", repository["path"])}: Running consistency checks')
|
||||
borgmatic.borg.check.check_archives(
|
||||
repository['path'],
|
||||
location,
|
||||
storage,
|
||||
consistency,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
progress=check_arguments.progress,
|
||||
|
|
|
@ -39,12 +39,15 @@ def run_compact(
|
|||
**hook_context,
|
||||
)
|
||||
if borgmatic.borg.feature.available(borgmatic.borg.feature.Feature.COMPACT, local_borg_version):
|
||||
logger.info(f'{repository["path"]}: Compacting segments{dry_run_label}')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Compacting segments{dry_run_label}'
|
||||
)
|
||||
borgmatic.borg.compact.compact_segments(
|
||||
global_arguments.dry_run,
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
progress=compact_arguments.progress,
|
||||
|
@ -52,7 +55,9 @@ def run_compact(
|
|||
threshold=compact_arguments.threshold,
|
||||
)
|
||||
else: # pragma: nocover
|
||||
logger.info(f'{repository["path"]}: Skipping compact (only available/needed in Borg 1.2+)')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Skipping compact (only available/needed in Borg 1.2+)'
|
||||
)
|
||||
borgmatic.hooks.command.execute_hook(
|
||||
hooks.get('after_compact'),
|
||||
hooks.get('umask'),
|
||||
|
|
|
@ -42,7 +42,7 @@ def run_create(
|
|||
global_arguments.dry_run,
|
||||
**hook_context,
|
||||
)
|
||||
logger.info(f'{repository["path"]}: Creating archive{dry_run_label}')
|
||||
logger.info(f'{repository.get("label", repository["path"])}: Creating archive{dry_run_label}')
|
||||
borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured(
|
||||
'remove_database_dumps',
|
||||
hooks,
|
||||
|
@ -67,6 +67,7 @@ def run_create(
|
|||
location,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
progress=create_arguments.progress,
|
||||
|
|
|
@ -33,6 +33,7 @@ def run_export_tar(
|
|||
export_tar_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
),
|
||||
|
@ -40,6 +41,7 @@ def run_export_tar(
|
|||
export_tar_arguments.destination,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
tar_filter=export_tar_arguments.tar_filter,
|
||||
|
|
|
@ -35,7 +35,9 @@ def run_extract(
|
|||
if extract_arguments.repository is None or borgmatic.config.validate.repositories_match(
|
||||
repository, extract_arguments.repository
|
||||
):
|
||||
logger.info(f'{repository["path"]}: Extracting archive {extract_arguments.archive}')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Extracting archive {extract_arguments.archive}'
|
||||
)
|
||||
borgmatic.borg.extract.extract_archive(
|
||||
global_arguments.dry_run,
|
||||
repository['path'],
|
||||
|
@ -44,6 +46,7 @@ def run_extract(
|
|||
extract_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
),
|
||||
|
@ -51,6 +54,7 @@ def run_extract(
|
|||
location,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
destination_path=extract_arguments.destination,
|
||||
|
|
|
@ -9,7 +9,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_info(
|
||||
repository, storage, local_borg_version, info_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
info_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "info" action for the given repository and archive.
|
||||
|
@ -20,12 +26,15 @@ def run_info(
|
|||
repository, info_arguments.repository
|
||||
):
|
||||
if not info_arguments.json: # pragma: nocover
|
||||
logger.answer(f'{repository["path"]}: Displaying archive summary information')
|
||||
logger.answer(
|
||||
f'{repository.get("label", repository["path"])}: Displaying archive summary information'
|
||||
)
|
||||
info_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
|
||||
repository['path'],
|
||||
info_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -33,9 +42,10 @@ def run_info(
|
|||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
info_arguments=info_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
info_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
if json_output: # pragma: nocover
|
||||
yield json.loads(json_output)
|
||||
|
|
|
@ -8,7 +8,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_list(
|
||||
repository, storage, local_borg_version, list_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
list_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "list" action for the given repository and archive.
|
||||
|
@ -20,14 +26,15 @@ def run_list(
|
|||
):
|
||||
if not list_arguments.json: # pragma: nocover
|
||||
if list_arguments.find_paths:
|
||||
logger.answer(f'{repository["path"]}: Searching archives')
|
||||
logger.answer(f'{repository.get("label", repository["path"])}: Searching archives')
|
||||
elif not list_arguments.archive:
|
||||
logger.answer(f'{repository["path"]}: Listing archives')
|
||||
logger.answer(f'{repository.get("label", repository["path"])}: Listing archives')
|
||||
list_arguments.archive = borgmatic.borg.rlist.resolve_archive_name(
|
||||
repository['path'],
|
||||
list_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -35,9 +42,10 @@ def run_list(
|
|||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
list_arguments=list_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
list_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
if json_output: # pragma: nocover
|
||||
yield json.loads(json_output)
|
||||
|
|
|
@ -8,7 +8,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_mount(
|
||||
repository, storage, local_borg_version, mount_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
mount_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "mount" action for the given repository.
|
||||
|
@ -17,9 +23,11 @@ def run_mount(
|
|||
repository, mount_arguments.repository
|
||||
):
|
||||
if mount_arguments.archive:
|
||||
logger.info(f'{repository["path"]}: Mounting archive {mount_arguments.archive}')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Mounting archive {mount_arguments.archive}'
|
||||
)
|
||||
else: # pragma: nocover
|
||||
logger.info(f'{repository["path"]}: Mounting repository')
|
||||
logger.info(f'{repository.get("label", repository["path"])}: Mounting repository')
|
||||
|
||||
borgmatic.borg.mount.mount_archive(
|
||||
repository['path'],
|
||||
|
@ -28,15 +36,14 @@ def run_mount(
|
|||
mount_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
),
|
||||
mount_arguments.mount_point,
|
||||
mount_arguments.paths,
|
||||
mount_arguments.foreground,
|
||||
mount_arguments.options,
|
||||
mount_arguments,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
|
|
|
@ -37,17 +37,17 @@ def run_prune(
|
|||
global_arguments.dry_run,
|
||||
**hook_context,
|
||||
)
|
||||
logger.info(f'{repository["path"]}: Pruning archives{dry_run_label}')
|
||||
logger.info(f'{repository.get("label", repository["path"])}: Pruning archives{dry_run_label}')
|
||||
borgmatic.borg.prune.prune_archives(
|
||||
global_arguments.dry_run,
|
||||
repository['path'],
|
||||
storage,
|
||||
retention,
|
||||
local_borg_version,
|
||||
prune_arguments,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
stats=prune_arguments.stats,
|
||||
list_archives=prune_arguments.list_archives,
|
||||
)
|
||||
borgmatic.hooks.command.execute_hook(
|
||||
hooks.get('after_prune'),
|
||||
|
|
|
@ -23,12 +23,13 @@ def run_rcreate(
|
|||
):
|
||||
return
|
||||
|
||||
logger.info(f'{repository["path"]}: Creating repository')
|
||||
logger.info(f'{repository.get("label", repository["path"])}: Creating repository')
|
||||
borgmatic.borg.rcreate.create_repository(
|
||||
global_arguments.dry_run,
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
rcreate_arguments.encryption_mode,
|
||||
rcreate_arguments.source_repository,
|
||||
rcreate_arguments.copy_crypt_key,
|
||||
|
|
|
@ -73,12 +73,14 @@ def restore_single_database(
|
|||
Given (among other things) an archive name, a database hook name, and a configured database
|
||||
configuration dict, restore that database from the archive.
|
||||
'''
|
||||
logger.info(f'{repository}: Restoring database {database["name"]}')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Restoring database {database["name"]}'
|
||||
)
|
||||
|
||||
dump_pattern = borgmatic.hooks.dispatch.call_hooks(
|
||||
'make_database_dump_pattern',
|
||||
hooks,
|
||||
repository,
|
||||
repository['path'],
|
||||
borgmatic.hooks.dump.DATABASE_HOOK_NAMES,
|
||||
location,
|
||||
database['name'],
|
||||
|
@ -87,12 +89,13 @@ def restore_single_database(
|
|||
# Kick off a single database extract to stdout.
|
||||
extract_process = borgmatic.borg.extract.extract_archive(
|
||||
dry_run=global_arguments.dry_run,
|
||||
repository=repository,
|
||||
repository=repository['path'],
|
||||
archive=archive_name,
|
||||
paths=borgmatic.hooks.dump.convert_glob_patterns_to_borg_patterns([dump_pattern]),
|
||||
location_config=location,
|
||||
storage_config=storage,
|
||||
local_borg_version=local_borg_version,
|
||||
global_arguments=global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
destination_path='/',
|
||||
|
@ -105,7 +108,7 @@ def restore_single_database(
|
|||
borgmatic.hooks.dispatch.call_hooks(
|
||||
'restore_database_dump',
|
||||
{hook_name: [database]},
|
||||
repository,
|
||||
repository['path'],
|
||||
borgmatic.hooks.dump.DATABASE_HOOK_NAMES,
|
||||
location,
|
||||
global_arguments.dry_run,
|
||||
|
@ -114,13 +117,20 @@ def restore_single_database(
|
|||
|
||||
|
||||
def collect_archive_database_names(
|
||||
repository, archive, location, storage, local_borg_version, local_path, remote_path,
|
||||
repository,
|
||||
archive,
|
||||
location,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a resolved archive name, a location configuration dict,
|
||||
a storage configuration dict, the local Borg version, and local and remote Borg paths, query the
|
||||
archive for the names of databases it contains and return them as a dict from hook name to a
|
||||
sequence of database names.
|
||||
a storage configuration dict, the local Borg version, global_arguments an argparse.Namespace,
|
||||
and local and remote Borg paths, query the archive for the names of databases it contains and
|
||||
return them as a dict from hook name to a sequence of database names.
|
||||
'''
|
||||
borgmatic_source_directory = os.path.expanduser(
|
||||
location.get(
|
||||
|
@ -135,6 +145,7 @@ def collect_archive_database_names(
|
|||
archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
list_path=parent_dump_path,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
|
@ -180,7 +191,7 @@ def find_databases_to_restore(requested_database_names, archive_database_names):
|
|||
if 'all' in restore_names[UNSPECIFIED_HOOK]:
|
||||
restore_names[UNSPECIFIED_HOOK].remove('all')
|
||||
|
||||
for (hook_name, database_names) in archive_database_names.items():
|
||||
for hook_name, database_names in archive_database_names.items():
|
||||
restore_names.setdefault(hook_name, []).extend(database_names)
|
||||
|
||||
# If a database is to be restored as part of "all", then remove it from restore names so
|
||||
|
@ -256,7 +267,7 @@ def run_restore(
|
|||
return
|
||||
|
||||
logger.info(
|
||||
f'{repository["path"]}: Restoring databases from archive {restore_arguments.archive}'
|
||||
f'{repository.get("label", repository["path"])}: Restoring databases from archive {restore_arguments.archive}'
|
||||
)
|
||||
|
||||
borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured(
|
||||
|
@ -273,6 +284,7 @@ def run_restore(
|
|||
restore_arguments.archive,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -282,6 +294,7 @@ def run_restore(
|
|||
location,
|
||||
storage,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -303,7 +316,7 @@ def run_restore(
|
|||
|
||||
found_names.add(database_name)
|
||||
restore_single_database(
|
||||
repository['path'],
|
||||
repository,
|
||||
location,
|
||||
storage,
|
||||
hooks,
|
||||
|
@ -313,7 +326,7 @@ def run_restore(
|
|||
remote_path,
|
||||
archive_name,
|
||||
found_hook_name or hook_name,
|
||||
found_database,
|
||||
dict(found_database, **{'schemas': restore_arguments.schemas}),
|
||||
)
|
||||
|
||||
# For any database that weren't found via exact matches in the hooks configuration, try to
|
||||
|
@ -332,7 +345,7 @@ def run_restore(
|
|||
database['name'] = database_name
|
||||
|
||||
restore_single_database(
|
||||
repository['path'],
|
||||
repository,
|
||||
location,
|
||||
storage,
|
||||
hooks,
|
||||
|
@ -342,7 +355,7 @@ def run_restore(
|
|||
remote_path,
|
||||
archive_name,
|
||||
found_hook_name or hook_name,
|
||||
database,
|
||||
dict(database, **{'schemas': restore_arguments.schemas}),
|
||||
)
|
||||
|
||||
borgmatic.hooks.dispatch.call_hooks_even_if_unconfigured(
|
||||
|
|
|
@ -8,7 +8,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_rinfo(
|
||||
repository, storage, local_borg_version, rinfo_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
rinfo_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "rinfo" action for the given repository.
|
||||
|
@ -19,13 +25,16 @@ def run_rinfo(
|
|||
repository, rinfo_arguments.repository
|
||||
):
|
||||
if not rinfo_arguments.json: # pragma: nocover
|
||||
logger.answer(f'{repository["path"]}: Displaying repository summary information')
|
||||
logger.answer(
|
||||
f'{repository.get("label", repository["path"])}: Displaying repository summary information'
|
||||
)
|
||||
|
||||
json_output = borgmatic.borg.rinfo.display_repository_info(
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
rinfo_arguments=rinfo_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
|
|
|
@ -8,7 +8,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def run_rlist(
|
||||
repository, storage, local_borg_version, rlist_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
):
|
||||
'''
|
||||
Run the "rlist" action for the given repository.
|
||||
|
@ -19,13 +25,14 @@ def run_rlist(
|
|||
repository, rlist_arguments.repository
|
||||
):
|
||||
if not rlist_arguments.json: # pragma: nocover
|
||||
logger.answer(f'{repository["path"]}: Listing repository')
|
||||
logger.answer(f'{repository.get("label", repository["path"])}: Listing repository')
|
||||
|
||||
json_output = borgmatic.borg.rlist.list_repository(
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
|
|
|
@ -17,13 +17,16 @@ def run_transfer(
|
|||
'''
|
||||
Run the "transfer" action for the given repository.
|
||||
'''
|
||||
logger.info(f'{repository["path"]}: Transferring archives to repository')
|
||||
logger.info(
|
||||
f'{repository.get("label", repository["path"])}: Transferring archives to repository'
|
||||
)
|
||||
borgmatic.borg.transfer.transfer_archives(
|
||||
global_arguments.dry_run,
|
||||
repository['path'],
|
||||
storage,
|
||||
local_borg_version,
|
||||
transfer_arguments,
|
||||
global_arguments,
|
||||
local_path=local_path,
|
||||
remote_path=remote_path,
|
||||
)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import logging
|
||||
|
||||
import borgmatic.commands.arguments
|
||||
import borgmatic.logger
|
||||
from borgmatic.borg import environment, flags
|
||||
from borgmatic.execute import execute_command
|
||||
from borgmatic.execute import DO_NOT_CAPTURE, execute_command
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -36,6 +37,14 @@ def run_arbitrary_borg(
|
|||
command_options_start_index = 2 if options[0] in BORG_SUBCOMMANDS_WITH_SUBCOMMANDS else 1
|
||||
borg_command = tuple(options[:command_options_start_index])
|
||||
command_options = tuple(options[command_options_start_index:])
|
||||
|
||||
if (
|
||||
borg_command
|
||||
and borg_command[0] in borgmatic.commands.arguments.SUBPARSER_ALIASES.keys()
|
||||
):
|
||||
logger.warning(
|
||||
f"Borg's {borg_command[0]} subcommand is supported natively by borgmatic. Try this instead: borgmatic {borg_command[0]}"
|
||||
)
|
||||
except IndexError:
|
||||
borg_command = ()
|
||||
command_options = ()
|
||||
|
@ -62,7 +71,7 @@ def run_arbitrary_borg(
|
|||
|
||||
return execute_command(
|
||||
full_command,
|
||||
output_log_level=logging.ANSWER,
|
||||
output_file=DO_NOT_CAPTURE,
|
||||
borg_local_path=local_path,
|
||||
extra_environment=environment.make_environment(storage_config),
|
||||
)
|
||||
|
|
|
@ -7,12 +7,17 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
def break_lock(
|
||||
repository_path, storage_config, local_borg_version, local_path='borg', remote_path=None,
|
||||
repository_path,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage configuration dict, the local Borg version,
|
||||
and optional local and remote Borg paths, break any repository and cache locks leftover from Borg
|
||||
aborting.
|
||||
an argparse.Namespace of global arguments, and optional local and remote Borg paths, break any
|
||||
repository and cache locks leftover from Borg aborting.
|
||||
'''
|
||||
umask = storage_config.get('umask', None)
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
@ -21,6 +26,7 @@ def break_lock(
|
|||
(local_path, 'break-lock')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import argparse
|
||||
import datetime
|
||||
import hashlib
|
||||
import itertools
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
@ -88,12 +90,18 @@ def parse_frequency(frequency):
|
|||
|
||||
|
||||
def filter_checks_on_frequency(
|
||||
location_config, consistency_config, borg_repository_id, checks, force
|
||||
location_config,
|
||||
consistency_config,
|
||||
borg_repository_id,
|
||||
checks,
|
||||
force,
|
||||
archives_check_id=None,
|
||||
):
|
||||
'''
|
||||
Given a location config, a consistency config with a "checks" sequence of dicts, a Borg
|
||||
repository ID, a sequence of checks, and whether to force checks to run, filter down those
|
||||
checks based on the configured "frequency" for each check as compared to its check time file.
|
||||
repository ID, a sequence of checks, whether to force checks to run, and an ID for the archives
|
||||
check potentially being run (if any), filter down those checks based on the configured
|
||||
"frequency" for each check as compared to its check time file.
|
||||
|
||||
In other words, a check whose check time file's timestamp is too new (based on the configured
|
||||
frequency) will get cut from the returned sequence of checks. Example:
|
||||
|
@ -127,8 +135,8 @@ def filter_checks_on_frequency(
|
|||
if not frequency_delta:
|
||||
continue
|
||||
|
||||
check_time = read_check_time(
|
||||
make_check_time_path(location_config, borg_repository_id, check)
|
||||
check_time = probe_for_check_time(
|
||||
location_config, borg_repository_id, check, archives_check_id
|
||||
)
|
||||
if not check_time:
|
||||
continue
|
||||
|
@ -145,36 +153,19 @@ def filter_checks_on_frequency(
|
|||
return tuple(filtered_checks)
|
||||
|
||||
|
||||
def make_check_flags(local_borg_version, storage_config, checks, check_last=None, prefix=None):
|
||||
def make_archive_filter_flags(
|
||||
local_borg_version, storage_config, checks, check_last=None, prefix=None
|
||||
):
|
||||
'''
|
||||
Given the local Borg version, a storage configuration dict, a parsed sequence of checks, the
|
||||
check last value, and a consistency check prefix, transform the checks into tuple of
|
||||
command-line flags.
|
||||
command-line flags for filtering archives in a check command.
|
||||
|
||||
For example, given parsed checks of:
|
||||
|
||||
('repository',)
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('--repository-only',)
|
||||
|
||||
However, if both "repository" and "archives" are in checks, then omit them from the returned
|
||||
flags because Borg does both checks by default. If "data" is in checks, that implies "archives".
|
||||
|
||||
Additionally, if a check_last value is given and "archives" is in checks, then include a
|
||||
"--last" flag. And if a prefix value is given and "archives" is in checks, then include a
|
||||
"--match-archives" flag.
|
||||
If a check_last value is given and "archives" is in checks, then include a "--last" flag. And if
|
||||
a prefix value is given and "archives" is in checks, then include a "--match-archives" flag.
|
||||
'''
|
||||
if 'data' in checks:
|
||||
data_flags = ('--verify-data',)
|
||||
checks += ('archives',)
|
||||
else:
|
||||
data_flags = ()
|
||||
|
||||
if 'archives' in checks:
|
||||
last_flags = ('--last', str(check_last)) if check_last else ()
|
||||
match_archives_flags = (
|
||||
if 'archives' in checks or 'data' in checks:
|
||||
return (('--last', str(check_last)) if check_last else ()) + (
|
||||
(
|
||||
('--match-archives', f'sh:{prefix}*')
|
||||
if feature.available(feature.Feature.MATCH_ARCHIVES, local_borg_version)
|
||||
|
@ -189,19 +180,53 @@ def make_check_flags(local_borg_version, storage_config, checks, check_last=None
|
|||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
last_flags = ()
|
||||
match_archives_flags = ()
|
||||
if check_last:
|
||||
logger.warning(
|
||||
'Ignoring check_last option, as "archives" or "data" are not in consistency checks'
|
||||
)
|
||||
if prefix:
|
||||
logger.warning(
|
||||
'Ignoring consistency prefix option, as "archives" or "data" are not in consistency checks'
|
||||
)
|
||||
|
||||
common_flags = last_flags + match_archives_flags + data_flags
|
||||
if check_last:
|
||||
logger.warning(
|
||||
'Ignoring check_last option, as "archives" or "data" are not in consistency checks'
|
||||
)
|
||||
if prefix:
|
||||
logger.warning(
|
||||
'Ignoring consistency prefix option, as "archives" or "data" are not in consistency checks'
|
||||
)
|
||||
|
||||
return ()
|
||||
|
||||
|
||||
def make_archives_check_id(archive_filter_flags):
|
||||
'''
|
||||
Given a sequence of flags to filter archives, return a unique hash corresponding to those
|
||||
particular flags. If there are no flags, return None.
|
||||
'''
|
||||
if not archive_filter_flags:
|
||||
return None
|
||||
|
||||
return hashlib.sha256(' '.join(archive_filter_flags).encode()).hexdigest()
|
||||
|
||||
|
||||
def make_check_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.
|
||||
|
||||
For example, given parsed checks of:
|
||||
|
||||
('repository',)
|
||||
|
||||
This will be returned as:
|
||||
|
||||
('--repository-only',)
|
||||
|
||||
However, if both "repository" and "archives" are in checks, then omit them from the returned
|
||||
flags because Borg does both checks by default. If "data" is in checks, that implies "archives".
|
||||
'''
|
||||
if 'data' in checks:
|
||||
data_flags = ('--verify-data',)
|
||||
checks += ('archives',)
|
||||
else:
|
||||
data_flags = ()
|
||||
|
||||
common_flags = archive_filter_flags + data_flags
|
||||
|
||||
if {'repository', 'archives'}.issubset(set(checks)):
|
||||
return common_flags
|
||||
|
@ -212,18 +237,27 @@ def make_check_flags(local_borg_version, storage_config, checks, check_last=None
|
|||
)
|
||||
|
||||
|
||||
def make_check_time_path(location_config, borg_repository_id, check_type):
|
||||
def make_check_time_path(location_config, borg_repository_id, check_type, archives_check_id=None):
|
||||
'''
|
||||
Given a location configuration dict, a Borg repository ID, and the name of a check type
|
||||
("repository", "archives", etc.), return a path for recording that check's time (the time of
|
||||
that check last occurring).
|
||||
Given a location configuration dict, a Borg repository ID, the name of a check type
|
||||
("repository", "archives", etc.), and a unique hash of the archives filter flags, return a
|
||||
path for recording that check's time (the time of that check last occurring).
|
||||
'''
|
||||
borgmatic_source_directory = os.path.expanduser(
|
||||
location_config.get('borgmatic_source_directory', state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY)
|
||||
)
|
||||
|
||||
if check_type in ('archives', 'data'):
|
||||
return os.path.join(
|
||||
borgmatic_source_directory,
|
||||
'checks',
|
||||
borg_repository_id,
|
||||
check_type,
|
||||
archives_check_id if archives_check_id else 'all',
|
||||
)
|
||||
|
||||
return os.path.join(
|
||||
os.path.expanduser(
|
||||
location_config.get(
|
||||
'borgmatic_source_directory', state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
|
||||
)
|
||||
),
|
||||
borgmatic_source_directory,
|
||||
'checks',
|
||||
borg_repository_id,
|
||||
check_type,
|
||||
|
@ -253,12 +287,81 @@ def read_check_time(path):
|
|||
return None
|
||||
|
||||
|
||||
def probe_for_check_time(location_config, borg_repository_id, check, archives_check_id):
|
||||
'''
|
||||
Given a location configuration dict, a Borg repository ID, the name of a check type
|
||||
("repository", "archives", etc.), and a unique hash of the archives filter flags, return a
|
||||
the corresponding check time or None if such a check time does not exist.
|
||||
|
||||
When the check type is "archives" or "data", this function probes two different paths to find
|
||||
the check time, e.g.:
|
||||
|
||||
~/.borgmatic/checks/1234567890/archives/9876543210
|
||||
~/.borgmatic/checks/1234567890/archives/all
|
||||
|
||||
... and returns the maximum modification time of the files found (if any). The first path
|
||||
represents a more specific archives check time (a check on a subset of archives), and the second
|
||||
is a fallback to the last "all" archives check.
|
||||
|
||||
For other check types, this function reads from a single check time path, e.g.:
|
||||
|
||||
~/.borgmatic/checks/1234567890/repository
|
||||
'''
|
||||
check_times = (
|
||||
read_check_time(group[0])
|
||||
for group in itertools.groupby(
|
||||
(
|
||||
make_check_time_path(location_config, borg_repository_id, check, archives_check_id),
|
||||
make_check_time_path(location_config, borg_repository_id, check),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
return max(check_time for check_time in check_times if check_time)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def upgrade_check_times(location_config, borg_repository_id):
|
||||
'''
|
||||
Given a location configuration dict and a Borg repository ID, upgrade any corresponding check
|
||||
times on disk from old-style paths to new-style paths.
|
||||
|
||||
Currently, the only upgrade performed is renaming an archive or data check path that looks like:
|
||||
|
||||
~/.borgmatic/checks/1234567890/archives
|
||||
|
||||
to:
|
||||
|
||||
~/.borgmatic/checks/1234567890/archives/all
|
||||
'''
|
||||
for check_type in ('archives', 'data'):
|
||||
new_path = make_check_time_path(location_config, borg_repository_id, check_type, 'all')
|
||||
old_path = os.path.dirname(new_path)
|
||||
temporary_path = f'{old_path}.temp'
|
||||
|
||||
if not os.path.isfile(old_path) and not os.path.isfile(temporary_path):
|
||||
return
|
||||
|
||||
logger.debug(f'Upgrading archives check time from {old_path} to {new_path}')
|
||||
|
||||
try:
|
||||
os.rename(old_path, temporary_path)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
os.mkdir(old_path)
|
||||
os.rename(temporary_path, new_path)
|
||||
|
||||
|
||||
def check_archives(
|
||||
repository_path,
|
||||
location_config,
|
||||
storage_config,
|
||||
consistency_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
progress=None,
|
||||
|
@ -283,6 +386,7 @@ def check_archives(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
argparse.Namespace(json=True),
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -290,16 +394,26 @@ def check_archives(
|
|||
except (json.JSONDecodeError, KeyError):
|
||||
raise ValueError(f'Cannot determine Borg repository ID for {repository_path}')
|
||||
|
||||
upgrade_check_times(location_config, borg_repository_id)
|
||||
|
||||
check_last = consistency_config.get('check_last', None)
|
||||
prefix = consistency_config.get('prefix')
|
||||
configured_checks = parse_checks(consistency_config, only_checks)
|
||||
lock_wait = None
|
||||
extra_borg_options = storage_config.get('extra_borg_options', {}).get('check', '')
|
||||
archive_filter_flags = make_archive_filter_flags(
|
||||
local_borg_version, storage_config, configured_checks, check_last, prefix
|
||||
)
|
||||
archives_check_id = make_archives_check_id(archive_filter_flags)
|
||||
|
||||
checks = filter_checks_on_frequency(
|
||||
location_config,
|
||||
consistency_config,
|
||||
borg_repository_id,
|
||||
parse_checks(consistency_config, only_checks),
|
||||
configured_checks,
|
||||
force,
|
||||
archives_check_id,
|
||||
)
|
||||
check_last = consistency_config.get('check_last', None)
|
||||
lock_wait = None
|
||||
extra_borg_options = storage_config.get('extra_borg_options', {}).get('check', '')
|
||||
|
||||
if set(checks).intersection({'repository', 'archives', 'data'}):
|
||||
lock_wait = storage_config.get('lock_wait')
|
||||
|
@ -310,13 +424,12 @@ def check_archives(
|
|||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
|
||||
prefix = consistency_config.get('prefix')
|
||||
|
||||
full_command = (
|
||||
(local_path, 'check')
|
||||
+ (('--repair',) if repair else ())
|
||||
+ make_check_flags(local_borg_version, storage_config, checks, check_last, prefix)
|
||||
+ make_check_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 ())
|
||||
+ verbosity_flags
|
||||
+ (('--progress',) if progress else ())
|
||||
|
@ -336,10 +449,18 @@ def check_archives(
|
|||
execute_command(full_command, extra_environment=borg_environment)
|
||||
|
||||
for check in checks:
|
||||
write_check_time(make_check_time_path(location_config, borg_repository_id, check))
|
||||
write_check_time(
|
||||
make_check_time_path(location_config, borg_repository_id, check, archives_check_id)
|
||||
)
|
||||
|
||||
if 'extract' in checks:
|
||||
extract.extract_last_archive_dry_run(
|
||||
storage_config, local_borg_version, repository_path, lock_wait, local_path, remote_path
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
repository_path,
|
||||
lock_wait,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
write_check_time(make_check_time_path(location_config, borg_repository_id, 'extract'))
|
||||
|
|
|
@ -11,6 +11,7 @@ def compact_segments(
|
|||
repository_path,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
progress=False,
|
||||
|
@ -29,6 +30,7 @@ def compact_segments(
|
|||
(local_path, 'compact')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--progress',) if progress else ())
|
||||
+ (('--cleanup-commits',) if cleanup_commits else ())
|
||||
|
|
|
@ -314,7 +314,7 @@ def check_all_source_directories_exist(source_directories):
|
|||
missing_directories = [
|
||||
source_directory
|
||||
for source_directory in source_directories
|
||||
if not os.path.exists(source_directory)
|
||||
if not all([os.path.exists(directory) for directory in expand_directory(source_directory)])
|
||||
]
|
||||
if missing_directories:
|
||||
raise ValueError(f"Source directories do not exist: {', '.join(missing_directories)}")
|
||||
|
@ -326,6 +326,7 @@ def create_archive(
|
|||
location_config,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
progress=False,
|
||||
|
@ -438,6 +439,7 @@ def create_archive(
|
|||
+ (('--files-cache', files_cache) if files_cache else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (
|
||||
('--list', '--filter', list_filter_flags)
|
||||
|
@ -509,7 +511,9 @@ def create_archive(
|
|||
)
|
||||
elif output_log_level is None:
|
||||
return execute_command_and_capture_output(
|
||||
create_command, working_directory=working_directory, extra_environment=borg_environment,
|
||||
create_command,
|
||||
working_directory=working_directory,
|
||||
extra_environment=borg_environment,
|
||||
)
|
||||
else:
|
||||
execute_command(
|
||||
|
|
|
@ -15,6 +15,7 @@ def export_tar_archive(
|
|||
destination_path,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
tar_filter=None,
|
||||
|
@ -38,6 +39,7 @@ def export_tar_archive(
|
|||
(local_path, 'export-tar')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--list',) if list_files else ())
|
||||
|
@ -45,7 +47,11 @@ def export_tar_archive(
|
|||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (('--tar-filter', tar_filter) if tar_filter else ())
|
||||
+ (('--strip-components', str(strip_components)) if strip_components else ())
|
||||
+ flags.make_repository_archive_flags(repository_path, archive, local_borg_version,)
|
||||
+ flags.make_repository_archive_flags(
|
||||
repository_path,
|
||||
archive,
|
||||
local_borg_version,
|
||||
)
|
||||
+ (destination_path,)
|
||||
+ (tuple(paths) if paths else ())
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
import borgmatic.config.validate
|
||||
from borgmatic.borg import environment, feature, flags, rlist
|
||||
from borgmatic.execute import DO_NOT_CAPTURE, execute_command
|
||||
|
||||
|
@ -11,6 +12,7 @@ logger = logging.getLogger(__name__)
|
|||
def extract_last_archive_dry_run(
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
repository_path,
|
||||
lock_wait=None,
|
||||
local_path='borg',
|
||||
|
@ -20,8 +22,6 @@ def extract_last_archive_dry_run(
|
|||
Perform an extraction dry-run of the most recent archive. If there are no archives, skip the
|
||||
dry-run.
|
||||
'''
|
||||
remote_path_flags = ('--remote-path', remote_path) if remote_path else ()
|
||||
lock_wait_flags = ('--lock-wait', str(lock_wait)) if lock_wait else ()
|
||||
verbosity_flags = ()
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
verbosity_flags = ('--debug', '--show-rc')
|
||||
|
@ -30,7 +30,13 @@ def extract_last_archive_dry_run(
|
|||
|
||||
try:
|
||||
last_archive_name = rlist.resolve_archive_name(
|
||||
repository_path, 'latest', storage_config, local_borg_version, local_path, remote_path
|
||||
repository_path,
|
||||
'latest',
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
except ValueError:
|
||||
logger.warning('No archives found. Skipping extract consistency check.')
|
||||
|
@ -40,8 +46,9 @@ def extract_last_archive_dry_run(
|
|||
borg_environment = environment.make_environment(storage_config)
|
||||
full_extract_command = (
|
||||
(local_path, 'extract', '--dry-run')
|
||||
+ remote_path_flags
|
||||
+ lock_wait_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 ())
|
||||
+ verbosity_flags
|
||||
+ list_flag
|
||||
+ flags.make_repository_archive_flags(
|
||||
|
@ -62,6 +69,7 @@ def extract_archive(
|
|||
location_config,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
destination_path=None,
|
||||
|
@ -71,9 +79,9 @@ def extract_archive(
|
|||
):
|
||||
'''
|
||||
Given a dry-run flag, a local or remote repository path, an archive name, zero or more paths to
|
||||
restore from the archive, the local Borg version string, location/storage configuration dicts,
|
||||
optional local and remote Borg paths, and an optional destination path to extract to, extract
|
||||
the archive into the current directory.
|
||||
restore from the archive, the local Borg version string, an argparse.Namespace of global
|
||||
arguments, location/storage configuration dicts, optional local and remote Borg paths, and an
|
||||
optional destination path to extract to, extract the archive into the current directory.
|
||||
|
||||
If extract to stdout is True, then start the extraction streaming to stdout, and return that
|
||||
extract process as an instance of subprocess.Popen.
|
||||
|
@ -101,6 +109,7 @@ def extract_archive(
|
|||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ numeric_ids_flags
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--list', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
|
@ -108,7 +117,13 @@ def extract_archive(
|
|||
+ (('--strip-components', str(strip_components)) if strip_components else ())
|
||||
+ (('--progress',) if progress else ())
|
||||
+ (('--stdout',) if extract_to_stdout else ())
|
||||
+ flags.make_repository_archive_flags(repository, archive, local_borg_version,)
|
||||
+ flags.make_repository_archive_flags(
|
||||
# Make the repository path absolute so the working directory changes below don't
|
||||
# prevent Borg from finding the repo.
|
||||
borgmatic.config.validate.normalize_repository_path(repository),
|
||||
archive,
|
||||
local_borg_version,
|
||||
)
|
||||
+ (tuple(paths) if paths else ())
|
||||
)
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from enum import Enum
|
||||
|
||||
from pkg_resources import parse_version
|
||||
from packaging.version import parse
|
||||
|
||||
|
||||
class Feature(Enum):
|
||||
|
@ -18,17 +18,17 @@ class Feature(Enum):
|
|||
|
||||
|
||||
FEATURE_TO_MINIMUM_BORG_VERSION = {
|
||||
Feature.COMPACT: parse_version('1.2.0a2'), # borg compact
|
||||
Feature.ATIME: parse_version('1.2.0a7'), # borg create --atime
|
||||
Feature.NOFLAGS: parse_version('1.2.0a8'), # borg create --noflags
|
||||
Feature.NUMERIC_IDS: parse_version('1.2.0b3'), # borg create/extract/mount --numeric-ids
|
||||
Feature.UPLOAD_RATELIMIT: parse_version('1.2.0b3'), # borg create --upload-ratelimit
|
||||
Feature.SEPARATE_REPOSITORY_ARCHIVE: parse_version('2.0.0a2'), # --repo with separate archive
|
||||
Feature.RCREATE: parse_version('2.0.0a2'), # borg rcreate
|
||||
Feature.RLIST: parse_version('2.0.0a2'), # borg rlist
|
||||
Feature.RINFO: parse_version('2.0.0a2'), # borg rinfo
|
||||
Feature.MATCH_ARCHIVES: parse_version('2.0.0b3'), # borg --match-archives
|
||||
Feature.EXCLUDED_FILES_MINUS: parse_version('2.0.0b5'), # --list --filter uses "-" for excludes
|
||||
Feature.COMPACT: parse('1.2.0a2'), # borg compact
|
||||
Feature.ATIME: parse('1.2.0a7'), # borg create --atime
|
||||
Feature.NOFLAGS: parse('1.2.0a8'), # borg create --noflags
|
||||
Feature.NUMERIC_IDS: parse('1.2.0b3'), # borg create/extract/mount --numeric-ids
|
||||
Feature.UPLOAD_RATELIMIT: parse('1.2.0b3'), # borg create --upload-ratelimit
|
||||
Feature.SEPARATE_REPOSITORY_ARCHIVE: parse('2.0.0a2'), # --repo with separate archive
|
||||
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.MATCH_ARCHIVES: parse('2.0.0b3'), # borg --match-archives
|
||||
Feature.EXCLUDED_FILES_MINUS: parse('2.0.0b5'), # --list --filter uses "-" for excludes
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,4 +37,4 @@ def available(feature, borg_version):
|
|||
Given a Borg Feature constant and a Borg version string, return whether that feature is
|
||||
available in that version of Borg.
|
||||
'''
|
||||
return FEATURE_TO_MINIMUM_BORG_VERSION[feature] <= parse_version(borg_version)
|
||||
return FEATURE_TO_MINIMUM_BORG_VERSION[feature] <= parse(borg_version)
|
||||
|
|
|
@ -12,13 +12,14 @@ def display_archives_info(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
info_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, and the
|
||||
arguments to the info action, display summary information for Borg archives in the repository or
|
||||
return JSON summary information.
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, global
|
||||
arguments as an argparse.Namespace, and the arguments to the info action, display summary
|
||||
information for Borg archives in the repository or return JSON summary information.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
@ -36,6 +37,7 @@ def display_archives_info(
|
|||
else ()
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ (
|
||||
(
|
||||
|
@ -62,7 +64,8 @@ def display_archives_info(
|
|||
|
||||
if info_arguments.json:
|
||||
return execute_command_and_capture_output(
|
||||
full_command, extra_environment=environment.make_environment(storage_config),
|
||||
full_command,
|
||||
extra_environment=environment.make_environment(storage_config),
|
||||
)
|
||||
else:
|
||||
execute_command(
|
||||
|
|
|
@ -25,6 +25,7 @@ def make_list_command(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
list_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
|
@ -48,6 +49,7 @@ def make_list_command(
|
|||
else ()
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ flags.make_flags_from_arguments(list_arguments, excludes=MAKE_FLAGS_EXCLUDES)
|
||||
+ (
|
||||
|
@ -90,14 +92,16 @@ def capture_archive_listing(
|
|||
archive,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
list_path=None,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, an archive name, a storage config dict, the local Borg
|
||||
version, the archive path in which to list files, and local and remote Borg paths, capture the
|
||||
output of listing that archive and return it as a list of file paths.
|
||||
version, global arguments as an argparse.Namespace, the archive path in which to list files, 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(storage_config)
|
||||
|
||||
|
@ -115,6 +119,7 @@ def capture_archive_listing(
|
|||
json=None,
|
||||
format='{path}{NL}', # noqa: FS003
|
||||
),
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
),
|
||||
|
@ -130,15 +135,17 @@ def list_archive(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
list_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, the
|
||||
arguments to the list action, 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 storage config 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.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
|
||||
|
@ -164,6 +171,7 @@ def list_archive(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -205,6 +213,7 @@ def list_archive(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
),
|
||||
|
@ -233,6 +242,7 @@ def list_archive(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
archive_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
) + make_find_paths(list_arguments.find_paths)
|
||||
|
|
|
@ -9,20 +9,18 @@ logger = logging.getLogger(__name__)
|
|||
def mount_archive(
|
||||
repository_path,
|
||||
archive,
|
||||
mount_point,
|
||||
paths,
|
||||
foreground,
|
||||
options,
|
||||
mount_arguments,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, an optional archive name, a filesystem mount point,
|
||||
zero or more paths to mount from the archive, extra Borg mount options, a storage configuration
|
||||
dict, the local Borg version, and optional local and remote Borg paths, mount the archive onto
|
||||
the mount point.
|
||||
dict, the local Borg version, global arguments as an argparse.Namespace instance, and optional
|
||||
local and remote Borg paths, mount the archive onto the mount point.
|
||||
'''
|
||||
umask = storage_config.get('umask', None)
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
@ -31,11 +29,15 @@ def mount_archive(
|
|||
(local_path, 'mount')
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--foreground',) if foreground else ())
|
||||
+ (('-o', options) if options else ())
|
||||
+ flags.make_flags_from_arguments(
|
||||
mount_arguments,
|
||||
excludes=('repository', 'archive', 'mount_point', 'paths', 'options'),
|
||||
)
|
||||
+ (('-o', mount_arguments.options) if mount_arguments.options else ())
|
||||
+ (
|
||||
(
|
||||
flags.make_repository_flags(repository_path, local_borg_version)
|
||||
|
@ -52,14 +54,14 @@ def mount_archive(
|
|||
else flags.make_repository_flags(repository_path, local_borg_version)
|
||||
)
|
||||
)
|
||||
+ (mount_point,)
|
||||
+ (tuple(paths) if paths else ())
|
||||
+ (mount_arguments.mount_point,)
|
||||
+ (tuple(mount_arguments.paths) if mount_arguments.paths else ())
|
||||
)
|
||||
|
||||
borg_environment = environment.make_environment(storage_config)
|
||||
|
||||
# Don't capture the output when foreground mode is used so that ctrl-C can work properly.
|
||||
if foreground:
|
||||
if mount_arguments.foreground:
|
||||
execute_command(
|
||||
full_command,
|
||||
output_file=DO_NOT_CAPTURE,
|
||||
|
|
|
@ -53,10 +53,10 @@ def prune_archives(
|
|||
storage_config,
|
||||
retention_config,
|
||||
local_borg_version,
|
||||
prune_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
stats=False,
|
||||
list_archives=False,
|
||||
):
|
||||
'''
|
||||
Given dry-run flag, a local or remote repository path, a storage config dict, and a
|
||||
|
@ -73,17 +73,22 @@ def prune_archives(
|
|||
+ make_prune_flags(storage_config, retention_config, local_borg_version)
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (('--umask', str(umask)) if umask else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--stats',) if stats and not dry_run else ())
|
||||
+ (('--stats',) if prune_arguments.stats and not dry_run else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--list',) if list_archives else ())
|
||||
+ flags.make_flags_from_arguments(
|
||||
prune_arguments,
|
||||
excludes=('repository', 'stats', 'list_archives'),
|
||||
)
|
||||
+ (('--list',) if prune_arguments.list_archives else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--dry-run',) if dry_run else ())
|
||||
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
)
|
||||
|
||||
if stats or list_archives:
|
||||
if prune_arguments.stats or prune_arguments.list_archives:
|
||||
output_log_level = logging.ANSWER
|
||||
else:
|
||||
output_log_level = logging.INFO
|
||||
|
|
|
@ -16,6 +16,7 @@ def create_repository(
|
|||
repository_path,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
encryption_mode,
|
||||
source_repository=None,
|
||||
copy_crypt_key=False,
|
||||
|
@ -37,6 +38,7 @@ def create_repository(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
argparse.Namespace(json=True),
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -46,6 +48,7 @@ def create_repository(
|
|||
if error.returncode != RINFO_REPOSITORY_NOT_FOUND_EXIT_CODE:
|
||||
raise
|
||||
|
||||
lock_wait = storage_config.get('lock_wait')
|
||||
extra_borg_options = storage_config.get('extra_borg_options', {}).get('rcreate', '')
|
||||
|
||||
rcreate_command = (
|
||||
|
@ -63,6 +66,8 @@ def create_repository(
|
|||
+ (('--make-parent-dirs',) if make_parent_dirs else ())
|
||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug',) if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ (('--log-json',) if global_arguments.log_json else ())
|
||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||
+ (('--remote-path', remote_path) if remote_path else ())
|
||||
+ (tuple(extra_borg_options.split(' ')) if extra_borg_options else ())
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
|
|
|
@ -12,13 +12,14 @@ def display_repository_info(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rinfo_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, and the
|
||||
arguments to the rinfo action, display summary information for the Borg repository or return
|
||||
JSON summary information.
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, the
|
||||
arguments to the rinfo action, and global arguments as an argparse.Namespace, display summary
|
||||
information for the Borg repository or return JSON summary information.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
@ -41,6 +42,7 @@ def display_repository_info(
|
|||
else ()
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ (('--json',) if rinfo_arguments.json else ())
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
|
@ -50,7 +52,8 @@ def display_repository_info(
|
|||
|
||||
if rinfo_arguments.json:
|
||||
return execute_command_and_capture_output(
|
||||
full_command, extra_environment=extra_environment,
|
||||
full_command,
|
||||
extra_environment=extra_environment,
|
||||
)
|
||||
else:
|
||||
execute_command(
|
||||
|
|
|
@ -12,35 +12,37 @@ def resolve_archive_name(
|
|||
archive,
|
||||
storage_config,
|
||||
local_borg_version,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, an archive name, a storage config dict, a local Borg
|
||||
path, and a remote Borg path, simply return the archive name. But if the archive name is
|
||||
"latest", then instead introspect the repository for the latest archive and return its name.
|
||||
Given a local or remote repository path, an archive name, a storage config dict, the local Borg
|
||||
version, global arguments as an argparse.Namespace, a local Borg path, and a remote Borg path,
|
||||
return the archive name. But if the archive name is "latest", then instead introspect the
|
||||
repository for the latest archive and return its name.
|
||||
|
||||
Raise ValueError if "latest" is given but there are no archives in the repository.
|
||||
'''
|
||||
if archive != 'latest':
|
||||
return archive
|
||||
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
full_command = (
|
||||
(
|
||||
local_path,
|
||||
'rlist' if feature.available(feature.Feature.RLIST, local_borg_version) else 'list',
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', storage_config.get('lock_wait'))
|
||||
+ flags.make_flags('last', 1)
|
||||
+ ('--short',)
|
||||
+ flags.make_repository_flags(repository_path, local_borg_version)
|
||||
)
|
||||
|
||||
output = execute_command_and_capture_output(
|
||||
full_command, extra_environment=environment.make_environment(storage_config),
|
||||
full_command,
|
||||
extra_environment=environment.make_environment(storage_config),
|
||||
)
|
||||
try:
|
||||
latest_archive = output.strip().splitlines()[-1]
|
||||
|
@ -60,16 +62,15 @@ def make_rlist_command(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, the
|
||||
arguments to the rlist action, and local and remote Borg paths, return a command as a tuple to
|
||||
list archives with a repository.
|
||||
arguments to the rlist action, global arguments as an argparse.Namespace instance, and local and
|
||||
remote Borg paths, return a command as a tuple to list archives with a repository.
|
||||
'''
|
||||
lock_wait = storage_config.get('lock_wait', None)
|
||||
|
||||
return (
|
||||
(
|
||||
local_path,
|
||||
|
@ -86,7 +87,8 @@ def make_rlist_command(
|
|||
else ()
|
||||
)
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('lock-wait', lock_wait)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', storage_config.get('lock_wait'))
|
||||
+ (
|
||||
(
|
||||
flags.make_flags('match-archives', f'sh:{rlist_arguments.prefix}*')
|
||||
|
@ -112,13 +114,15 @@ def list_repository(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a local or remote repository path, a storage config dict, the local Borg version, the
|
||||
arguments to the list action, and local and remote Borg paths, display the output of listing
|
||||
Borg archives in the given repository (or return JSON output).
|
||||
arguments to the list action, global arguments as an argparse.Namespace instance, and local and
|
||||
remote Borg paths, display the output of listing Borg archives in the given repository (or
|
||||
return JSON output).
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
borg_environment = environment.make_environment(storage_config)
|
||||
|
@ -128,6 +132,7 @@ def list_repository(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
rlist_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
|
|
@ -13,12 +13,14 @@ def transfer_archives(
|
|||
storage_config,
|
||||
local_borg_version,
|
||||
transfer_arguments,
|
||||
global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
):
|
||||
'''
|
||||
Given a dry-run flag, a local or remote repository path, a storage config dict, the local Borg
|
||||
version, and the arguments to the transfer action, transfer archives to the given repository.
|
||||
version, the arguments to the transfer action, and global arguments as an argparse.Namespace
|
||||
instance, transfer archives to the given repository.
|
||||
'''
|
||||
borgmatic.logger.add_custom_log_levels()
|
||||
|
||||
|
@ -27,6 +29,7 @@ def transfer_archives(
|
|||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
+ flags.make_flags('remote-path', remote_path)
|
||||
+ flags.make_flags('log-json', global_arguments.log_json)
|
||||
+ flags.make_flags('lock-wait', storage_config.get('lock_wait', None))
|
||||
+ (
|
||||
flags.make_flags_from_arguments(
|
||||
|
|
|
@ -19,7 +19,8 @@ def local_borg_version(storage_config, local_path='borg'):
|
|||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||
)
|
||||
output = execute_command_and_capture_output(
|
||||
full_command, extra_environment=environment.make_environment(storage_config),
|
||||
full_command,
|
||||
extra_environment=environment.make_environment(storage_config),
|
||||
)
|
||||
|
||||
try:
|
||||
|
|
|
@ -178,13 +178,20 @@ def make_parsers():
|
|||
help='Log verbose progress to monitoring integrations that support logging (from only errors to very verbose: -1, 0, 1, or 2)',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--log-file', type=str, help='Write log messages to this file instead of syslog',
|
||||
'--log-file',
|
||||
type=str,
|
||||
help='Write log messages to this file instead of syslog',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--log-file-format',
|
||||
type=str,
|
||||
help='Log format string used for log messages written to the log file',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--log-json',
|
||||
action='store_true',
|
||||
help='Write log messages and console output as one JSON object per log line instead of formatted text',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--override',
|
||||
metavar='SECTION.OPTION=VALUE',
|
||||
|
@ -205,6 +212,12 @@ def make_parsers():
|
|||
action='store_true',
|
||||
help='Show bash completion script and exit',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--fish-completion',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Show fish completion script and exit',
|
||||
)
|
||||
global_group.add_argument(
|
||||
'--version',
|
||||
dest='version',
|
||||
|
@ -246,7 +259,7 @@ def make_parsers():
|
|||
'--source-repository',
|
||||
'--other-repo',
|
||||
metavar='KEY_REPOSITORY',
|
||||
help='Path to an existing Borg repository whose key material should be reused (Borg 2.x+ only)',
|
||||
help='Path to an existing Borg repository whose key material should be reused [Borg 2.x+ only]',
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--repository',
|
||||
|
@ -255,13 +268,16 @@ def make_parsers():
|
|||
rcreate_group.add_argument(
|
||||
'--copy-crypt-key',
|
||||
action='store_true',
|
||||
help='Copy the crypt key used for authenticated encryption from the source repository, defaults to a new random key (Borg 2.x+ only)',
|
||||
help='Copy the crypt key used for authenticated encryption from the source repository, defaults to a new random key [Borg 2.x+ only]',
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--append-only', action='store_true', help='Create an append-only repository',
|
||||
'--append-only',
|
||||
action='store_true',
|
||||
help='Create an append-only repository',
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--storage-quota', help='Create a repository with a fixed storage quota',
|
||||
'--storage-quota',
|
||||
help='Create a repository with a fixed storage quota',
|
||||
)
|
||||
rcreate_group.add_argument(
|
||||
'--make-parent-dirs',
|
||||
|
@ -275,8 +291,8 @@ def make_parsers():
|
|||
transfer_parser = subparsers.add_parser(
|
||||
'transfer',
|
||||
aliases=SUBPARSER_ALIASES['transfer'],
|
||||
help='Transfer archives from one repository to another, optionally upgrading the transferred data (Borg 2.0+ only)',
|
||||
description='Transfer archives from one repository to another, optionally upgrading the transferred data (Borg 2.0+ only)',
|
||||
help='Transfer archives from one repository to another, optionally upgrading the transferred data [Borg 2.0+ only]',
|
||||
description='Transfer archives from one repository to another, optionally upgrading the transferred data [Borg 2.0+ only]',
|
||||
add_help=False,
|
||||
)
|
||||
transfer_group = transfer_parser.add_argument_group('transfer arguments')
|
||||
|
@ -321,6 +337,26 @@ def make_parsers():
|
|||
transfer_group.add_argument(
|
||||
'--last', metavar='N', help='Only transfer last N archives after other filters are applied'
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='Transfer archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='Transfer 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]',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='Transfer archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='Transfer archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
transfer_group.add_argument(
|
||||
'-h', '--help', action='help', help='Show this help message and exit'
|
||||
)
|
||||
|
@ -347,13 +383,33 @@ def make_parsers():
|
|||
prune_group.add_argument(
|
||||
'--list', dest='list_archives', action='store_true', help='List archives kept/pruned'
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='Prune archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='Prune 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]',
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='Prune archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
prune_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='Prune archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
prune_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
compact_parser = subparsers.add_parser(
|
||||
'compact',
|
||||
aliases=SUBPARSER_ALIASES['compact'],
|
||||
help='Compact segments to free space (Borg 1.2+, borgmatic 1.5.23+ only)',
|
||||
description='Compact segments to free space (Borg 1.2+, borgmatic 1.5.23+ only)',
|
||||
help='Compact segments to free space [Borg 1.2+, borgmatic 1.5.23+ only]',
|
||||
description='Compact segments to free space [Borg 1.2+, borgmatic 1.5.23+ only]',
|
||||
add_help=False,
|
||||
)
|
||||
compact_group = compact_parser.add_argument_group('compact arguments')
|
||||
|
@ -373,7 +429,7 @@ def make_parsers():
|
|||
dest='cleanup_commits',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Cleanup commit-only 17-byte segment files left behind by Borg 1.1 (flag in Borg 1.2 only)',
|
||||
help='Cleanup commit-only 17-byte segment files left behind by Borg 1.1 [flag in Borg 1.2 only]',
|
||||
)
|
||||
compact_group.add_argument(
|
||||
'--threshold',
|
||||
|
@ -587,6 +643,34 @@ def make_parsers():
|
|||
action='store_true',
|
||||
help='Stay in foreground until ctrl-C is pressed',
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--first',
|
||||
metavar='N',
|
||||
help='Mount first N archives after other filters are applied',
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--last', metavar='N', help='Mount last N archives after other filters are applied'
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='Mount archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='Mount 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]',
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='Mount archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
mount_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='Mount archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
mount_group.add_argument('--options', dest='options', help='Extra Borg mount options')
|
||||
mount_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
|
@ -629,6 +713,13 @@ def make_parsers():
|
|||
dest='databases',
|
||||
help="Names of databases to restore from archive, defaults to all databases. Note that any databases to restore must be defined in borgmatic's configuration",
|
||||
)
|
||||
restore_group.add_argument(
|
||||
'--schema',
|
||||
metavar='NAME',
|
||||
nargs='+',
|
||||
dest='schemas',
|
||||
help='Names of schemas to restore from the database, defaults to all schemas. Schemas are only supported for PostgreSQL and MongoDB databases',
|
||||
)
|
||||
restore_group.add_argument(
|
||||
'-h', '--help', action='help', help='Show this help message and exit'
|
||||
)
|
||||
|
@ -642,7 +733,8 @@ 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',
|
||||
'--repository',
|
||||
help='Path of repository to list, defaults to the configured repositories',
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--short', default=False, action='store_true', help='Output only archive names'
|
||||
|
@ -670,6 +762,26 @@ def make_parsers():
|
|||
rlist_group.add_argument(
|
||||
'--last', metavar='N', help='List last N archives after other filters are applied'
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='List archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='List 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]',
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='List archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
rlist_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='List archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
rlist_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
list_parser = subparsers.add_parser(
|
||||
|
@ -801,6 +913,26 @@ def make_parsers():
|
|||
info_group.add_argument(
|
||||
'--last', metavar='N', help='Show info for last N archives after other filters are applied'
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--oldest',
|
||||
metavar='TIMESPAN',
|
||||
help='Show info for archives within a specified time range starting from the timestamp of the oldest archive (e.g. 7d or 12m) [Borg 2.x+ only]',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--newest',
|
||||
metavar='TIMESPAN',
|
||||
help='Show info for 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]',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--older',
|
||||
metavar='TIMESPAN',
|
||||
help='Show info for archives that are older than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
info_group.add_argument(
|
||||
'--newer',
|
||||
metavar='TIMESPAN',
|
||||
help='Show info for archives that are newer than the specified time range (e.g. 7d or 12m) from the current time [Borg 2.x+ only]',
|
||||
)
|
||||
info_group.add_argument('-h', '--help', action='help', help='Show this help message and exit')
|
||||
|
||||
break_lock_parser = subparsers.add_parser(
|
||||
|
@ -865,6 +997,10 @@ def parse_arguments(*unparsed_arguments):
|
|||
raise ValueError(
|
||||
'With the create action, only one of --list (--files) and --progress flags can be used.'
|
||||
)
|
||||
if 'create' in arguments and arguments['create'].list_files and arguments['create'].json:
|
||||
raise ValueError(
|
||||
'With the create action, only one of --list (--files) and --json flags can be used.'
|
||||
)
|
||||
|
||||
if (
|
||||
('list' in arguments and 'rinfo' in arguments and arguments['list'].json)
|
||||
|
|
|
@ -8,7 +8,11 @@ from queue import Queue
|
|||
from subprocess import CalledProcessError
|
||||
|
||||
import colorama
|
||||
import pkg_resources
|
||||
|
||||
try:
|
||||
import importlib_metadata
|
||||
except ModuleNotFoundError: # pragma: nocover
|
||||
import importlib.metadata as importlib_metadata
|
||||
|
||||
import borgmatic.actions.borg
|
||||
import borgmatic.actions.break_lock
|
||||
|
@ -103,14 +107,20 @@ def run_configuration(config_filename, config, arguments):
|
|||
if not encountered_error:
|
||||
repo_queue = Queue()
|
||||
for repo in location['repositories']:
|
||||
repo_queue.put((repo, 0),)
|
||||
repo_queue.put(
|
||||
(repo, 0),
|
||||
)
|
||||
|
||||
while not repo_queue.empty():
|
||||
repository, retry_num = repo_queue.get()
|
||||
logger.debug(f'{repository["path"]}: Running actions for repository')
|
||||
logger.debug(
|
||||
f'{repository.get("label", repository["path"])}: Running actions for repository'
|
||||
)
|
||||
timeout = retry_num * retry_wait
|
||||
if timeout:
|
||||
logger.warning(f'{config_filename}: Sleeping {timeout}s before next retry')
|
||||
logger.warning(
|
||||
f'{repository.get("label", repository["path"])}: Sleeping {timeout}s before next retry'
|
||||
)
|
||||
time.sleep(timeout)
|
||||
try:
|
||||
yield from run_actions(
|
||||
|
@ -128,17 +138,19 @@ def run_configuration(config_filename, config, arguments):
|
|||
)
|
||||
except (OSError, CalledProcessError, ValueError) as error:
|
||||
if retry_num < retries:
|
||||
repo_queue.put((repository, retry_num + 1),)
|
||||
repo_queue.put(
|
||||
(repository, retry_num + 1),
|
||||
)
|
||||
tuple( # Consume the generator so as to trigger logging.
|
||||
log_error_records(
|
||||
f'{repository["path"]}: Error running actions for repository',
|
||||
f'{repository.get("label", repository["path"])}: Error running actions for repository',
|
||||
error,
|
||||
levelno=logging.WARNING,
|
||||
log_command_error_output=True,
|
||||
)
|
||||
)
|
||||
logger.warning(
|
||||
f'{config_filename}: Retrying... attempt {retry_num + 1}/{retries}'
|
||||
f'{repository.get("label", repository["path"])}: Retrying... attempt {retry_num + 1}/{retries}'
|
||||
)
|
||||
continue
|
||||
|
||||
|
@ -146,7 +158,8 @@ def run_configuration(config_filename, config, arguments):
|
|||
return
|
||||
|
||||
yield from log_error_records(
|
||||
f'{repository["path"]}: Error running actions for repository', error
|
||||
f'{repository.get("label", repository["path"])}: Error running actions for repository',
|
||||
error,
|
||||
)
|
||||
encountered_error = error
|
||||
error_repository = repository['path']
|
||||
|
@ -279,7 +292,7 @@ def run_actions(
|
|||
**hook_context,
|
||||
)
|
||||
|
||||
for (action_name, action_arguments) in arguments.items():
|
||||
for action_name, action_arguments in arguments.items():
|
||||
if action_name == 'rcreate':
|
||||
borgmatic.actions.rcreate.run_rcreate(
|
||||
repository,
|
||||
|
@ -390,7 +403,8 @@ def run_actions(
|
|||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
arguments['mount'],
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
@ -408,32 +422,63 @@ def run_actions(
|
|||
)
|
||||
elif action_name == 'rlist':
|
||||
yield from borgmatic.actions.rlist.run_rlist(
|
||||
repository, storage, local_borg_version, action_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'list':
|
||||
yield from borgmatic.actions.list.run_list(
|
||||
repository, storage, local_borg_version, action_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'rinfo':
|
||||
yield from borgmatic.actions.rinfo.run_rinfo(
|
||||
repository, storage, local_borg_version, action_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'info':
|
||||
yield from borgmatic.actions.info.run_info(
|
||||
repository, storage, local_borg_version, action_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'break-lock':
|
||||
borgmatic.actions.break_lock.run_break_lock(
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
arguments['break-lock'],
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
elif action_name == 'borg':
|
||||
borgmatic.actions.borg.run_borg(
|
||||
repository, storage, local_borg_version, action_arguments, local_path, remote_path,
|
||||
repository,
|
||||
storage,
|
||||
local_borg_version,
|
||||
action_arguments,
|
||||
global_arguments,
|
||||
local_path,
|
||||
remote_path,
|
||||
)
|
||||
|
||||
command.execute_hook(
|
||||
|
@ -626,7 +671,8 @@ def collect_configuration_run_summary_logs(configs, arguments):
|
|||
logger.info(f"Unmounting mount point {arguments['umount'].mount_point}")
|
||||
try:
|
||||
borg_umount.unmount_archive(
|
||||
mount_point=arguments['umount'].mount_point, local_path=get_local_path(configs),
|
||||
mount_point=arguments['umount'].mount_point,
|
||||
local_path=get_local_path(configs),
|
||||
)
|
||||
except (CalledProcessError, OSError) as error:
|
||||
yield from log_error_records('Error unmounting mount point', error)
|
||||
|
@ -676,11 +722,14 @@ def main(): # pragma: no cover
|
|||
|
||||
global_arguments = arguments['global']
|
||||
if global_arguments.version:
|
||||
print(pkg_resources.require('borgmatic')[0].version)
|
||||
print(importlib_metadata.version('borgmatic'))
|
||||
sys.exit(0)
|
||||
if global_arguments.bash_completion:
|
||||
print(borgmatic.commands.completion.bash_completion())
|
||||
sys.exit(0)
|
||||
if global_arguments.fish_completion:
|
||||
print(borgmatic.commands.completion.fish_completion())
|
||||
sys.exit(0)
|
||||
|
||||
config_filenames = tuple(collect.collect_config_filenames(global_arguments.config_paths))
|
||||
configs, parse_logs = load_configurations(
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
import shlex
|
||||
from argparse import Action
|
||||
from textwrap import dedent
|
||||
|
||||
from borgmatic.commands import arguments
|
||||
|
||||
UPGRADE_MESSAGE = '''
|
||||
Your bash completions script is from a different version of borgmatic than is
|
||||
|
||||
def upgrade_message(language: str, upgrade_command: str, completion_file: str):
|
||||
return f'''
|
||||
Your {language} completions script is from a different version of borgmatic than is
|
||||
currently installed. Please upgrade your script so your completions match the
|
||||
command-line flags in your installed borgmatic! Try this to upgrade:
|
||||
|
||||
sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"
|
||||
source $BASH_SOURCE
|
||||
{upgrade_command}
|
||||
source {completion_file}
|
||||
'''
|
||||
|
||||
|
||||
|
@ -34,7 +40,11 @@ def bash_completion():
|
|||
' local this_script="$(cat "$BASH_SOURCE" 2> /dev/null)"',
|
||||
' local installed_script="$(borgmatic --bash-completion 2> /dev/null)"',
|
||||
' if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ];'
|
||||
f' then cat << EOF\n{UPGRADE_MESSAGE}\nEOF',
|
||||
f''' then cat << EOF\n{upgrade_message(
|
||||
'bash',
|
||||
'sudo sh -c "borgmatic --bash-completion > $BASH_SOURCE"',
|
||||
'$BASH_SOURCE',
|
||||
)}\nEOF''',
|
||||
' fi',
|
||||
'}',
|
||||
'complete_borgmatic() {',
|
||||
|
@ -55,3 +65,172 @@ def bash_completion():
|
|||
'\ncomplete -o bashdefault -o default -F complete_borgmatic borgmatic',
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# fish section
|
||||
|
||||
|
||||
def has_file_options(action: Action):
|
||||
'''
|
||||
Given an argparse.Action instance, return True if it takes a file argument.
|
||||
'''
|
||||
return action.metavar in (
|
||||
'FILENAME',
|
||||
'PATH',
|
||||
) or action.dest in ('config_paths',)
|
||||
|
||||
|
||||
def has_choice_options(action: Action):
|
||||
'''
|
||||
Given an argparse.Action instance, return True if it takes one of a predefined set of arguments.
|
||||
'''
|
||||
return action.choices is not None
|
||||
|
||||
|
||||
def has_unknown_required_param_options(action: Action):
|
||||
'''
|
||||
A catch-all for options that take a required parameter, but we don't know what the parameter is.
|
||||
This should be used last. These are actions that take something like a glob, a list of numbers, or a string.
|
||||
|
||||
Actions that match this pattern should not show the normal arguments, because those are unlikely to be valid.
|
||||
'''
|
||||
return (
|
||||
action.required is True
|
||||
or action.nargs
|
||||
in (
|
||||
'+',
|
||||
'*',
|
||||
)
|
||||
or action.metavar in ('PATTERN', 'KEYS', 'N')
|
||||
or (action.type is not None and action.default is None)
|
||||
)
|
||||
|
||||
|
||||
def has_exact_options(action: Action):
|
||||
return (
|
||||
has_file_options(action)
|
||||
or has_choice_options(action)
|
||||
or has_unknown_required_param_options(action)
|
||||
)
|
||||
|
||||
|
||||
def exact_options_completion(action: Action):
|
||||
'''
|
||||
Given an argparse.Action instance, return a completion invocation that forces file completions, options completion,
|
||||
or just that some value follow the action, if the action takes such an argument and was the last action on the
|
||||
command line prior to the cursor.
|
||||
|
||||
Otherwise, return an empty string.
|
||||
'''
|
||||
|
||||
if not has_exact_options(action):
|
||||
return ''
|
||||
|
||||
args = ' '.join(action.option_strings)
|
||||
|
||||
if has_file_options(action):
|
||||
return f'''\ncomplete -c borgmatic -Fr -n "__borgmatic_current_arg {args}"'''
|
||||
|
||||
if has_choice_options(action):
|
||||
return f'''\ncomplete -c borgmatic -f -a '{' '.join(map(str, action.choices))}' -n "__borgmatic_current_arg {args}"'''
|
||||
|
||||
if has_unknown_required_param_options(action):
|
||||
return f'''\ncomplete -c borgmatic -x -n "__borgmatic_current_arg {args}"'''
|
||||
|
||||
raise ValueError(
|
||||
f'Unexpected action: {action} passes has_exact_options but has no choices produced'
|
||||
)
|
||||
|
||||
|
||||
def dedent_strip_as_tuple(string: str):
|
||||
'''
|
||||
Dedent a string, then strip it to avoid requiring your first line to have content, then return a tuple of the string.
|
||||
Makes it easier to write multiline strings for completions when you join them with a tuple.
|
||||
'''
|
||||
return (dedent(string).strip('\n'),)
|
||||
|
||||
|
||||
def fish_completion():
|
||||
'''
|
||||
Return a fish completion script for the borgmatic command. Produce this by introspecting
|
||||
borgmatic's command-line argument parsers.
|
||||
'''
|
||||
top_level_parser, subparsers = arguments.make_parsers()
|
||||
|
||||
all_subparsers = ' '.join(action for action in subparsers.choices.keys())
|
||||
|
||||
exact_option_args = tuple(
|
||||
' '.join(action.option_strings)
|
||||
for subparser in subparsers.choices.values()
|
||||
for action in subparser._actions
|
||||
if has_exact_options(action)
|
||||
) + tuple(
|
||||
' '.join(action.option_strings)
|
||||
for action in top_level_parser._actions
|
||||
if len(action.option_strings) > 0
|
||||
if has_exact_options(action)
|
||||
)
|
||||
|
||||
# Avert your eyes.
|
||||
return '\n'.join(
|
||||
dedent_strip_as_tuple(
|
||||
f'''
|
||||
function __borgmatic_check_version
|
||||
set -fx this_filename (status current-filename)
|
||||
fish -c '
|
||||
if test -f "$this_filename"
|
||||
set this_script (cat $this_filename 2> /dev/null)
|
||||
set installed_script (borgmatic --fish-completion 2> /dev/null)
|
||||
if [ "$this_script" != "$installed_script" ] && [ "$installed_script" != "" ]
|
||||
echo "{upgrade_message(
|
||||
'fish',
|
||||
'borgmatic --fish-completion | sudo tee $this_filename',
|
||||
'$this_filename',
|
||||
)}"
|
||||
end
|
||||
end
|
||||
' &
|
||||
end
|
||||
__borgmatic_check_version
|
||||
|
||||
function __borgmatic_current_arg --description 'Check if any of the given arguments are the last on the command line before the cursor'
|
||||
set -l all_args (commandline -poc)
|
||||
# premature optimization to avoid iterating all args if there aren't enough
|
||||
# to have a last arg beyond borgmatic
|
||||
if [ (count $all_args) -lt 2 ]
|
||||
return 1
|
||||
end
|
||||
for arg in $argv
|
||||
if [ "$arg" = "$all_args[-1]" ]
|
||||
return 0
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
set --local subparser_condition "not __fish_seen_subcommand_from {all_subparsers}"
|
||||
set --local exact_option_condition "not __borgmatic_current_arg {' '.join(exact_option_args)}"
|
||||
'''
|
||||
)
|
||||
+ ('\n# subparser completions',)
|
||||
+ tuple(
|
||||
f'''complete -c borgmatic -f -n "$subparser_condition" -n "$exact_option_condition" -a '{action_name}' -d {shlex.quote(subparser.description)}'''
|
||||
for action_name, subparser in subparsers.choices.items()
|
||||
)
|
||||
+ ('\n# global flags',)
|
||||
+ tuple(
|
||||
# -n is checked in order, so put faster / more likely to be true checks first
|
||||
f'''complete -c borgmatic -f -n "$exact_option_condition" -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)}{exact_options_completion(action)}'''
|
||||
for action in top_level_parser._actions
|
||||
# ignore the noargs action, as this is an impossible completion for fish
|
||||
if len(action.option_strings) > 0
|
||||
if 'Deprecated' not in action.help
|
||||
)
|
||||
+ ('\n# subparser flags',)
|
||||
+ tuple(
|
||||
f'''complete -c borgmatic -f -n "$exact_option_condition" -a '{' '.join(action.option_strings)}' -d {shlex.quote(action.help)} -n "__fish_seen_subcommand_from {action_name}"{exact_options_completion(action)}'''
|
||||
for action_name, subparser in subparsers.choices.items()
|
||||
for action in subparser._actions
|
||||
if 'Deprecated' not in action.help
|
||||
)
|
||||
)
|
||||
|
|
|
@ -260,7 +260,7 @@ def merge_source_configuration_into_destination(destination_config, source_confi
|
|||
)
|
||||
continue
|
||||
|
||||
# This is some sort of scalar. Simply set it into the destination.
|
||||
# This is some sort of scalar. Set it into the destination.
|
||||
destination_config[field_name] = source_config[field_name]
|
||||
|
||||
return destination_config
|
||||
|
|
|
@ -38,9 +38,9 @@ def include_configuration(loader, filename_node, include_directory):
|
|||
return load_configuration(include_filename)
|
||||
|
||||
|
||||
def retain_node_error(loader, node):
|
||||
def raise_retain_node_error(loader, node):
|
||||
'''
|
||||
Given a ruamel.yaml.loader.Loader and a YAML node, raise an error.
|
||||
Given a ruamel.yaml.loader.Loader and a YAML node, raise an error about "!retain" usage.
|
||||
|
||||
Raise ValueError if a mapping or sequence node is given, as that indicates that "!retain" was
|
||||
used in a configuration file without a merge. In configuration files with a merge, mapping and
|
||||
|
@ -56,6 +56,19 @@ def retain_node_error(loader, node):
|
|||
raise ValueError('The !retain tag may only be used on a YAML mapping or sequence.')
|
||||
|
||||
|
||||
def raise_omit_node_error(loader, node):
|
||||
'''
|
||||
Given a ruamel.yaml.loader.Loader and a YAML node, raise an error about "!omit" usage.
|
||||
|
||||
Raise ValueError unconditionally, as an "!omit" node here indicates it was used in a
|
||||
configuration file without a merge. In configuration files with a merge, nodes with "!omit"
|
||||
tags are handled by deep_merge_nodes() below.
|
||||
'''
|
||||
raise ValueError(
|
||||
'The !omit tag may only be used on a scalar (e.g., string) list element within a configuration file containing a merged !include tag.'
|
||||
)
|
||||
|
||||
|
||||
class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||
'''
|
||||
A YAML "constructor" (a ruamel.yaml concept) that supports a custom "!include" tag for including
|
||||
|
@ -68,7 +81,8 @@ class Include_constructor(ruamel.yaml.SafeConstructor):
|
|||
'!include',
|
||||
functools.partial(include_configuration, include_directory=include_directory),
|
||||
)
|
||||
self.add_constructor('!retain', retain_node_error)
|
||||
self.add_constructor('!retain', raise_retain_node_error)
|
||||
self.add_constructor('!omit', raise_omit_node_error)
|
||||
|
||||
def flatten_mapping(self, node):
|
||||
'''
|
||||
|
@ -107,6 +121,7 @@ def load_configuration(filename):
|
|||
Raise ruamel.yaml.error.YAMLError if something goes wrong parsing the YAML, or RecursionError
|
||||
if there are too many recursive includes.
|
||||
'''
|
||||
|
||||
# Use an embedded derived class for the include constructor so as to capture the filename
|
||||
# value. (functools.partial doesn't work for this use case because yaml.Constructor has to be
|
||||
# an actual class.)
|
||||
|
@ -134,6 +149,16 @@ def load_configuration(filename):
|
|||
return config
|
||||
|
||||
|
||||
def filter_omitted_nodes(nodes):
|
||||
'''
|
||||
Given a list of nodes, return a filtered list omitting any nodes with an "!omit" tag or with a
|
||||
value matching such nodes.
|
||||
'''
|
||||
omitted_values = tuple(node.value for node in nodes if node.tag == '!omit')
|
||||
|
||||
return [node for node in nodes if node.value not in omitted_values]
|
||||
|
||||
|
||||
DELETED_NODE = object()
|
||||
|
||||
|
||||
|
@ -247,7 +272,7 @@ def deep_merge_nodes(nodes):
|
|||
b_key,
|
||||
ruamel.yaml.nodes.SequenceNode(
|
||||
tag=b_value.tag,
|
||||
value=a_value.value + b_value.value,
|
||||
value=filter_omitted_nodes(a_value.value + b_value.value),
|
||||
start_mark=b_value.start_mark,
|
||||
end_mark=b_value.end_mark,
|
||||
flow_style=b_value.flow_style,
|
||||
|
|
|
@ -81,7 +81,10 @@ def normalize(config_filename, config):
|
|||
repository_path.partition('file://')[-1]
|
||||
)
|
||||
config['location']['repositories'].append(
|
||||
dict(repository_dict, path=updated_repository_path,)
|
||||
dict(
|
||||
repository_dict,
|
||||
path=updated_repository_path,
|
||||
)
|
||||
)
|
||||
elif repository_path.startswith('ssh://'):
|
||||
config['location']['repositories'].append(repository_dict)
|
||||
|
@ -97,7 +100,10 @@ def normalize(config_filename, config):
|
|||
)
|
||||
)
|
||||
config['location']['repositories'].append(
|
||||
dict(repository_dict, path=rewritten_repository_path,)
|
||||
dict(
|
||||
repository_dict,
|
||||
path=rewritten_repository_path,
|
||||
)
|
||||
)
|
||||
else:
|
||||
config['location']['repositories'].append(repository_dict)
|
||||
|
|
|
@ -57,7 +57,12 @@ def parse_overrides(raw_overrides):
|
|||
for raw_override in raw_overrides:
|
||||
try:
|
||||
raw_keys, value = raw_override.split('=', 1)
|
||||
parsed_overrides.append((tuple(raw_keys.split('.')), convert_value_type(value),))
|
||||
parsed_overrides.append(
|
||||
(
|
||||
tuple(raw_keys.split('.')),
|
||||
convert_value_type(value),
|
||||
)
|
||||
)
|
||||
except ValueError:
|
||||
raise ValueError(
|
||||
f"Invalid override '{raw_override}'. Make sure you use the form: SECTION.OPTION=VALUE"
|
||||
|
@ -75,5 +80,5 @@ def apply_overrides(config, raw_overrides):
|
|||
'''
|
||||
overrides = parse_overrides(raw_overrides)
|
||||
|
||||
for (keys, value) in overrides:
|
||||
for keys, value in overrides:
|
||||
set_values(config, keys, value)
|
||||
|
|
|
@ -30,8 +30,8 @@ properties:
|
|||
items:
|
||||
type: string
|
||||
description: |
|
||||
List of source directories to backup. Globs and tildes are
|
||||
expanded. Do not backslash spaces in path names.
|
||||
List of source directories and files to backup. Globs and
|
||||
tildes are expanded. Do not backslash spaces in path names.
|
||||
example:
|
||||
- /home
|
||||
- /etc
|
||||
|
@ -60,7 +60,7 @@ properties:
|
|||
or port. If systemd service is used, then add local
|
||||
repository paths in the systemd service file to the
|
||||
ReadWritePaths list. Prior to borgmatic 1.7.10, repositories
|
||||
was just a list of plain path strings.
|
||||
was a list of plain path strings.
|
||||
example:
|
||||
- path: ssh://user@backupserver/./sourcehostname.borg
|
||||
label: backupserver
|
||||
|
@ -836,25 +836,25 @@ properties:
|
|||
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
|
||||
docker container). Defaults to "pg_dump" for
|
||||
single database dump or "pg_dumpall" to dump
|
||||
all databases.
|
||||
container). 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
|
||||
description: |
|
||||
Command to use instead of "pg_restore". This
|
||||
can be used to run a specific pg_restore
|
||||
version (e.g., one inside a running docker
|
||||
container). Defaults to "pg_restore".
|
||||
version (e.g., one inside a running container).
|
||||
Defaults to "pg_restore".
|
||||
example: docker exec my_pg_container pg_restore
|
||||
psql_command:
|
||||
type: string
|
||||
description: |
|
||||
Command to use instead of "psql". This can be
|
||||
used to run a specific psql version (e.g.,
|
||||
one inside a running docker container).
|
||||
Defaults to "psql".
|
||||
one inside a running container). Defaults to
|
||||
"psql".
|
||||
example: docker exec my_pg_container psql
|
||||
options:
|
||||
type: string
|
||||
|
@ -1216,7 +1216,7 @@ properties:
|
|||
type: string
|
||||
description: |
|
||||
Healthchecks ping URL or UUID to notify when a
|
||||
backup begins, ends, errors or just to send logs.
|
||||
backup begins, ends, errors, or to send only logs.
|
||||
example: https://hc-ping.com/your-uuid-here
|
||||
verify_tls:
|
||||
type: boolean
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
import os
|
||||
|
||||
import jsonschema
|
||||
import pkg_resources
|
||||
import ruamel.yaml
|
||||
|
||||
try:
|
||||
import importlib_metadata
|
||||
except ModuleNotFoundError: # pragma: nocover
|
||||
import importlib.metadata as importlib_metadata
|
||||
|
||||
import borgmatic.config
|
||||
from borgmatic.config import environment, load, normalize, override
|
||||
|
||||
|
||||
|
@ -11,8 +16,19 @@ def schema_filename():
|
|||
'''
|
||||
Path to the installed YAML configuration schema file, used to validate and parse the
|
||||
configuration.
|
||||
|
||||
Raise FileNotFoundError when the schema path does not exist.
|
||||
'''
|
||||
return pkg_resources.resource_filename('borgmatic', 'config/schema.yaml')
|
||||
try:
|
||||
return next(
|
||||
str(path.locate())
|
||||
for path in importlib_metadata.files('borgmatic')
|
||||
if path.match('config/schema.yaml')
|
||||
)
|
||||
except StopIteration:
|
||||
# If the schema wasn't found in the package's files, this is probably a pip editable
|
||||
# install, so try a different approach to get the schema.
|
||||
return os.path.join(os.path.dirname(borgmatic.config.__file__), 'schema.yaml')
|
||||
|
||||
|
||||
def format_json_error_path_element(path_element):
|
||||
|
|
|
@ -236,7 +236,11 @@ def execute_command(
|
|||
|
||||
|
||||
def execute_command_and_capture_output(
|
||||
full_command, capture_stderr=False, shell=False, extra_environment=None, working_directory=None,
|
||||
full_command,
|
||||
capture_stderr=False,
|
||||
shell=False,
|
||||
extra_environment=None,
|
||||
working_directory=None,
|
||||
):
|
||||
'''
|
||||
Execute the given command (a sequence of command/argument strings), capturing and returning its
|
||||
|
|
|
@ -161,4 +161,7 @@ def build_restore_command(extract_process, database, dump_filename):
|
|||
command.extend(('--authenticationDatabase', database['authentication_database']))
|
||||
if 'restore_options' in database:
|
||||
command.extend(database['restore_options'].split(' '))
|
||||
if database['schemas']:
|
||||
for schema in database['schemas']:
|
||||
command.extend(('--nsInclude', schema))
|
||||
return command
|
||||
|
|
|
@ -100,7 +100,9 @@ def execute_dump_command(
|
|||
dump.create_named_pipe_for_dump(dump_filename)
|
||||
|
||||
return execute_command(
|
||||
dump_command, extra_environment=extra_environment, run_to_completion=False,
|
||||
dump_command,
|
||||
extra_environment=extra_environment,
|
||||
run_to_completion=False,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
import csv
|
||||
import itertools
|
||||
import logging
|
||||
import os
|
||||
import shlex
|
||||
|
||||
from borgmatic.execute import (
|
||||
execute_command,
|
||||
|
@ -59,8 +61,10 @@ def database_names_to_dump(database, extra_environment, log_prefix, dry_run):
|
|||
if dry_run:
|
||||
return ()
|
||||
|
||||
psql_command = shlex.split(database.get('psql_command') or 'psql')
|
||||
list_command = (
|
||||
('psql', '--list', '--no-password', '--csv', '--tuples-only')
|
||||
tuple(psql_command)
|
||||
+ ('--list', '--no-password', '--no-psqlrc', '--csv', '--tuples-only')
|
||||
+ (('--host', database['hostname']) if 'hostname' in database else ())
|
||||
+ (('--port', str(database['port'])) if 'port' in database else ())
|
||||
+ (('--username', database['username']) if 'username' in database else ())
|
||||
|
@ -122,7 +126,12 @@ def dump_databases(databases, log_prefix, location_config, dry_run):
|
|||
continue
|
||||
|
||||
command = (
|
||||
(dump_command, '--no-password', '--clean', '--if-exists',)
|
||||
(
|
||||
dump_command,
|
||||
'--no-password',
|
||||
'--clean',
|
||||
'--if-exists',
|
||||
)
|
||||
+ (('--host', database['hostname']) if 'hostname' in database else ())
|
||||
+ (('--port', str(database['port'])) if 'port' in database else ())
|
||||
+ (('--username', database['username']) if 'username' in database else ())
|
||||
|
@ -145,7 +154,9 @@ def dump_databases(databases, log_prefix, location_config, dry_run):
|
|||
if dump_format == 'directory':
|
||||
dump.create_parent_directory_for_dump(dump_filename)
|
||||
execute_command(
|
||||
command, shell=True, extra_environment=extra_environment,
|
||||
command,
|
||||
shell=True,
|
||||
extra_environment=extra_environment,
|
||||
)
|
||||
else:
|
||||
dump.create_named_pipe_for_dump(dump_filename)
|
||||
|
@ -202,9 +213,10 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
|||
dump_filename = dump.make_database_dump_filename(
|
||||
make_dump_path(location_config), database['name'], database.get('hostname')
|
||||
)
|
||||
psql_command = database.get('psql_command') or 'psql'
|
||||
psql_command = shlex.split(database.get('psql_command') or 'psql')
|
||||
analyze_command = (
|
||||
(psql_command, '--no-password', '--quiet')
|
||||
tuple(psql_command)
|
||||
+ ('--no-password', '--no-psqlrc', '--quiet')
|
||||
+ (('--host', database['hostname']) if 'hostname' in database else ())
|
||||
+ (('--port', str(database['port'])) if 'port' in database else ())
|
||||
+ (('--username', database['username']) if 'username' in database else ())
|
||||
|
@ -212,20 +224,25 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
|||
+ (tuple(database['analyze_options'].split(' ')) if 'analyze_options' in database else ())
|
||||
+ ('--command', 'ANALYZE')
|
||||
)
|
||||
pg_restore_command = database.get('pg_restore_command') or 'pg_restore'
|
||||
use_psql_command = all_databases or database.get('format') == 'plain'
|
||||
pg_restore_command = shlex.split(database.get('pg_restore_command') or 'pg_restore')
|
||||
restore_command = (
|
||||
(psql_command if all_databases else pg_restore_command, '--no-password')
|
||||
+ (
|
||||
('--if-exists', '--exit-on-error', '--clean', '--dbname', database['name'])
|
||||
if not all_databases
|
||||
else ()
|
||||
)
|
||||
tuple(psql_command if use_psql_command else pg_restore_command)
|
||||
+ ('--no-password',)
|
||||
+ (('--no-psqlrc',) if use_psql_command else ('--if-exists', '--exit-on-error', '--clean'))
|
||||
+ (('--dbname', database['name']) if not all_databases else ())
|
||||
+ (('--host', database['hostname']) if 'hostname' in database else ())
|
||||
+ (('--port', str(database['port'])) if 'port' in database else ())
|
||||
+ (('--username', database['username']) if 'username' in database else ())
|
||||
+ (tuple(database['restore_options'].split(' ')) if 'restore_options' in database else ())
|
||||
+ (() if extract_process else (dump_filename,))
|
||||
+ tuple(
|
||||
itertools.chain.from_iterable(('--schema', schema) for schema in database['schemas'])
|
||||
if database['schemas']
|
||||
else ()
|
||||
)
|
||||
)
|
||||
|
||||
extra_environment = make_extra_environment(database)
|
||||
|
||||
logger.debug(f"{log_prefix}: Restoring PostgreSQL database {database['name']}{dry_run_label}")
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
version: '3'
|
||||
services:
|
||||
docs:
|
||||
image: borgmatic-docs
|
||||
container_name: docs
|
||||
ports:
|
||||
- 8080:80
|
||||
build:
|
||||
dockerfile: docs/Dockerfile
|
||||
context: ..
|
||||
args:
|
||||
ENVIRONMENT: dev
|
||||
message:
|
||||
image: alpine
|
||||
container_name: message
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
echo "You can view dev docs at http://localhost:8080"
|
||||
depends_on:
|
||||
- docs
|
|
@ -138,9 +138,9 @@ hooks:
|
|||
|
||||
### Containers
|
||||
|
||||
If your database is running within a Docker container and borgmatic is too, no
|
||||
problem—simply configure borgmatic to connect to the container's name on its
|
||||
exposed port. For instance:
|
||||
If your database is running within a container and borgmatic is too, no
|
||||
problem—configure borgmatic to connect to the container's name on its exposed
|
||||
port. For instance:
|
||||
|
||||
```yaml
|
||||
hooks:
|
||||
|
@ -154,10 +154,10 @@ hooks:
|
|||
|
||||
But what if borgmatic is running on the host? You can still connect to a
|
||||
database container if its ports are properly exposed to the host. For
|
||||
instance, when running the database container with Docker, you can specify
|
||||
`--publish 127.0.0.1:5433:5432` so that it exposes the container's port 5432
|
||||
to port 5433 on the host (only reachable on localhost, in this case). Or the
|
||||
same thing with Docker Compose:
|
||||
instance, when running the database container, you can specify `--publish
|
||||
127.0.0.1:5433:5432` so that it exposes the container's port 5432 to port 5433
|
||||
on the host (only reachable on localhost, in this case). Or the same thing
|
||||
with Docker Compose:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
|
@ -179,7 +179,7 @@ hooks:
|
|||
password: trustsome1
|
||||
```
|
||||
|
||||
Of course, alter the ports in these examples to suit your particular database
|
||||
You can alter the ports in these examples to suit your particular database
|
||||
system.
|
||||
|
||||
|
||||
|
@ -324,6 +324,17 @@ includes any combined dump file named "all" and any other individual database
|
|||
dumps found in the archive.
|
||||
|
||||
|
||||
### Restore particular schemas
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.13</span> With
|
||||
PostgreSQL and MongoDB, you can limit the restore to a single schema found
|
||||
within the database dump:
|
||||
|
||||
```bash
|
||||
borgmatic restore --archive latest --database users --schema tentant1
|
||||
```
|
||||
|
||||
|
||||
### Limitations
|
||||
|
||||
There are a few important limitations with borgmatic's current database
|
||||
|
@ -386,9 +397,9 @@ dumps with any database system.
|
|||
With PostgreSQL and MySQL/MariaDB, if you're getting authentication errors
|
||||
when borgmatic tries to connect to your database, a natural reaction is to
|
||||
increase your borgmatic verbosity with `--verbosity 2` and go looking in the
|
||||
logs. You'll notice however that your database password does not show up in
|
||||
the logs. This is likely not the cause of the authentication problem unless
|
||||
you mistyped your password, however; borgmatic passes your password to the
|
||||
logs. You'll notice though that your database password does not show up in the
|
||||
logs. This is likely not the cause of the authentication problem unless you
|
||||
mistyped your password, however; borgmatic passes your password to the
|
||||
database via an environment variable that does not appear in the logs.
|
||||
|
||||
The cause of an authentication error is often on the database side—in the
|
||||
|
|
|
@ -95,6 +95,7 @@ See [Borg's check
|
|||
documentation](https://borgbackup.readthedocs.io/en/stable/usage/check.html)
|
||||
for more information.
|
||||
|
||||
|
||||
### Check frequency
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.6.2</span> You can
|
||||
|
|
|
@ -7,7 +7,7 @@ eleventyNavigation:
|
|||
---
|
||||
## Source code
|
||||
|
||||
To get set up to hack on borgmatic, first clone master via HTTPS or SSH:
|
||||
To get set up to hack on borgmatic, first clone it via HTTPS or SSH:
|
||||
|
||||
```bash
|
||||
git clone https://projects.torsion.org/borgmatic-collective/borgmatic.git
|
||||
|
@ -87,19 +87,20 @@ tox -e codespell
|
|||
borgmatic additionally includes some end-to-end tests that integration test
|
||||
with Borg and supported databases for a few representative scenarios. These
|
||||
tests don't run by default when running `tox`, because they're relatively slow
|
||||
and depend on Docker containers for runtime dependencies. These tests tests do
|
||||
run on the continuous integration (CI) server, and running them on your
|
||||
developer machine is the closest thing to CI test parity.
|
||||
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 CI-test parity.
|
||||
|
||||
If you would like to run the full test suite, first install Docker and [Docker
|
||||
Compose](https://docs.docker.com/compose/install/). Then run:
|
||||
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:
|
||||
|
||||
```bash
|
||||
scripts/run-end-to-end-dev-tests
|
||||
```
|
||||
|
||||
Note that this scripts assumes you have permission to run Docker. If you
|
||||
don't, then you may need to run with `sudo`.
|
||||
This script assumes you have permission to run `docker`. If you don't, then
|
||||
you may need to run with `sudo`.
|
||||
|
||||
|
||||
#### Podman
|
||||
|
@ -112,13 +113,13 @@ borgmatic's end-to-end tests optionally support using
|
|||
Setting up Podman is outside the scope of this documentation, but here are
|
||||
some key points to double-check:
|
||||
|
||||
* Install Podman along with `podman-docker` and your desired networking
|
||||
support.
|
||||
* Install Podman and your desired networking support.
|
||||
* Configure `/etc/subuid` and `/etc/subgid` to map users/groups for the
|
||||
non-root user who will run tests.
|
||||
* Create a non-root Podman socket for that user:
|
||||
```bash
|
||||
systemctl --user enable --now podman.socket
|
||||
systemctl --user start --now podman.socket
|
||||
```
|
||||
|
||||
Then you'll be able to run end-to-end tests as per normal, and the test script
|
||||
|
@ -161,11 +162,12 @@ To build and view a copy of the documentation with your local changes, run the
|
|||
following from the root of borgmatic's source code:
|
||||
|
||||
```bash
|
||||
sudo scripts/dev-docs
|
||||
scripts/dev-docs
|
||||
```
|
||||
|
||||
This requires Docker to be installed on your system. You may not need to use
|
||||
sudo if your non-root user has permissions to run Docker.
|
||||
This requires Docker (or Podman; see below) to be installed on your system.
|
||||
This script assumes you have permission to run `docker`. If you don't, then
|
||||
you may need to run with `sudo`.
|
||||
|
||||
After you run the script, you can point your web browser at
|
||||
http://localhost:8080 to view the documentation with your changes.
|
||||
|
@ -183,5 +185,5 @@ borgmatic's developer build for documentation optionally supports using
|
|||
[Podman](https://podman.io/) instead of Docker.
|
||||
|
||||
Setting up Podman is outside the scope of this documentation. But once you
|
||||
install `podman-docker`, then `scripts/dev-docs` should automatically use
|
||||
install and configure Podman, then `scripts/dev-docs` should automatically use
|
||||
Podman instead of Docker.
|
||||
|
|
|
@ -169,7 +169,7 @@ brackets. For instance, the default log format is: `[{asctime}] {levelname}:
|
|||
{message}`. This means each log message is recorded as the log time (in square
|
||||
brackets), a logging level name, a colon, and the actual log message.
|
||||
|
||||
So if you just want each log message to get logged *without* a timestamp or a
|
||||
So if you only want each log message to get logged *without* a timestamp or a
|
||||
logging level name:
|
||||
|
||||
```bash
|
||||
|
|
|
@ -81,13 +81,16 @@ If `archive_name_format` is unspecified, the default is
|
|||
`{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}`, meaning your system hostname plus a
|
||||
timestamp in a particular format.
|
||||
|
||||
|
||||
### Archive filtering
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.11</span> borgmatic
|
||||
uses the `archive_name_format` option to automatically limit which archives
|
||||
get used for actions operating on multiple archives. This prevents, for
|
||||
instance, duplicate archives from showing up in `rlist` or `info` results—even
|
||||
if the same repository appears in multiple borgmatic configuration files. To
|
||||
take advantage of this feature, simply use a different `archive_name_format`
|
||||
in each configuration file.
|
||||
take advantage of this feature, use a different `archive_name_format` in each
|
||||
configuration file.
|
||||
|
||||
Under the hood, borgmatic accomplishes this by substituting globs for certain
|
||||
ephemeral data placeholders in your `archive_name_format`—and using the result
|
||||
|
@ -108,8 +111,8 @@ archives used for actions like `rlist`, `info`, `prune`, `check`, etc.
|
|||
|
||||
The end result is that when borgmatic runs the actions for a particular
|
||||
application-specific configuration file, it only operates on the archives
|
||||
created for that application. Of course, this doesn't apply to actions like
|
||||
`compact` that operate on an entire repository.
|
||||
created for that application. But this doesn't apply to actions like `compact`
|
||||
that operate on an entire repository.
|
||||
|
||||
If this behavior isn't quite smart enough for your needs, you can use the
|
||||
`match_archives` option to override the pattern that borgmatic uses for
|
||||
|
@ -272,9 +275,65 @@ Once this include gets merged in, the resulting configuration would have a
|
|||
When there's an option collision between the local file and the merged
|
||||
include, the local file's option takes precedence.
|
||||
|
||||
|
||||
#### List merge
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.6.1</span> Colliding
|
||||
list values are appended together.
|
||||
|
||||
<span class="minilink minilink-addedin">New in version 1.7.12</span> If there
|
||||
is a list value from an include that you *don't* want in your local
|
||||
configuration file, you can omit it with an `!omit` tag. For instance:
|
||||
|
||||
```yaml
|
||||
<<: !include /etc/borgmatic/common.yaml
|
||||
|
||||
location:
|
||||
source_directories:
|
||||
- !omit /home
|
||||
- /var
|
||||
```
|
||||
|
||||
And `common.yaml` like this:
|
||||
|
||||
```yaml
|
||||
location:
|
||||
source_directories:
|
||||
- /home
|
||||
- /etc
|
||||
```
|
||||
|
||||
Once this include gets merged in, the resulting configuration will have a
|
||||
`source_directories` value of `/etc` and `/var`—with `/home` omitted.
|
||||
|
||||
This feature currently only works on scalar (e.g. string or number) list items
|
||||
and will not work elsewhere in a configuration file. Be sure to put the
|
||||
`!omit` tag *before* the list item (after the dash). Putting `!omit` after the
|
||||
list item will not work, as it gets interpreted as part of the string. Here's
|
||||
an example of some things not to do:
|
||||
|
||||
```yaml
|
||||
<<: !include /etc/borgmatic/common.yaml
|
||||
|
||||
location:
|
||||
source_directories:
|
||||
# Do not do this! It will not work. "!omit" belongs before "/home".
|
||||
- /home !omit
|
||||
|
||||
# Do not do this either! "!omit" only works on scalar list items.
|
||||
repositories: !omit
|
||||
# Also do not do this for the same reason! This is a list item, but it's
|
||||
# not a scalar.
|
||||
- !omit path: repo.borg
|
||||
```
|
||||
|
||||
Additionally, the `!omit` tag only works in a configuration file that also
|
||||
performs a merge include with `<<: !include`. It doesn't make sense within,
|
||||
for instance, an included configuration file itself (unless it in turn
|
||||
performs its own merge include). That's because `!omit` only applies to the
|
||||
file doing the include; it doesn't work in reverse or propagate through
|
||||
includes.
|
||||
|
||||
|
||||
### Shallow merge
|
||||
|
||||
|
@ -296,7 +355,7 @@ on the `retention` mapping:
|
|||
|
||||
location:
|
||||
repositories:
|
||||
- repo.borg
|
||||
- path: repo.borg
|
||||
|
||||
retention: !retain
|
||||
keep_daily: 5
|
||||
|
@ -307,7 +366,7 @@ And `common.yaml` like this:
|
|||
```yaml
|
||||
location:
|
||||
repositories:
|
||||
- common.borg
|
||||
- path: common.borg
|
||||
|
||||
retention:
|
||||
keep_hourly: 24
|
||||
|
|
|
@ -73,7 +73,7 @@ from borgmatic for a configured interval.
|
|||
|
||||
### Consistency checks
|
||||
|
||||
While not strictly part of monitoring, if you really want confidence that your
|
||||
While not strictly part of monitoring, if you want confidence that your
|
||||
backups are not only running but are restorable as well, you can configure
|
||||
particular [consistency
|
||||
checks](https://torsion.org/borgmatic/docs/how-to/deal-with-very-large-backups/#consistency-check-configuration)
|
||||
|
|
|
@ -89,8 +89,10 @@ borgmatic's `borg` action is not without limitations:
|
|||
* Unlike normal borgmatic actions that support JSON, the `borg` action will
|
||||
not disable certain borgmatic logs to avoid interfering with JSON output.
|
||||
* Unlike other borgmatic actions, the `borg` action captures (and logs) all
|
||||
output, so interactive prompts or flags like `--progress` will not work as
|
||||
expected.
|
||||
output, so interactive prompts and flags like `--progress` will not work as
|
||||
expected. <span class="minilink minilink-addedin">New in version
|
||||
1.7.13</span> borgmatic now runs the `borg` action without capturing output,
|
||||
so interactive prompts work.
|
||||
|
||||
In general, this `borgmatic borg` feature should be considered an escape
|
||||
valve—a feature of second resort. In the long run, it's preferable to wrap
|
||||
|
|
|
@ -82,12 +82,13 @@ on a relatively dedicated system, then a global install can work out fine.
|
|||
Besides the approaches described above, there are several other options for
|
||||
installing borgmatic:
|
||||
|
||||
* [Docker image with scheduled backups](https://hub.docker.com/r/b3vis/borgmatic/) (+ Docker Compose files)
|
||||
* [Docker image with multi-arch and Docker CLI support](https://hub.docker.com/r/modem7/borgmatic-docker/)
|
||||
* [container image with scheduled backups](https://hub.docker.com/r/b3vis/borgmatic/) (+ Docker Compose files)
|
||||
* [container image with multi-arch and Docker CLI support](https://hub.docker.com/r/modem7/borgmatic-docker/)
|
||||
* [Debian](https://tracker.debian.org/pkg/borgmatic)
|
||||
* [Ubuntu](https://launchpad.net/ubuntu/+source/borgmatic)
|
||||
* [Fedora official](https://bodhi.fedoraproject.org/updates/?search=borgmatic)
|
||||
* [Fedora unofficial](https://copr.fedorainfracloud.org/coprs/heffer/borgmatic/)
|
||||
* [Gentoo](https://packages.gentoo.org/packages/app-backup/borgmatic)
|
||||
* [Arch Linux](https://www.archlinux.org/packages/community/any/borgmatic/)
|
||||
* [Alpine Linux](https://pkgs.alpinelinux.org/packages?name=borgmatic)
|
||||
* [OpenBSD](https://openports.pl/path/sysutils/borgmatic)
|
||||
|
@ -96,7 +97,7 @@ installing borgmatic:
|
|||
* [macOS (via MacPorts)](https://ports.macports.org/port/borgmatic/)
|
||||
* [NixOS](https://search.nixos.org/packages?show=borgmatic&sort=relevance&type=packages&query=borgmatic)
|
||||
* [Ansible role](https://github.com/borgbase/ansible-role-borgbackup)
|
||||
* [virtualenv](https://virtualenv.pypa.io/en/stable/)
|
||||
* [Unraid](https://unraid.net/community/apps?q=borgmatic#r)
|
||||
|
||||
|
||||
## Hosting providers
|
||||
|
@ -279,7 +280,7 @@ that, you can configure a separate job runner to invoke it periodically.
|
|||
### cron
|
||||
|
||||
If you're using cron, download the [sample cron
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/src/master/sample/cron/borgmatic).
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/src/main/sample/cron/borgmatic).
|
||||
Then, from the directory where you downloaded it:
|
||||
|
||||
```bash
|
||||
|
@ -303,9 +304,9 @@ you may already have borgmatic systemd service and timer files. If so, you may
|
|||
be able to skip some of the steps below.)
|
||||
|
||||
First, download the [sample systemd service
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/master/sample/systemd/borgmatic.service)
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/main/sample/systemd/borgmatic.service)
|
||||
and the [sample systemd timer
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/master/sample/systemd/borgmatic.timer).
|
||||
file](https://projects.torsion.org/borgmatic-collective/borgmatic/raw/branch/main/sample/systemd/borgmatic.timer).
|
||||
|
||||
Then, from the directory where you downloaded them:
|
||||
|
||||
|
@ -334,10 +335,13 @@ Access](https://projects.torsion.org/borgmatic-collective/borgmatic/issues/293).
|
|||
|
||||
### Shell completion
|
||||
|
||||
borgmatic includes a shell completion script (currently only for Bash) to
|
||||
borgmatic includes a shell completion script (currently only for Bash and Fish) to
|
||||
support tab-completing borgmatic command-line actions and flags. Depending on
|
||||
how you installed borgmatic, this may be enabled by default. But if it's not,
|
||||
start by installing the `bash-completion` Linux package or the
|
||||
how you installed borgmatic, this may be enabled by default.
|
||||
|
||||
#### Bash
|
||||
|
||||
If completions aren't enabled, start by installing the `bash-completion` Linux package or the
|
||||
[`bash-completion@2`](https://formulae.brew.sh/formula/bash-completion@2)
|
||||
macOS Homebrew formula. Then, install the shell completion script globally:
|
||||
|
||||
|
@ -362,6 +366,14 @@ borgmatic --bash-completion > ~/.local/share/bash-completion/completions/borgmat
|
|||
Finally, restart your shell (`exit` and open a new shell) so the completions
|
||||
take effect.
|
||||
|
||||
#### fish
|
||||
|
||||
To add completions for fish, install the completions file globally:
|
||||
|
||||
```fish
|
||||
borgmatic --fish-completion | sudo tee /usr/share/fish/vendor_completions.d/borgmatic.fish
|
||||
source /usr/share/fish/vendor_completions.d/borgmatic.fish
|
||||
```
|
||||
|
||||
### Colored output
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
set -e
|
||||
|
||||
docker build --tag borgmatic-docs --build-arg ENVIRONMENT=dev --file docs/Dockerfile .
|
||||
echo
|
||||
echo "You can view dev docs at http://localhost:8080"
|
||||
echo
|
||||
docker run --interactive --tty --publish 8080:80 --rm borgmatic-docs
|
||||
USER_PODMAN_SOCKET_PATH=/run/user/$UID/podman/podman.sock
|
||||
|
||||
if [ -e "$USER_PODMAN_SOCKET_PATH" ]; then
|
||||
export DOCKER_HOST="unix://$USER_PODMAN_SOCKET_PATH"
|
||||
fi
|
||||
|
||||
docker-compose --file docs/docker-compose.yaml up --build --force-recreate
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
set -e
|
||||
|
||||
if [ -z "$TEST_CONTAINER" ] ; then
|
||||
if [ -z "$TEST_CONTAINER" ]; then
|
||||
echo "This script is designed to work inside a test container and is not intended to"
|
||||
echo "be run manually. If you're trying to run borgmatic's end-to-end tests, execute"
|
||||
echo "scripts/run-end-to-end-dev-tests instead."
|
||||
|
@ -18,14 +18,14 @@ if [ -z "$TEST_CONTAINER" ] ; then
|
|||
fi
|
||||
|
||||
apk add --no-cache python3 py3-pip borgbackup postgresql-client mariadb-client mongodb-tools \
|
||||
py3-ruamel.yaml py3-ruamel.yaml.clib bash sqlite
|
||||
py3-ruamel.yaml py3-ruamel.yaml.clib 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
|
||||
pip3 install --ignore-installed tox==3.25.1
|
||||
export COVERAGE_FILE=/tmp/.coverage
|
||||
|
||||
if [ "$1" != "--end-to-end-only" ] ; then
|
||||
if [ "$1" != "--end-to-end-only" ]; then
|
||||
tox --workdir /tmp/.tox --sitepackages
|
||||
fi
|
||||
|
||||
|
|
13
setup.cfg
13
setup.cfg
|
@ -4,22 +4,23 @@ description_file=README.md
|
|||
[tool:pytest]
|
||||
testpaths = tests
|
||||
addopts = --cov-report term-missing:skip-covered --cov=borgmatic --ignore=tests/end-to-end
|
||||
filterwarnings =
|
||||
ignore:Deprecated call to `pkg_resources.declare_namespace\('ruamel'\)`.*:DeprecationWarning
|
||||
|
||||
[flake8]
|
||||
ignore = E501,W503
|
||||
max-line-length = 100
|
||||
extend-ignore = E203,E501,W503
|
||||
exclude = *.*/*
|
||||
multiline-quotes = '''
|
||||
docstring-quotes = '''
|
||||
|
||||
[tool:isort]
|
||||
force_single_line = False
|
||||
include_trailing_comma = True
|
||||
profile=black
|
||||
known_first_party = borgmatic
|
||||
line_length = 100
|
||||
multi_line_output = 3
|
||||
skip = .tox
|
||||
|
||||
[codespell]
|
||||
skip = .git,.tox,build
|
||||
|
||||
[pycodestyle]
|
||||
ignore = E203
|
||||
max_line_length = 100
|
||||
|
|
3
setup.py
3
setup.py
|
@ -1,6 +1,6 @@
|
|||
from setuptools import find_packages, setup
|
||||
|
||||
VERSION = '1.7.12.dev0'
|
||||
VERSION = '1.7.14.dev0'
|
||||
|
||||
|
||||
setup(
|
||||
|
@ -32,6 +32,7 @@ setup(
|
|||
install_requires=(
|
||||
'colorama>=0.4.1,<0.5',
|
||||
'jsonschema',
|
||||
'packaging',
|
||||
'requests',
|
||||
'ruamel.yaml>0.15.0,<0.18.0',
|
||||
'setuptools',
|
||||
|
|
|
@ -1,27 +1,33 @@
|
|||
appdirs==1.4.4; python_version >= '3.8'
|
||||
attrs==20.3.0; python_version >= '3.8'
|
||||
black==19.10b0; python_version >= '3.8'
|
||||
click==7.1.2; python_version >= '3.8'
|
||||
attrs==22.2.0; python_version >= '3.8'
|
||||
black==23.3.0; python_version >= '3.8'
|
||||
chardet==5.1.0
|
||||
click==8.1.3; python_version >= '3.8'
|
||||
codespell==2.2.4
|
||||
colorama==0.4.4
|
||||
coverage==5.3
|
||||
flake8==4.0.1
|
||||
colorama==0.4.6
|
||||
coverage==7.2.3
|
||||
flake8==6.0.0
|
||||
flake8-quotes==3.3.2
|
||||
flake8-use-fstring==1.4
|
||||
flake8-variables-names==0.0.5
|
||||
flexmock==0.10.4
|
||||
isort==5.9.1
|
||||
mccabe==0.6.1
|
||||
pluggy==0.13.1
|
||||
pathspec==0.8.1; python_version >= '3.8'
|
||||
py==1.10.0
|
||||
pycodestyle==2.8.0
|
||||
pyflakes==2.4.0
|
||||
jsonschema==3.2.0
|
||||
pytest==7.2.0
|
||||
flexmock==0.11.3
|
||||
idna==3.4
|
||||
importlib_metadata==6.3.0; python_version < '3.8'
|
||||
isort==5.12.0
|
||||
mccabe==0.7.0
|
||||
packaging==23.1
|
||||
pluggy==1.0.0
|
||||
pathspec==0.11.1; python_version >= '3.8'
|
||||
py==1.11.0
|
||||
pycodestyle==2.10.0
|
||||
pyflakes==3.0.1
|
||||
jsonschema==4.17.3
|
||||
pytest==7.3.0
|
||||
pytest-cov==4.0.0
|
||||
regex; python_version >= '3.8'
|
||||
requests==2.25.0
|
||||
requests==2.31.0
|
||||
ruamel.yaml>0.15.0,<0.18.0
|
||||
toml==0.10.2; python_version >= '3.8'
|
||||
typed-ast; python_version >= '3.8'
|
||||
typing-extensions==4.5.0; python_version < '3.8'
|
||||
zipp==3.15.0; python_version < '3.8'
|
||||
|
|
|
@ -23,6 +23,7 @@ services:
|
|||
- "../..:/app:ro"
|
||||
tmpfs:
|
||||
- "/app/borgmatic.egg-info"
|
||||
- "/app/build"
|
||||
tty: true
|
||||
working_dir: /app
|
||||
entrypoint: /app/scripts/run-full-tests
|
||||
|
|
|
@ -3,3 +3,7 @@ import subprocess
|
|||
|
||||
def test_bash_completion_runs_without_error():
|
||||
subprocess.check_call('borgmatic --bash-completion | bash', shell=True)
|
||||
|
||||
|
||||
def test_fish_completion_runs_without_error():
|
||||
subprocess.check_call('borgmatic --fish-completion | fish', shell=True)
|
||||
|
|
|
@ -118,7 +118,7 @@ def test_database_dump_and_restore():
|
|||
|
||||
# Restore the database from the archive.
|
||||
subprocess.check_call(
|
||||
['borgmatic', '--config', config_path, 'restore', '--archive', archive_name]
|
||||
['borgmatic', '-v', '2', '--config', config_path, 'restore', '--archive', archive_name]
|
||||
)
|
||||
finally:
|
||||
os.chdir(original_working_directory)
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
import argparse
|
||||
import copy
|
||||
|
||||
import flexmock
|
||||
from flexmock import flexmock
|
||||
|
||||
import borgmatic.borg.info
|
||||
import borgmatic.borg.list
|
||||
import borgmatic.borg.mount
|
||||
import borgmatic.borg.prune
|
||||
import borgmatic.borg.rlist
|
||||
import borgmatic.borg.transfer
|
||||
import borgmatic.commands.arguments
|
||||
|
@ -58,7 +61,55 @@ def test_transfer_archives_command_does_not_duplicate_flags_or_raise():
|
|||
continue
|
||||
|
||||
borgmatic.borg.transfer.transfer_archives(
|
||||
False, 'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
False,
|
||||
'repo',
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments('prune')['prune']
|
||||
flexmock(borgmatic.borg.prune).should_receive('execute_command').replace_with(
|
||||
assert_command_does_not_duplicate_flags
|
||||
)
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
borgmatic.borg.prune.prune_archives(
|
||||
False,
|
||||
'repo',
|
||||
{},
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
argparse.Namespace(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_command_does_not_duplicate_flags_or_raise():
|
||||
arguments = borgmatic.commands.arguments.parse_arguments('mount', '--mount-point', 'tmp')[
|
||||
'mount'
|
||||
]
|
||||
flexmock(borgmatic.borg.mount).should_receive('execute_command').replace_with(
|
||||
assert_command_does_not_duplicate_flags
|
||||
)
|
||||
|
||||
for argument_name in dir(arguments):
|
||||
if argument_name.startswith('_'):
|
||||
continue
|
||||
|
||||
borgmatic.borg.mount.mount_archive(
|
||||
'repo',
|
||||
'archive',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
{},
|
||||
'2.3.4',
|
||||
argparse.Namespace(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -70,7 +121,11 @@ def test_make_list_command_does_not_duplicate_flags_or_raise():
|
|||
continue
|
||||
|
||||
command = borgmatic.borg.list.make_list_command(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
'repo',
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
argparse.Namespace(log_json=False),
|
||||
)
|
||||
|
||||
assert_command_does_not_duplicate_flags(command)
|
||||
|
@ -84,7 +139,11 @@ def test_make_rlist_command_does_not_duplicate_flags_or_raise():
|
|||
continue
|
||||
|
||||
command = borgmatic.borg.rlist.make_rlist_command(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
'repo',
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
assert_command_does_not_duplicate_flags(command)
|
||||
|
@ -104,5 +163,9 @@ def test_display_archives_info_command_does_not_duplicate_flags_or_raise():
|
|||
continue
|
||||
|
||||
borgmatic.borg.info.display_archives_info(
|
||||
'repo', {}, '2.3.4', fuzz_argument(arguments, argument_name)
|
||||
'repo',
|
||||
{},
|
||||
'2.3.4',
|
||||
fuzz_argument(arguments, argument_name),
|
||||
argparse.Namespace(log_json=False),
|
||||
)
|
||||
|
|
|
@ -422,6 +422,13 @@ def test_parse_arguments_disallows_list_with_progress_for_create_action():
|
|||
module.parse_arguments('create', '--list', '--progress')
|
||||
|
||||
|
||||
def test_parse_arguments_disallows_list_with_json_for_create_action():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.parse_arguments('create', '--list', '--json')
|
||||
|
||||
|
||||
def test_parse_arguments_allows_json_with_list_or_info():
|
||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||
|
||||
|
|
|
@ -3,3 +3,7 @@ from borgmatic.commands import completion as module
|
|||
|
||||
def test_bash_completion_does_not_raise():
|
||||
assert module.bash_completion()
|
||||
|
||||
|
||||
def test_fish_completion_does_not_raise():
|
||||
assert module.fish_completion()
|
||||
|
|
|
@ -211,7 +211,7 @@ def test_load_configuration_with_retain_tag_but_without_merge_include_raises():
|
|||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
assert module.load_configuration('config.yaml')
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_retain_tag_on_scalar_raises():
|
||||
|
@ -239,7 +239,156 @@ def test_load_configuration_with_retain_tag_on_scalar_raises():
|
|||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
assert module.load_configuration('config.yaml')
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_merges_include_and_omits_requested_values():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- !omit b
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {'stuff': ['a', 'c', 'x', 'y']}
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_unknown_value_merges_include_and_does_not_raise():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- !omit q
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
assert module.load_configuration('config.yaml') == {'stuff': ['a', 'b', 'c', 'x', 'y']}
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_non_list_item_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff: !omit
|
||||
- x
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_on_non_scalar_list_item_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- foo: bar
|
||||
baz: quux
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- !omit foo: bar
|
||||
baz: quux
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_with_omit_tag_but_without_merge_raises():
|
||||
builtins = flexmock(sys.modules['builtins'])
|
||||
flexmock(module.os).should_receive('getcwd').and_return('/tmp')
|
||||
flexmock(module.os.path).should_receive('isabs').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(True)
|
||||
include_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- a
|
||||
- !omit b
|
||||
- c
|
||||
'''
|
||||
)
|
||||
include_file.name = 'include.yaml'
|
||||
builtins.should_receive('open').with_args('/tmp/include.yaml').and_return(include_file)
|
||||
config_file = io.StringIO(
|
||||
'''
|
||||
stuff:
|
||||
- x
|
||||
- y
|
||||
<<: !include include.yaml
|
||||
'''
|
||||
)
|
||||
config_file.name = 'config.yaml'
|
||||
builtins.should_receive('open').with_args('config.yaml').and_return(config_file)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.load_configuration('config.yaml')
|
||||
|
||||
|
||||
def test_load_configuration_does_not_merge_include_list():
|
||||
|
@ -277,13 +426,33 @@ def test_load_configuration_does_not_merge_include_list():
|
|||
module.ruamel.yaml.nodes.ScalarNode,
|
||||
),
|
||||
)
|
||||
def test_retain_node_error_raises(node_class):
|
||||
def test_raise_retain_node_error_raises(node_class):
|
||||
with pytest.raises(ValueError):
|
||||
module.retain_node_error(
|
||||
module.raise_retain_node_error(
|
||||
loader=flexmock(), node=node_class(tag=flexmock(), value=flexmock())
|
||||
)
|
||||
|
||||
|
||||
def test_raise_omit_node_error_raises():
|
||||
with pytest.raises(ValueError):
|
||||
module.raise_omit_node_error(loader=flexmock(), node=flexmock())
|
||||
|
||||
|
||||
def test_filter_omitted_nodes():
|
||||
nodes = [
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='a'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='b'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='c'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='a'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='!omit', value='b'),
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='c'),
|
||||
]
|
||||
|
||||
result = module.filter_omitted_nodes(nodes)
|
||||
|
||||
assert [item.value for item in result] == ['a', 'c', 'a', 'c']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_replaces_colliding_scalar_values():
|
||||
node_values = [
|
||||
(
|
||||
|
@ -483,7 +652,15 @@ def test_deep_merge_nodes_appends_colliding_sequence_values():
|
|||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq', value=['echo 1', 'echo 2']
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -499,7 +676,15 @@ def test_deep_merge_nodes_appends_colliding_sequence_values():
|
|||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq', value=['echo 3', 'echo 4']
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 4'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -514,10 +699,10 @@ def test_deep_merge_nodes_appends_colliding_sequence_values():
|
|||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert options[0][1].value == ['echo 1', 'echo 2', 'echo 3', 'echo 4']
|
||||
assert [item.value for item in options[0][1].value] == ['echo 1', 'echo 2', 'echo 3', 'echo 4']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_keeps_mapping_values_tagged_with_retain():
|
||||
def test_deep_merge_nodes_only_keeps_mapping_values_tagged_with_retain():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='retention'),
|
||||
|
@ -568,7 +753,7 @@ def test_deep_merge_nodes_keeps_mapping_values_tagged_with_retain():
|
|||
assert options[0][1].value == '5'
|
||||
|
||||
|
||||
def test_deep_merge_nodes_keeps_sequence_values_tagged_with_retain():
|
||||
def test_deep_merge_nodes_only_keeps_sequence_values_tagged_with_retain():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
|
@ -580,7 +765,15 @@ def test_deep_merge_nodes_keeps_sequence_values_tagged_with_retain():
|
|||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq', value=['echo 1', 'echo 2']
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -596,7 +789,15 @@ def test_deep_merge_nodes_keeps_sequence_values_tagged_with_retain():
|
|||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='!retain', value=['echo 3', 'echo 4']
|
||||
tag='!retain',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 4'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -612,4 +813,64 @@ def test_deep_merge_nodes_keeps_sequence_values_tagged_with_retain():
|
|||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert options[0][1].tag == 'tag:yaml.org,2002:seq'
|
||||
assert options[0][1].value == ['echo 3', 'echo 4']
|
||||
assert [item.value for item in options[0][1].value] == ['echo 3', 'echo 4']
|
||||
|
||||
|
||||
def test_deep_merge_nodes_skips_sequence_values_tagged_with_omit():
|
||||
node_values = [
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 1'
|
||||
),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 2'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(tag='tag:yaml.org,2002:str', value='hooks'),
|
||||
module.ruamel.yaml.nodes.MappingNode(
|
||||
tag='tag:yaml.org,2002:map',
|
||||
value=[
|
||||
(
|
||||
module.ruamel.yaml.nodes.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='before_backup'
|
||||
),
|
||||
module.ruamel.yaml.nodes.SequenceNode(
|
||||
tag='tag:yaml.org,2002:seq',
|
||||
value=[
|
||||
module.ruamel.yaml.ScalarNode(tag='!omit', value='echo 2'),
|
||||
module.ruamel.yaml.ScalarNode(
|
||||
tag='tag:yaml.org,2002:str', value='echo 3'
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]
|
||||
|
||||
result = module.deep_merge_nodes(node_values)
|
||||
assert len(result) == 1
|
||||
(section_key, section_value) = result[0]
|
||||
assert section_key.value == 'hooks'
|
||||
options = section_value.value
|
||||
assert len(options) == 1
|
||||
assert options[0][0].value == 'before_backup'
|
||||
assert [item.value for item in options[0][1].value] == ['echo 1', 'echo 3']
|
||||
|
|
|
@ -16,6 +16,7 @@ def test_run_borg_does_not_raise():
|
|||
repository={'path': 'repos'},
|
||||
storage={},
|
||||
local_borg_version=None,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
borg_arguments=borg_arguments,
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
|
|
|
@ -14,6 +14,7 @@ def test_run_break_lock_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
break_lock_arguments=break_lock_arguments,
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -12,7 +12,11 @@ def test_run_check_calls_hooks_for_configured_repository():
|
|||
flexmock(module.borgmatic.borg.check).should_receive('check_archives').once()
|
||||
flexmock(module.borgmatic.hooks.command).should_receive('execute_hook').times(2)
|
||||
check_arguments = flexmock(
|
||||
repository=None, progress=flexmock(), repair=flexmock(), only=flexmock(), force=flexmock(),
|
||||
repository=None,
|
||||
progress=flexmock(),
|
||||
repair=flexmock(),
|
||||
only=flexmock(),
|
||||
force=flexmock(),
|
||||
)
|
||||
global_arguments = flexmock(monitoring_verbosity=1, dry_run=False)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ def test_run_info_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
info_arguments=info_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -18,6 +18,7 @@ def test_run_list_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -21,6 +21,7 @@ def test_run_mount_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
mount_arguments=mount_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -72,6 +72,7 @@ def test_collect_archive_database_names_parses_archive_paths():
|
|||
location={'borgmatic_source_directory': '.borgmatic'},
|
||||
storage=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
|
@ -97,6 +98,7 @@ def test_collect_archive_database_names_parses_directory_format_archive_paths():
|
|||
location={'borgmatic_source_directory': '.borgmatic'},
|
||||
storage=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
|
@ -118,6 +120,7 @@ def test_collect_archive_database_names_skips_bad_archive_paths():
|
|||
location={'borgmatic_source_directory': '.borgmatic'},
|
||||
storage=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
)
|
||||
|
@ -148,7 +151,8 @@ def test_find_databases_to_restore_without_requested_names_finds_all_archive_dat
|
|||
archive_database_names = {'postresql_databases': ['foo', 'bar']}
|
||||
|
||||
restore_names = module.find_databases_to_restore(
|
||||
requested_database_names=[], archive_database_names=archive_database_names,
|
||||
requested_database_names=[],
|
||||
archive_database_names=archive_database_names,
|
||||
)
|
||||
|
||||
assert restore_names == archive_database_names
|
||||
|
@ -158,7 +162,8 @@ def test_find_databases_to_restore_with_all_in_requested_names_finds_all_archive
|
|||
archive_database_names = {'postresql_databases': ['foo', 'bar']}
|
||||
|
||||
restore_names = module.find_databases_to_restore(
|
||||
requested_database_names=['all'], archive_database_names=archive_database_names,
|
||||
requested_database_names=['all'],
|
||||
archive_database_names=archive_database_names,
|
||||
)
|
||||
|
||||
assert restore_names == archive_database_names
|
||||
|
@ -194,7 +199,9 @@ def test_ensure_databases_found_with_all_databases_found_does_not_raise():
|
|||
def test_ensure_databases_found_with_no_databases_raises():
|
||||
with pytest.raises(ValueError):
|
||||
module.ensure_databases_found(
|
||||
restore_names={'postgresql_databases': []}, remaining_restore_names={}, found_names=[],
|
||||
restore_names={'postgresql_databases': []},
|
||||
remaining_restore_names={},
|
||||
found_names=[],
|
||||
)
|
||||
|
||||
|
||||
|
@ -233,7 +240,7 @@ def test_run_restore_restores_each_database():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'foo'},
|
||||
database={'name': 'foo', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('restore_single_database').with_args(
|
||||
repository=object,
|
||||
|
@ -246,7 +253,7 @@ def test_run_restore_restores_each_database():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'bar'},
|
||||
database={'name': 'bar', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('ensure_databases_found')
|
||||
|
||||
|
@ -256,7 +263,9 @@ def test_run_restore_restores_each_database():
|
|||
storage=flexmock(),
|
||||
hooks=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
restore_arguments=flexmock(repository='repo', archive='archive', databases=flexmock()),
|
||||
restore_arguments=flexmock(
|
||||
repository='repo', archive='archive', databases=flexmock(), schemas=None
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
|
@ -327,7 +336,7 @@ def test_run_restore_restores_database_configured_with_all_name():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'foo'},
|
||||
database={'name': 'foo', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('restore_single_database').with_args(
|
||||
repository=object,
|
||||
|
@ -340,7 +349,7 @@ def test_run_restore_restores_database_configured_with_all_name():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'bar'},
|
||||
database={'name': 'bar', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('ensure_databases_found')
|
||||
|
||||
|
@ -350,7 +359,9 @@ def test_run_restore_restores_database_configured_with_all_name():
|
|||
storage=flexmock(),
|
||||
hooks=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
restore_arguments=flexmock(repository='repo', archive='archive', databases=flexmock()),
|
||||
restore_arguments=flexmock(
|
||||
repository='repo', archive='archive', databases=flexmock(), schemas=None
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
|
@ -399,7 +410,7 @@ def test_run_restore_skips_missing_database():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'foo'},
|
||||
database={'name': 'foo', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('restore_single_database').with_args(
|
||||
repository=object,
|
||||
|
@ -412,7 +423,7 @@ def test_run_restore_skips_missing_database():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'bar'},
|
||||
database={'name': 'bar', 'schemas': None},
|
||||
).never()
|
||||
flexmock(module).should_receive('ensure_databases_found')
|
||||
|
||||
|
@ -422,7 +433,9 @@ def test_run_restore_skips_missing_database():
|
|||
storage=flexmock(),
|
||||
hooks=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
restore_arguments=flexmock(repository='repo', archive='archive', databases=flexmock()),
|
||||
restore_arguments=flexmock(
|
||||
repository='repo', archive='archive', databases=flexmock(), schemas=None
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
|
@ -465,7 +478,7 @@ def test_run_restore_restores_databases_from_different_hooks():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='postgresql_databases',
|
||||
database={'name': 'foo'},
|
||||
database={'name': 'foo', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('restore_single_database').with_args(
|
||||
repository=object,
|
||||
|
@ -478,7 +491,7 @@ def test_run_restore_restores_databases_from_different_hooks():
|
|||
remote_path=object,
|
||||
archive_name=object,
|
||||
hook_name='mysql_databases',
|
||||
database={'name': 'bar'},
|
||||
database={'name': 'bar', 'schemas': None},
|
||||
).once()
|
||||
flexmock(module).should_receive('ensure_databases_found')
|
||||
|
||||
|
@ -488,7 +501,9 @@ def test_run_restore_restores_databases_from_different_hooks():
|
|||
storage=flexmock(),
|
||||
hooks=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
restore_arguments=flexmock(repository='repo', archive='archive', databases=flexmock()),
|
||||
restore_arguments=flexmock(
|
||||
repository='repo', archive='archive', databases=flexmock(), schemas=None
|
||||
),
|
||||
global_arguments=flexmock(dry_run=False),
|
||||
local_path=flexmock(),
|
||||
remote_path=flexmock(),
|
||||
|
|
|
@ -15,6 +15,7 @@ def test_run_rinfo_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
rinfo_arguments=rinfo_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -15,6 +15,7 @@ def test_run_rlist_does_not_raise():
|
|||
storage={},
|
||||
local_borg_version=None,
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=flexmock(),
|
||||
local_path=None,
|
||||
remote_path=None,
|
||||
)
|
||||
|
|
|
@ -7,7 +7,7 @@ from borgmatic.borg import borg as module
|
|||
from ..test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_calls_borg_with_parameters():
|
||||
def test_run_arbitrary_borg_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -15,7 +15,7 @@ def test_run_arbitrary_borg_calls_borg_with_parameters():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -28,7 +28,7 @@ def test_run_arbitrary_borg_calls_borg_with_parameters():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -36,7 +36,7 @@ def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_parameter():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo', '--info'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -50,7 +50,7 @@ def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_parameter():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_parameter():
|
||||
def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -58,7 +58,7 @@ def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_parameter():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo', '--debug', '--show-rc'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -72,7 +72,7 @@ def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_parameter():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
storage_config = {'lock_wait': 5}
|
||||
|
@ -83,7 +83,7 @@ def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_parameters(
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo', '--lock-wait', '5'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -96,7 +96,7 @@ def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_parameters(
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_with_archive_calls_borg_with_archive_parameter():
|
||||
def test_run_arbitrary_borg_with_archive_calls_borg_with_archive_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
|
@ -106,7 +106,7 @@ def test_run_arbitrary_borg_with_archive_calls_borg_with_archive_parameter():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo::archive'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -128,7 +128,7 @@ def test_run_arbitrary_borg_with_local_path_calls_borg_via_local_path():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg1', 'break-lock', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg1',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -142,7 +142,7 @@ def test_run_arbitrary_borg_with_local_path_calls_borg_via_local_path():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -152,7 +152,7 @@ def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_paramet
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo', '--remote-path', 'borg1'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -166,7 +166,7 @@ def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_paramet
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_passes_borg_specific_parameters_to_borg():
|
||||
def test_run_arbitrary_borg_passes_borg_specific_flags_to_borg():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -174,7 +174,7 @@ def test_run_arbitrary_borg_passes_borg_specific_parameters_to_borg():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'list', 'repo', '--progress'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -187,7 +187,7 @@ def test_run_arbitrary_borg_passes_borg_specific_parameters_to_borg():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_omits_dash_dash_in_parameters_passed_to_borg():
|
||||
def test_run_arbitrary_borg_omits_dash_dash_in_flags_passed_to_borg():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -195,7 +195,7 @@ def test_run_arbitrary_borg_omits_dash_dash_in_parameters_passed_to_borg():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'break-lock', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -208,7 +208,7 @@ def test_run_arbitrary_borg_omits_dash_dash_in_parameters_passed_to_borg():
|
|||
)
|
||||
|
||||
|
||||
def test_run_arbitrary_borg_without_borg_specific_parameters_does_not_raise():
|
||||
def test_run_arbitrary_borg_without_borg_specific_flags_does_not_raise():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_flags').never()
|
||||
|
@ -216,13 +216,16 @@ def test_run_arbitrary_borg_without_borg_specific_parameters_does_not_raise():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg',),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.run_arbitrary_borg(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3', options=[],
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
options=[],
|
||||
)
|
||||
|
||||
|
||||
|
@ -234,7 +237,7 @@ def test_run_arbitrary_borg_passes_key_sub_command_to_borg_before_repository():
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'key', 'export', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -255,7 +258,7 @@ def test_run_arbitrary_borg_passes_debug_sub_command_to_borg_before_repository()
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'debug', 'dump-manifest', 'repo', 'path'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -276,7 +279,7 @@ def test_run_arbitrary_borg_with_debug_info_command_does_not_pass_borg_repositor
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'debug', 'info'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
@ -297,7 +300,7 @@ def test_run_arbitrary_borg_with_debug_convert_profile_command_does_not_pass_bor
|
|||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'debug', 'convert-profile', 'in', 'out'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=module.borgmatic.execute.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
|
|
@ -10,7 +10,9 @@ from ..test_verbosity import insert_logging_mock
|
|||
def insert_execute_command_mock(command):
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
command, borg_local_path='borg', extra_environment=None,
|
||||
command,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
).once()
|
||||
|
||||
|
||||
|
@ -19,7 +21,10 @@ def test_break_lock_calls_borg_with_required_flags():
|
|||
insert_execute_command_mock(('borg', 'break-lock', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3',
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -28,7 +33,11 @@ def test_break_lock_calls_borg_with_remote_path_flags():
|
|||
insert_execute_command_mock(('borg', 'break-lock', '--remote-path', 'borg1', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3', remote_path='borg1',
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
|
@ -37,7 +46,22 @@ def test_break_lock_calls_borg_with_umask_flags():
|
|||
insert_execute_command_mock(('borg', 'break-lock', '--umask', '0770', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={'umask': '0770'}, local_borg_version='1.2.3',
|
||||
repository_path='repo',
|
||||
storage_config={'umask': '0770'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_break_lock_calls_borg_with_log_json_flags():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'break-lock', '--log-json', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -46,7 +70,10 @@ def test_break_lock_calls_borg_with_lock_wait_flags():
|
|||
insert_execute_command_mock(('borg', 'break-lock', '--lock-wait', '5', 'repo'))
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={'lock_wait': '5'}, local_borg_version='1.2.3',
|
||||
repository_path='repo',
|
||||
storage_config={'lock_wait': '5'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -56,7 +83,10 @@ def test_break_lock_with_log_info_calls_borg_with_info_parameter():
|
|||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3',
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -66,5 +96,8 @@ def test_break_lock_with_log_debug_calls_borg_with_debug_flags():
|
|||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.break_lock(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3',
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -79,7 +79,12 @@ def test_parse_frequency_parses_into_timedeltas(frequency, expected_result):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'frequency', ('sometime', 'x days', '3 decades',),
|
||||
'frequency',
|
||||
(
|
||||
'sometime',
|
||||
'x days',
|
||||
'3 decades',
|
||||
),
|
||||
)
|
||||
def test_parse_frequency_raises_on_parse_error(frequency):
|
||||
with pytest.raises(ValueError):
|
||||
|
@ -91,7 +96,7 @@ def test_filter_checks_on_frequency_without_config_uses_default_checks():
|
|||
module.datetime.timedelta(weeks=4)
|
||||
)
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
flexmock(module).should_receive('read_check_time').and_return(None)
|
||||
flexmock(module).should_receive('probe_for_check_time').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
location_config={},
|
||||
|
@ -99,6 +104,7 @@ def test_filter_checks_on_frequency_without_config_uses_default_checks():
|
|||
borg_repository_id='repo',
|
||||
checks=('repository', 'archives'),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
) == ('repository', 'archives')
|
||||
|
||||
|
||||
|
@ -121,6 +127,7 @@ def test_filter_checks_on_frequency_retains_check_without_frequency():
|
|||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
|
@ -129,7 +136,7 @@ def test_filter_checks_on_frequency_retains_check_with_elapsed_frequency():
|
|||
module.datetime.timedelta(hours=1)
|
||||
)
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
flexmock(module).should_receive('read_check_time').and_return(
|
||||
flexmock(module).should_receive('probe_for_check_time').and_return(
|
||||
module.datetime.datetime(year=module.datetime.MINYEAR, month=1, day=1)
|
||||
)
|
||||
|
||||
|
@ -139,6 +146,7 @@ def test_filter_checks_on_frequency_retains_check_with_elapsed_frequency():
|
|||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
|
@ -147,7 +155,7 @@ def test_filter_checks_on_frequency_retains_check_with_missing_check_time_file()
|
|||
module.datetime.timedelta(hours=1)
|
||||
)
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
flexmock(module).should_receive('read_check_time').and_return(None)
|
||||
flexmock(module).should_receive('probe_for_check_time').and_return(None)
|
||||
|
||||
assert module.filter_checks_on_frequency(
|
||||
location_config={},
|
||||
|
@ -155,6 +163,7 @@ def test_filter_checks_on_frequency_retains_check_with_missing_check_time_file()
|
|||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
|
@ -163,7 +172,9 @@ def test_filter_checks_on_frequency_skips_check_with_unelapsed_frequency():
|
|||
module.datetime.timedelta(hours=1)
|
||||
)
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
flexmock(module).should_receive('read_check_time').and_return(module.datetime.datetime.now())
|
||||
flexmock(module).should_receive('probe_for_check_time').and_return(
|
||||
module.datetime.datetime.now()
|
||||
)
|
||||
|
||||
assert (
|
||||
module.filter_checks_on_frequency(
|
||||
|
@ -172,6 +183,7 @@ def test_filter_checks_on_frequency_skips_check_with_unelapsed_frequency():
|
|||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=False,
|
||||
archives_check_id='1234',
|
||||
)
|
||||
== ()
|
||||
)
|
||||
|
@ -184,41 +196,189 @@ def test_filter_checks_on_frequency_restains_check_with_unelapsed_frequency_and_
|
|||
borg_repository_id='repo',
|
||||
checks=('archives',),
|
||||
force=True,
|
||||
archives_check_id='1234',
|
||||
) == ('archives',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_returns_flag():
|
||||
def test_make_archive_filter_flags_with_default_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',))
|
||||
flags = module.make_archive_filter_flags(
|
||||
'1.2.3',
|
||||
{},
|
||||
('repository', 'archives'),
|
||||
prefix='foo',
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_all_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags(
|
||||
'1.2.3',
|
||||
{},
|
||||
('repository', 'archives', 'extract'),
|
||||
prefix='foo',
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_all_checks_and_prefix_without_borg_features_returns_glob_archives_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags(
|
||||
'1.2.3',
|
||||
{},
|
||||
('repository', 'archives', 'extract'),
|
||||
prefix='foo',
|
||||
)
|
||||
|
||||
assert flags == ('--glob-archives', 'foo*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_archives_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('archives',), check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_data_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('data',), check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_repository_check_and_last_omits_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('repository',), check_last=3)
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_default_checks_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('repository', 'archives'), check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_archives_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('archives',), prefix='foo-')
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_data_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('data',), prefix='foo-')
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_archives_check_and_empty_prefix_uses_archive_name_format_instead():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
|
||||
flags = module.make_archive_filter_flags(
|
||||
'1.2.3', {'archive_name_format': 'bar-{now}'}, ('archives',), prefix='' # noqa: FS003
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:bar-*')
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_archives_check_and_none_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('archives',), prefix=None)
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_repository_check_and_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('repository',), prefix='foo-')
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
||||
def test_make_archive_filter_flags_with_default_checks_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_archive_filter_flags('1.2.3', {}, ('repository', 'archives'), prefix='foo-')
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_archives_check_id_with_flags_returns_a_value_and_does_not_raise():
|
||||
assert module.make_archives_check_id(('--match-archives', 'sh:foo-*'))
|
||||
|
||||
|
||||
def test_make_archives_check_id_with_empty_flags_returns_none():
|
||||
assert module.make_archives_check_id(()) is None
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_returns_flag():
|
||||
flags = module.make_check_flags(('repository',), ())
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_returns_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',))
|
||||
flags = module.make_check_flags(('archives',), ())
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archive_filtler_flags_includes_those_flags():
|
||||
flags = module.make_check_flags(('archives',), ('--match-archives', 'sh:foo-*'))
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_returns_flag_and_implies_archives():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',))
|
||||
flags = module.make_check_flags(('data',), ())
|
||||
|
||||
assert flags == ('--archives-only', '--verify-data',)
|
||||
assert flags == (
|
||||
'--archives-only',
|
||||
'--verify-data',
|
||||
)
|
||||
|
||||
|
||||
def test_make_check_flags_with_extract_omits_extract_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('extract',))
|
||||
flags = module.make_check_flags(('extract',), ())
|
||||
|
||||
assert flags == ()
|
||||
|
||||
|
@ -227,134 +387,67 @@ def test_make_check_flags_with_repository_and_data_checks_does_not_return_reposi
|
|||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'data',))
|
||||
flags = module.make_check_flags(
|
||||
(
|
||||
'repository',
|
||||
'data',
|
||||
),
|
||||
(),
|
||||
)
|
||||
|
||||
assert flags == ('--verify-data',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), prefix='foo',)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_and_prefix_returns_default_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', {}, ('repository', 'archives', 'extract'), prefix='foo',
|
||||
def test_make_check_time_path_with_borgmatic_source_directory_includes_it():
|
||||
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
||||
'/home/user/.borgmatic'
|
||||
)
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_all_checks_and_prefix_without_borg_features_returns_glob_archives_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', {}, ('repository', 'archives', 'extract'), prefix='foo',
|
||||
assert (
|
||||
module.make_check_time_path(
|
||||
{'borgmatic_source_directory': '~/.borgmatic'}, '1234', 'archives', '5678'
|
||||
)
|
||||
== '/home/user/.borgmatic/checks/1234/archives/5678'
|
||||
)
|
||||
|
||||
assert flags == ('--glob-archives', 'foo*')
|
||||
|
||||
def test_make_check_time_path_without_borgmatic_source_directory_uses_default():
|
||||
flexmock(module.os.path).should_receive('expanduser').with_args(
|
||||
module.state.DEFAULT_BORGMATIC_SOURCE_DIRECTORY
|
||||
).and_return('/home/user/.borgmatic')
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), check_last=3)
|
||||
|
||||
assert flags == ('--archives-only', '--last', '3')
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',), check_last=3)
|
||||
|
||||
assert flags == ('--archives-only', '--last', '3', '--verify-data')
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_last_omits_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',), check_last=3)
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_last_includes_last_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), check_last=3)
|
||||
|
||||
assert flags == ('--last', '3')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), prefix='foo-')
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*')
|
||||
|
||||
|
||||
def test_make_check_flags_with_data_check_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('data',), prefix='foo-')
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:foo-*', '--verify-data')
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_empty_prefix_uses_archive_name_format_instead():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, 'bar-{now}', '1.2.3' # noqa: FS003
|
||||
).and_return(('--match-archives', 'sh:bar-*'))
|
||||
|
||||
flags = module.make_check_flags(
|
||||
'1.2.3', {'archive_name_format': 'bar-{now}'}, ('archives',), prefix='' # noqa: FS003
|
||||
assert (
|
||||
module.make_check_time_path({}, '1234', 'archives', '5678')
|
||||
== '/home/user/.borgmatic/checks/1234/archives/5678'
|
||||
)
|
||||
|
||||
assert flags == ('--archives-only', '--match-archives', 'sh:bar-*')
|
||||
|
||||
def test_make_check_time_path_with_archives_check_and_no_archives_check_id_defaults_to_all():
|
||||
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
||||
'/home/user/.borgmatic'
|
||||
)
|
||||
|
||||
assert (
|
||||
module.make_check_time_path(
|
||||
{'borgmatic_source_directory': '~/.borgmatic'},
|
||||
'1234',
|
||||
'archives',
|
||||
)
|
||||
== '/home/user/.borgmatic/checks/1234/archives/all'
|
||||
)
|
||||
|
||||
|
||||
def test_make_check_flags_with_archives_check_and_none_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
def test_make_check_time_path_with_repositories_check_ignores_archives_check_id():
|
||||
flexmock(module.os.path).should_receive('expanduser').with_args('~/.borgmatic').and_return(
|
||||
'/home/user/.borgmatic'
|
||||
)
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('archives',), prefix=None)
|
||||
|
||||
assert flags == ('--archives-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_repository_check_and_prefix_omits_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository',), prefix='foo-')
|
||||
|
||||
assert flags == ('--repository-only',)
|
||||
|
||||
|
||||
def test_make_check_flags_with_default_checks_and_prefix_includes_match_archives_flag():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
|
||||
flags = module.make_check_flags('1.2.3', {}, ('repository', 'archives'), prefix='foo-')
|
||||
|
||||
assert flags == ('--match-archives', 'sh:foo-*')
|
||||
assert (
|
||||
module.make_check_time_path(
|
||||
{'borgmatic_source_directory': '~/.borgmatic'}, '1234', 'repository', '5678'
|
||||
)
|
||||
== '/home/user/.borgmatic/checks/1234/repository'
|
||||
)
|
||||
|
||||
|
||||
def test_read_check_time_does_not_raise():
|
||||
|
@ -369,14 +462,135 @@ def test_read_check_time_on_missing_file_does_not_raise():
|
|||
assert module.read_check_time('/path') is None
|
||||
|
||||
|
||||
def test_probe_for_check_time_uses_maximum_of_multiple_check_times():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/5678'
|
||||
).and_return('~/.borgmatic/checks/1234/archives/all')
|
||||
flexmock(module).should_receive('read_check_time').and_return(1).and_return(2)
|
||||
|
||||
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 2
|
||||
|
||||
|
||||
def test_probe_for_check_time_deduplicates_identical_check_time_paths():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/5678'
|
||||
).and_return('~/.borgmatic/checks/1234/archives/5678')
|
||||
flexmock(module).should_receive('read_check_time').and_return(1).once()
|
||||
|
||||
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 1
|
||||
|
||||
|
||||
def test_probe_for_check_time_skips_none_check_time():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/5678'
|
||||
).and_return('~/.borgmatic/checks/1234/archives/all')
|
||||
flexmock(module).should_receive('read_check_time').and_return(None).and_return(2)
|
||||
|
||||
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 2
|
||||
|
||||
|
||||
def test_probe_for_check_time_uses_single_check_time():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/5678'
|
||||
).and_return('~/.borgmatic/checks/1234/archives/all')
|
||||
flexmock(module).should_receive('read_check_time').and_return(1).and_return(None)
|
||||
|
||||
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) == 1
|
||||
|
||||
|
||||
def test_probe_for_check_time_returns_none_when_no_check_time_found():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/5678'
|
||||
).and_return('~/.borgmatic/checks/1234/archives/all')
|
||||
flexmock(module).should_receive('read_check_time').and_return(None).and_return(None)
|
||||
|
||||
assert module.probe_for_check_time(flexmock(), flexmock(), flexmock(), flexmock()) is None
|
||||
|
||||
|
||||
def test_upgrade_check_times_renames_old_check_paths_to_all():
|
||||
base_path = '~/.borgmatic/checks/1234'
|
||||
flexmock(module).should_receive('make_check_time_path').with_args(
|
||||
object, object, 'archives', 'all'
|
||||
).and_return(f'{base_path}/archives/all')
|
||||
flexmock(module).should_receive('make_check_time_path').with_args(
|
||||
object, object, 'data', 'all'
|
||||
).and_return(f'{base_path}/data/all')
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return(
|
||||
True
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(
|
||||
f'{base_path}/archives.temp'
|
||||
).and_return(False)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return(
|
||||
False
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(
|
||||
f'{base_path}/data.temp'
|
||||
).and_return(False)
|
||||
flexmock(module.os).should_receive('rename').with_args(
|
||||
f'{base_path}/archives', f'{base_path}/archives.temp'
|
||||
).once()
|
||||
flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/archives').once()
|
||||
flexmock(module.os).should_receive('rename').with_args(
|
||||
f'{base_path}/archives.temp', f'{base_path}/archives/all'
|
||||
).once()
|
||||
|
||||
module.upgrade_check_times(flexmock(), flexmock())
|
||||
|
||||
|
||||
def test_upgrade_check_times_skips_missing_check_paths():
|
||||
flexmock(module).should_receive('make_check_time_path').and_return(
|
||||
'~/.borgmatic/checks/1234/archives/all'
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').and_return(False)
|
||||
flexmock(module.os).should_receive('rename').never()
|
||||
flexmock(module.os).should_receive('mkdir').never()
|
||||
|
||||
module.upgrade_check_times(flexmock(), flexmock())
|
||||
|
||||
|
||||
def test_upgrade_check_times_renames_stale_temporary_check_path():
|
||||
base_path = '~/.borgmatic/checks/1234'
|
||||
flexmock(module).should_receive('make_check_time_path').with_args(
|
||||
object, object, 'archives', 'all'
|
||||
).and_return(f'{base_path}/archives/all')
|
||||
flexmock(module).should_receive('make_check_time_path').with_args(
|
||||
object, object, 'data', 'all'
|
||||
).and_return(f'{base_path}/data/all')
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/archives').and_return(
|
||||
False
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(
|
||||
f'{base_path}/archives.temp'
|
||||
).and_return(True)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(f'{base_path}/data').and_return(
|
||||
False
|
||||
)
|
||||
flexmock(module.os.path).should_receive('isfile').with_args(
|
||||
f'{base_path}/data.temp'
|
||||
).and_return(False)
|
||||
flexmock(module.os).should_receive('rename').with_args(
|
||||
f'{base_path}/archives', f'{base_path}/archives.temp'
|
||||
).and_raise(FileNotFoundError)
|
||||
flexmock(module.os).should_receive('mkdir').with_args(f'{base_path}/archives').once()
|
||||
flexmock(module.os).should_receive('rename').with_args(
|
||||
f'{base_path}/archives.temp', f'{base_path}/archives/all'
|
||||
).once()
|
||||
|
||||
module.upgrade_check_times(flexmock(), flexmock())
|
||||
|
||||
|
||||
def test_check_archives_with_progress_calls_borg_with_progress_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -395,6 +609,7 @@ def test_check_archives_with_progress_calls_borg_with_progress_parameter():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
)
|
||||
|
||||
|
@ -402,11 +617,14 @@ def test_check_archives_with_progress_calls_borg_with_progress_parameter():
|
|||
def test_check_archives_with_repair_calls_borg_with_repair_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -425,6 +643,7 @@ def test_check_archives_with_repair_calls_borg_with_repair_parameter():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repair=True,
|
||||
)
|
||||
|
||||
|
@ -441,14 +660,15 @@ def test_check_archives_with_repair_calls_borg_with_repair_parameter():
|
|||
def test_check_archives_calls_borg_with_parameters(checks):
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
|
@ -460,6 +680,7 @@ def test_check_archives_calls_borg_with_parameters(checks):
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -467,11 +688,14 @@ def test_check_archives_with_json_error_raises():
|
|||
checks = ('archives',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"unexpected": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_archives(
|
||||
|
@ -480,6 +704,7 @@ def test_check_archives_with_json_error_raises():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -487,9 +712,12 @@ def test_check_archives_with_missing_json_keys_raises():
|
|||
checks = ('archives',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return('{invalid JSON')
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_archives(
|
||||
|
@ -498,6 +726,7 @@ def test_check_archives_with_missing_json_keys_raises():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -505,11 +734,14 @@ def test_check_archives_with_extract_check_calls_extract_only():
|
|||
checks = ('extract',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').never()
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
flexmock(module.extract).should_receive('extract_last_archive_dry_run').once()
|
||||
|
@ -522,17 +754,21 @@ def test_check_archives_with_extract_check_calls_extract_only():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_info_calls_borg_with_info_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
@ -546,17 +782,21 @@ def test_check_archives_with_log_info_calls_borg_with_info_parameter():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
@ -570,16 +810,20 @@ def test_check_archives_with_log_debug_calls_borg_with_debug_parameter():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_without_any_checks_bails():
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(())
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(())
|
||||
insert_execute_command_never()
|
||||
|
||||
module.check_archives(
|
||||
|
@ -588,6 +832,7 @@ def test_check_archives_without_any_checks_bails():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -595,14 +840,15 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
|
|||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1', 'check', 'repo'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
|
@ -614,6 +860,7 @@ def test_check_archives_with_local_path_calls_borg_via_local_path():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -622,14 +869,15 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
|
|||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', {}, checks, check_last, prefix=None,
|
||||
).and_return(())
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_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'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
|
@ -641,23 +889,54 @@ def test_check_archives_with_remote_path_calls_borg_with_remote_path_parameters(
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_log_json_calls_borg_with_log_json_parameters():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
storage_config = {}
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_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'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
flexmock(module).should_receive('write_check_time')
|
||||
|
||||
module.check_archives(
|
||||
repository_path='repo',
|
||||
location_config={},
|
||||
storage_config=storage_config,
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
checks = ('repository',)
|
||||
check_last = flexmock()
|
||||
storage_config = {'lock_wait': 5}
|
||||
consistency_config = {'check_last': check_last}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', storage_config, checks, check_last, None,
|
||||
).and_return(())
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_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'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
|
@ -669,6 +948,7 @@ def test_check_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|||
storage_config=storage_config,
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -677,14 +957,15 @@ def test_check_archives_with_retention_prefix():
|
|||
check_last = flexmock()
|
||||
prefix = 'foo-'
|
||||
consistency_config = {'check_last': check_last, 'prefix': prefix}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(
|
||||
'1.2.3', {}, checks, check_last, prefix
|
||||
).and_return(())
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').with_args(checks, ()).and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', 'repo'))
|
||||
flexmock(module).should_receive('make_check_time_path')
|
||||
|
@ -696,17 +977,21 @@ def test_check_archives_with_retention_prefix():
|
|||
storage_config={},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_check_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
||||
checks = ('repository',)
|
||||
consistency_config = {'check_last': None}
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module.rinfo).should_receive('display_repository_info').and_return(
|
||||
'{"repository": {"id": "repo"}}'
|
||||
)
|
||||
flexmock(module).should_receive('upgrade_check_times')
|
||||
flexmock(module).should_receive('parse_checks')
|
||||
flexmock(module).should_receive('make_archive_filter_flags').and_return(())
|
||||
flexmock(module).should_receive('make_archives_check_id').and_return(None)
|
||||
flexmock(module).should_receive('filter_checks_on_frequency').and_return(checks)
|
||||
flexmock(module).should_receive('make_check_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'check', '--extra', '--options', 'repo'))
|
||||
|
@ -719,4 +1004,5 @@ def test_check_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|||
storage_config={'extra_borg_options': {'check': '--extra --options'}},
|
||||
consistency_config=consistency_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -25,7 +25,11 @@ def test_compact_segments_calls_borg_with_parameters():
|
|||
insert_execute_command_mock(COMPACT_COMMAND + ('repo',), logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False, repository_path='repo', storage_config={}, local_borg_version='1.2.3'
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -35,7 +39,11 @@ def test_compact_segments_with_log_info_calls_borg_with_info_parameter():
|
|||
insert_logging_mock(logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3', dry_run=False
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
|
@ -45,7 +53,11 @@ def test_compact_segments_with_log_debug_calls_borg_with_debug_parameter():
|
|||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
module.compact_segments(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3', dry_run=False
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
dry_run=False,
|
||||
)
|
||||
|
||||
|
||||
|
@ -53,7 +65,11 @@ def test_compact_segments_with_dry_run_skips_borg_call():
|
|||
flexmock(module).should_receive('execute_command').never()
|
||||
|
||||
module.compact_segments(
|
||||
repository_path='repo', storage_config={}, local_borg_version='1.2.3', dry_run=True
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
dry_run=True,
|
||||
)
|
||||
|
||||
|
||||
|
@ -66,6 +82,7 @@ def test_compact_segments_with_local_path_calls_borg_via_local_path():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -79,6 +96,7 @@ def test_compact_segments_with_remote_path_calls_borg_with_remote_path_parameter
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -92,6 +110,7 @@ def test_compact_segments_with_progress_calls_borg_with_progress_parameter():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
)
|
||||
|
||||
|
@ -105,6 +124,7 @@ def test_compact_segments_with_cleanup_commits_calls_borg_with_cleanup_commits_p
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
cleanup_commits=True,
|
||||
)
|
||||
|
||||
|
@ -118,6 +138,7 @@ def test_compact_segments_with_threshold_calls_borg_with_threshold_parameter():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
threshold=20,
|
||||
)
|
||||
|
||||
|
@ -132,6 +153,20 @@ def test_compact_segments_with_umask_calls_borg_with_umask_parameters():
|
|||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_compact_segments_with_log_json_calls_borg_with_log_json_parameters():
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(COMPACT_COMMAND + ('--log-json', 'repo'), logging.INFO)
|
||||
|
||||
module.compact_segments(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -145,6 +180,7 @@ def test_compact_segments_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -157,4 +193,5 @@ def test_compact_segments_with_extra_borg_options_calls_borg_with_extra_options(
|
|||
repository_path='repo',
|
||||
storage_config={'extra_borg_options': {'compact': '--extra --options'}},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -492,6 +492,7 @@ def test_create_archive_calls_borg_with_parameters():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -535,6 +536,7 @@ def test_create_archive_calls_borg_with_environment():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -580,6 +582,7 @@ def test_create_archive_with_patterns_calls_borg_with_patterns_including_convert
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -625,6 +628,7 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -668,6 +672,7 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -708,6 +713,7 @@ def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
json=True,
|
||||
)
|
||||
|
||||
|
@ -752,6 +758,7 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -792,6 +799,7 @@ def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
json=True,
|
||||
)
|
||||
|
||||
|
@ -835,6 +843,7 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -880,6 +889,7 @@ def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_paramete
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stats=True,
|
||||
)
|
||||
|
||||
|
@ -923,6 +933,7 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
|
|||
},
|
||||
storage_config={'checkpoint_interval': 600},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -965,6 +976,7 @@ def test_create_archive_with_checkpoint_volume_calls_borg_with_checkpoint_volume
|
|||
},
|
||||
storage_config={'checkpoint_volume': 1024},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1007,6 +1019,7 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
|
|||
},
|
||||
storage_config={'chunker_params': '1,2,3,4'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1049,11 +1062,13 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
|
|||
},
|
||||
storage_config={'compression': 'rle'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'feature_available,option_flag', ((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
|
||||
'feature_available,option_flag',
|
||||
((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
|
||||
)
|
||||
def test_create_archive_with_upload_rate_limit_calls_borg_with_upload_ratelimit_parameters(
|
||||
feature_available, option_flag
|
||||
|
@ -1096,6 +1111,7 @@ def test_create_archive_with_upload_rate_limit_calls_borg_with_upload_ratelimit_
|
|||
},
|
||||
storage_config={'upload_rate_limit': 100},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1141,6 +1157,7 @@ def test_create_archive_with_working_directory_calls_borg_with_working_directory
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1184,11 +1201,13 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner')),
|
||||
'feature_available,option_flag',
|
||||
((True, '--numeric-ids'), (False, '--numeric-owner')),
|
||||
)
|
||||
def test_create_archive_with_numeric_ids_calls_borg_with_numeric_ids_parameter(
|
||||
feature_available, option_flag
|
||||
|
@ -1232,6 +1251,7 @@ def test_create_archive_with_numeric_ids_calls_borg_with_numeric_ids_parameter(
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1285,12 +1305,18 @@ def test_create_archive_with_read_special_calls_borg_with_read_special_parameter
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'option_name,option_value',
|
||||
(('ctime', True), ('ctime', False), ('birthtime', True), ('birthtime', False),),
|
||||
(
|
||||
('ctime', True),
|
||||
('ctime', False),
|
||||
('birthtime', True),
|
||||
('birthtime', False),
|
||||
),
|
||||
)
|
||||
def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
|
||||
option_name, option_value
|
||||
|
@ -1335,6 +1361,7 @@ def test_create_archive_with_basic_option_calls_borg_with_corresponding_paramete
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1389,6 +1416,7 @@ def test_create_archive_with_atime_option_calls_borg_with_corresponding_paramete
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1443,6 +1471,7 @@ def test_create_archive_with_flags_option_calls_borg_with_corresponding_paramete
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1486,6 +1515,7 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1528,6 +1558,7 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -1571,6 +1602,7 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -1614,6 +1646,50 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
|||
},
|
||||
storage_config={'umask': 740},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_create_archive_with_log_json_calls_borg_with_log_json_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
||||
flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
|
||||
flexmock(module).should_receive('map_directories_to_devices').and_return({})
|
||||
flexmock(module).should_receive('expand_directories').and_return(())
|
||||
flexmock(module).should_receive('pattern_root_directories').and_return([])
|
||||
flexmock(module.os.path).should_receive('expanduser').and_raise(TypeError)
|
||||
flexmock(module).should_receive('expand_home_directories').and_return(())
|
||||
flexmock(module).should_receive('write_pattern_file').and_return(None)
|
||||
flexmock(module).should_receive('make_list_filter_flags').and_return('FOO')
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module).should_receive('ensure_files_readable')
|
||||
flexmock(module).should_receive('make_pattern_flags').and_return(())
|
||||
flexmock(module).should_receive('make_exclude_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
(f'repo::{DEFAULT_ARCHIVE_NAME}',)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'create', '--log-json') + REPO_ARCHIVE_WITH_PATHS,
|
||||
output_log_level=logging.INFO,
|
||||
output_file=None,
|
||||
borg_local_path='borg',
|
||||
working_directory=None,
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.create_archive(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
location_config={
|
||||
'source_directories': ['foo', 'bar'],
|
||||
'repositories': ['repo'],
|
||||
'exclude_patterns': None,
|
||||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1656,6 +1732,7 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|||
},
|
||||
storage_config={'lock_wait': 5},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -1698,6 +1775,7 @@ def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_answer_ou
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stats=True,
|
||||
)
|
||||
|
||||
|
@ -1741,6 +1819,7 @@ def test_create_archive_with_files_calls_borg_with_list_parameter_and_answer_out
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
list_files=True,
|
||||
)
|
||||
|
||||
|
@ -1766,7 +1845,12 @@ def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_para
|
|||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'create') + REPO_ARCHIVE_WITH_PATHS + ('--info', '--progress',),
|
||||
('borg', 'create')
|
||||
+ REPO_ARCHIVE_WITH_PATHS
|
||||
+ (
|
||||
'--info',
|
||||
'--progress',
|
||||
),
|
||||
output_log_level=logging.INFO,
|
||||
output_file=module.DO_NOT_CAPTURE,
|
||||
borg_local_path='borg',
|
||||
|
@ -1785,6 +1869,7 @@ def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_para
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
)
|
||||
|
||||
|
@ -1828,6 +1913,7 @@ def test_create_archive_with_progress_calls_borg_with_progress_parameter():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
)
|
||||
|
||||
|
@ -1888,6 +1974,7 @@ def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progr
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
stream_processes=processes,
|
||||
)
|
||||
|
@ -1952,6 +2039,7 @@ def test_create_archive_with_stream_processes_ignores_read_special_false_and_log
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stream_processes=processes,
|
||||
)
|
||||
|
||||
|
@ -2019,6 +2107,7 @@ def test_create_archive_with_stream_processes_adds_special_files_to_excludes():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stream_processes=processes,
|
||||
)
|
||||
|
||||
|
@ -2083,6 +2172,7 @@ def test_create_archive_with_stream_processes_and_read_special_does_not_add_spec
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stream_processes=processes,
|
||||
)
|
||||
|
||||
|
@ -2123,6 +2213,7 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
json=True,
|
||||
)
|
||||
|
||||
|
@ -2165,6 +2256,7 @@ def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter()
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
json=True,
|
||||
stats=True,
|
||||
)
|
||||
|
@ -2212,6 +2304,7 @@ def test_create_archive_with_source_directories_glob_expands():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2255,6 +2348,7 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2297,6 +2391,7 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2339,6 +2434,7 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
|||
},
|
||||
storage_config={'archive_name_format': 'ARCHIVE_NAME'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2382,6 +2478,7 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
|||
},
|
||||
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2425,6 +2522,7 @@ def test_create_archive_with_repository_accepts_borg_placeholders():
|
|||
},
|
||||
storage_config={'archive_name_format': 'Documents_{hostname}-{now}'}, # noqa: FS003
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2467,6 +2565,7 @@ def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
|
|||
},
|
||||
storage_config={'extra_borg_options': {'create': '--extra --options'}},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -2527,6 +2626,7 @@ def test_create_archive_with_stream_processes_calls_borg_with_processes_and_read
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
stream_processes=processes,
|
||||
)
|
||||
|
||||
|
@ -2538,7 +2638,7 @@ def test_create_archive_with_non_existent_directory_and_source_directories_must_
|
|||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('collect_borgmatic_source_directories').and_return([])
|
||||
flexmock(module.os.path).should_receive('exists').and_return(False)
|
||||
flexmock(module).should_receive('check_all_source_directories_exist').and_raise(ValueError)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.create_archive(
|
||||
|
@ -2552,4 +2652,28 @@ def test_create_archive_with_non_existent_directory_and_source_directories_must_
|
|||
},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_check_all_source_directories_exist_with_glob_and_tilde_directories():
|
||||
flexmock(module).should_receive('expand_directory').with_args('foo*').and_return(
|
||||
('foo', 'food')
|
||||
)
|
||||
flexmock(module).should_receive('expand_directory').with_args('~/bar').and_return(
|
||||
('/root/bar',)
|
||||
)
|
||||
flexmock(module.os.path).should_receive('exists').and_return(False)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('foo').and_return(True)
|
||||
flexmock(module.os.path).should_receive('exists').with_args('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*', '~/bar'])
|
||||
|
||||
|
||||
def test_check_all_source_directories_exist_with_non_existent_directory_raises():
|
||||
flexmock(module).should_receive('expand_directory').with_args('foo').and_return(('foo',))
|
||||
flexmock(module.os.path).should_receive('exists').and_return(False)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.check_all_source_directories_exist(['foo'])
|
||||
|
|
|
@ -38,6 +38,7 @@ def test_export_tar_archive_calls_borg_with_path_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -59,6 +60,7 @@ def test_export_tar_archive_calls_borg_with_local_path_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -81,6 +83,7 @@ def test_export_tar_archive_calls_borg_with_remote_path_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -103,6 +106,27 @@ def test_export_tar_archive_calls_borg_with_umask_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={'umask': '0770'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_export_tar_archive_calls_borg_with_log_json_parameter():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',)
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'export-tar', '--log-json', 'repo::archive', 'test.tar'))
|
||||
|
||||
module.export_tar_archive(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
paths=None,
|
||||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -124,6 +148,7 @@ def test_export_tar_archive_calls_borg_with_lock_wait_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={'lock_wait': '5'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -144,6 +169,7 @@ def test_export_tar_archive_with_log_info_calls_borg_with_info_parameter():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -166,6 +192,7 @@ def test_export_tar_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -185,6 +212,7 @@ def test_export_tar_archive_calls_borg_with_dry_run_parameter():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -206,6 +234,7 @@ def test_export_tar_archive_calls_borg_with_tar_filter_parameters():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
tar_filter='bzip2',
|
||||
)
|
||||
|
||||
|
@ -229,6 +258,7 @@ def test_export_tar_archive_calls_borg_with_list_parameter():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
list_files=True,
|
||||
)
|
||||
|
||||
|
@ -251,6 +281,7 @@ def test_export_tar_archive_calls_borg_with_strip_components_parameter():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
strip_components=5,
|
||||
)
|
||||
|
||||
|
@ -271,6 +302,7 @@ def test_export_tar_archive_skips_abspath_for_remote_repository_parameter():
|
|||
destination_path='test.tar',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -290,4 +322,5 @@ def test_export_tar_archive_calls_borg_with_stdout_destination_path():
|
|||
destination_path='-',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -11,7 +11,9 @@ from ..test_verbosity import insert_logging_mock
|
|||
def insert_execute_command_mock(command, working_directory=None):
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
command, working_directory=working_directory, extra_environment=None,
|
||||
command,
|
||||
working_directory=working_directory,
|
||||
extra_environment=None,
|
||||
).once()
|
||||
|
||||
|
||||
|
@ -23,7 +25,11 @@ def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
|
|||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={}, local_borg_version='1.2.3', repository_path='repo', lock_wait=None
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
|
@ -32,7 +38,11 @@ def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
|
|||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(('repo',))
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={}, local_borg_version='1.2.3', repository_path='repo', lock_wait=None
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
|
@ -45,7 +55,11 @@ def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_paramet
|
|||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={}, local_borg_version='1.2.3', repository_path='repo', lock_wait=None
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
|
@ -60,7 +74,11 @@ def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_param
|
|||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={}, local_borg_version='1.2.3', repository_path='repo', lock_wait=None
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
|
@ -74,13 +92,14 @@ def test_extract_last_archive_dry_run_calls_borg_via_local_path():
|
|||
module.extract_last_archive_dry_run(
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.rlist).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--remote-path', 'borg1', 'repo::archive')
|
||||
|
@ -92,13 +111,30 @@ def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
|||
module.extract_last_archive_dry_run(
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_log_json_flag():
|
||||
flexmock(module.rlist).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(('borg', 'extract', '--dry-run', '--log-json', 'repo::archive'))
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',)
|
||||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
repository_path='repo',
|
||||
lock_wait=None,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.rlist).should_receive('resolve_archive_name').and_return('archive')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--dry-run', '--lock-wait', '5', 'repo::archive')
|
||||
|
@ -108,17 +144,24 @@ def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
|
|||
)
|
||||
|
||||
module.extract_last_archive_dry_run(
|
||||
storage_config={}, local_borg_version='1.2.3', repository_path='repo', lock_wait=5
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
repository_path='repo',
|
||||
lock_wait=5,
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_path_parameters():
|
||||
def test_extract_archive_calls_borg_with_path_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
|
||||
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,
|
||||
|
@ -128,16 +171,20 @@ def test_extract_archive_calls_borg_with_path_parameters():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_remote_path_parameters():
|
||||
def test_extract_archive_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--remote-path', 'borg1', 'repo::archive'))
|
||||
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,
|
||||
|
@ -147,12 +194,17 @@ def test_extract_archive_calls_borg_with_remote_path_parameters():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner'),),
|
||||
'feature_available,option_flag',
|
||||
(
|
||||
(True, '--numeric-ids'),
|
||||
(False, '--numeric-owner'),
|
||||
),
|
||||
)
|
||||
def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available, option_flag):
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
|
@ -161,6 +213,9 @@ def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available
|
|||
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,
|
||||
|
@ -170,16 +225,20 @@ def test_extract_archive_calls_borg_with_numeric_ids_parameter(feature_available
|
|||
location_config={'numeric_ids': True},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_umask_parameters():
|
||||
def test_extract_archive_calls_borg_with_umask_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--umask', '0770', 'repo::archive'))
|
||||
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,
|
||||
|
@ -189,17 +248,41 @@ def test_extract_archive_calls_borg_with_umask_parameters():
|
|||
location_config={},
|
||||
storage_config={'umask': '0770'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
||||
def test_extract_archive_calls_borg_with_log_json_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--lock-wait', '5', 'repo::archive'))
|
||||
insert_execute_command_mock(('borg', 'extract', '--log-json', 'repo::archive'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',)
|
||||
)
|
||||
|
||||
module.extract_archive(
|
||||
dry_run=False,
|
||||
repository='repo',
|
||||
archive='archive',
|
||||
paths=None,
|
||||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(('borg', 'extract', '--lock-wait', '5', 'repo::archive'))
|
||||
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',
|
||||
|
@ -208,6 +291,7 @@ def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
|||
location_config={},
|
||||
storage_config={'lock_wait': '5'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -219,6 +303,9 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|||
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,
|
||||
|
@ -228,10 +315,11 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
||||
def test_extract_archive_with_log_debug_calls_borg_with_debug_flags():
|
||||
flexmock(module.os.path).should_receive('abspath').and_return('repo')
|
||||
insert_execute_command_mock(
|
||||
('borg', 'extract', '--debug', '--list', '--show-rc', 'repo::archive')
|
||||
|
@ -241,6 +329,9 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|||
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,
|
||||
|
@ -250,6 +341,7 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -260,6 +352,9 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|||
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=True,
|
||||
|
@ -269,6 +364,7 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -279,6 +375,9 @@ def test_extract_archive_calls_borg_with_destination_path():
|
|||
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,
|
||||
|
@ -288,6 +387,7 @@ def test_extract_archive_calls_borg_with_destination_path():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
destination_path='/dest',
|
||||
)
|
||||
|
||||
|
@ -299,6 +399,9 @@ def test_extract_archive_calls_borg_with_strip_components():
|
|||
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,
|
||||
|
@ -308,6 +411,7 @@ def test_extract_archive_calls_borg_with_strip_components():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
strip_components=5,
|
||||
)
|
||||
|
||||
|
@ -329,6 +433,9 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
|
|||
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,
|
||||
|
@ -338,6 +445,7 @@ def test_extract_archive_calls_borg_with_strip_components_calculated_from_all():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
strip_components='all',
|
||||
)
|
||||
|
||||
|
@ -348,6 +456,9 @@ def test_extract_archive_with_strip_components_all_and_no_paths_raises():
|
|||
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')
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
|
@ -359,6 +470,7 @@ def test_extract_archive_with_strip_components_all_and_no_paths_raises():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
strip_components='all',
|
||||
)
|
||||
|
||||
|
@ -376,6 +488,9 @@ def test_extract_archive_calls_borg_with_progress_parameter():
|
|||
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,
|
||||
|
@ -385,6 +500,7 @@ def test_extract_archive_calls_borg_with_progress_parameter():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
)
|
||||
|
||||
|
@ -401,6 +517,7 @@ def test_extract_archive_with_progress_and_extract_to_stdout_raises():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
progress=True,
|
||||
extract_to_stdout=True,
|
||||
)
|
||||
|
@ -421,6 +538,9 @@ def test_extract_archive_calls_borg_with_stdout_parameter_and_returns_process():
|
|||
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')
|
||||
|
||||
assert (
|
||||
module.extract_archive(
|
||||
|
@ -431,6 +551,7 @@ def test_extract_archive_calls_borg_with_stdout_parameter_and_returns_process():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
extract_to_stdout=True,
|
||||
)
|
||||
== process
|
||||
|
@ -441,12 +562,17 @@ def test_extract_archive_skips_abspath_for_remote_repository():
|
|||
flexmock(module.os.path).should_receive('abspath').never()
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'extract', 'server:repo::archive'), working_directory=None, extra_environment=None,
|
||||
('borg', 'extract', 'server:repo::archive'),
|
||||
working_directory=None,
|
||||
extra_environment=None,
|
||||
).once()
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('server:repo::archive',)
|
||||
)
|
||||
flexmock(module.borgmatic.config.validate).should_receive(
|
||||
'normalize_repository_path'
|
||||
).and_return('repo')
|
||||
|
||||
module.extract_archive(
|
||||
dry_run=False,
|
||||
|
@ -456,4 +582,5 @@ def test_extract_archive_skips_abspath_for_remote_repository():
|
|||
location_config={},
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -70,7 +70,11 @@ def test_make_repository_archive_flags_with_borg_features_separates_repository_a
|
|||
|
||||
assert module.make_repository_archive_flags(
|
||||
repository_path='repo', archive='archive', local_borg_version='1.2.3'
|
||||
) == ('--repo', 'repo', 'archive',)
|
||||
) == (
|
||||
'--repo',
|
||||
'repo',
|
||||
'archive',
|
||||
)
|
||||
|
||||
|
||||
def test_make_repository_archive_flags_with_borg_features_joins_repository_and_archive():
|
||||
|
@ -86,9 +90,24 @@ def test_make_repository_archive_flags_with_borg_features_joins_repository_and_a
|
|||
(
|
||||
(None, None, True, ()),
|
||||
(None, '', True, ()),
|
||||
('re:foo-.*', '{hostname}-{now}', True, ('--match-archives', 're:foo-.*'),), # noqa: FS003
|
||||
('sh:foo-*', '{hostname}-{now}', False, ('--glob-archives', 'foo-*'),), # noqa: FS003
|
||||
('foo-*', '{hostname}-{now}', False, ('--glob-archives', 'foo-*'),), # noqa: FS003
|
||||
(
|
||||
're:foo-.*',
|
||||
'{hostname}-{now}',
|
||||
True,
|
||||
('--match-archives', 're:foo-.*'),
|
||||
), # noqa: FS003
|
||||
(
|
||||
'sh:foo-*',
|
||||
'{hostname}-{now}',
|
||||
False,
|
||||
('--glob-archives', 'foo-*'),
|
||||
), # noqa: FS003
|
||||
(
|
||||
'foo-*',
|
||||
'{hostname}-{now}',
|
||||
False,
|
||||
('--glob-archives', 'foo-*'),
|
||||
), # noqa: FS003
|
||||
(
|
||||
None,
|
||||
'{hostname}-docs-{now}', # noqa: FS003
|
||||
|
|
|
@ -29,6 +29,7 @@ def test_display_archives_info_calls_borg_with_parameters():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -54,6 +55,7 @@ def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -69,7 +71,8 @@ def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_outpu
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'info', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'info', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
@ -77,6 +80,7 @@ def test_display_archives_info_with_log_info_and_json_suppresses_most_borg_outpu
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -105,6 +109,7 @@ def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -120,7 +125,8 @@ def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_outp
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'info', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'info', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
@ -128,6 +134,7 @@ def test_display_archives_info_with_log_debug_and_json_suppresses_most_borg_outp
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -145,13 +152,15 @@ def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'info', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'info', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
json_output = module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=True, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -179,6 +188,7 @@ def test_display_archives_info_with_archive_calls_borg_with_match_archives_param
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive='archive', json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -204,6 +214,7 @@ def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
@ -233,11 +244,41 @@ def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_para
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_log_json_calls_borg_with_log_json_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'info', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
|
@ -263,6 +304,7 @@ def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_paramete
|
|||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -291,6 +333,7 @@ def test_display_archives_info_transforms_prefix_into_match_archives_parameters(
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix='foo'),
|
||||
)
|
||||
|
||||
|
@ -319,6 +362,7 @@ def test_display_archives_info_prefers_prefix_over_archive_name_format():
|
|||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix='foo'),
|
||||
)
|
||||
|
||||
|
@ -344,6 +388,7 @@ def test_display_archives_info_transforms_archive_name_format_into_match_archive
|
|||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -372,6 +417,7 @@ def test_display_archives_with_match_archives_option_calls_borg_with_match_archi
|
|||
'match_archives': 'sh:foo-*',
|
||||
},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives=None),
|
||||
)
|
||||
|
||||
|
@ -397,6 +443,7 @@ def test_display_archives_with_match_archives_flag_calls_borg_with_match_archive
|
|||
repository_path='repo',
|
||||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(archive=None, json=False, prefix=None, match_archives='sh:foo-*'),
|
||||
)
|
||||
|
||||
|
@ -426,7 +473,58 @@ def test_display_archives_info_passes_through_arguments_to_borg(argument_name):
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=flexmock(
|
||||
archive=None, json=False, prefix=None, match_archives=None, **{argument_name: 'value'}
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_display_archives_info_with_date_based_matching_calls_borg_with_date_based_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '2.3.4'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
('--newer', '1d', '--newest', '1y', '--older', '1m', '--oldest', '1w')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
(
|
||||
'borg',
|
||||
'info',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
info_arguments = flexmock(
|
||||
archive=None,
|
||||
json=False,
|
||||
prefix=None,
|
||||
match_archives=None,
|
||||
newer='1d',
|
||||
newest='1y',
|
||||
older='1m',
|
||||
oldest='1w',
|
||||
)
|
||||
module.display_archives_info(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
info_arguments=info_arguments,
|
||||
)
|
||||
|
|
|
@ -20,6 +20,7 @@ def test_make_list_command_includes_log_info():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--info', 'repo')
|
||||
|
@ -36,6 +37,7 @@ def test_make_list_command_includes_json_but_not_info():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
@ -52,6 +54,7 @@ def test_make_list_command_includes_log_debug():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
||||
|
@ -68,6 +71,7 @@ def test_make_list_command_includes_json_but_not_debug():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
@ -83,11 +87,28 @@ def test_make_list_command_includes_json():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_log_json():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(('--log-json',))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_list_command(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_list_command_includes_lock_wait():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
||||
('--lock-wait', '5')
|
||||
|
@ -100,6 +121,7 @@ def test_make_list_command_includes_lock_wait():
|
|||
storage_config={'lock_wait': 5},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
||||
|
@ -117,6 +139,7 @@ def test_make_list_command_includes_archive():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive='archive', paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', 'repo::archive')
|
||||
|
@ -134,6 +157,7 @@ def test_make_list_command_includes_archive_and_path():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive='archive', paths=['var/lib'], json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', 'repo::archive', 'var/lib')
|
||||
|
@ -149,6 +173,7 @@ def test_make_list_command_includes_local_path():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -156,9 +181,13 @@ def test_make_list_command_includes_local_path():
|
|||
|
||||
|
||||
def test_make_list_command_includes_remote_path():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(
|
||||
('--remote-path', 'borg2')
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args(
|
||||
'remote-path', 'borg2'
|
||||
).and_return(('--remote-path', 'borg2'))
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
|
@ -167,6 +196,7 @@ def test_make_list_command_includes_remote_path():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -183,6 +213,7 @@ def test_make_list_command_includes_short():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=flexmock(archive=None, paths=None, json=False, short=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--short', 'repo')
|
||||
|
@ -221,6 +252,7 @@ def test_make_list_command_includes_additional_flags(argument_name):
|
|||
format=None,
|
||||
**{argument_name: 'value'},
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
||||
|
@ -263,10 +295,11 @@ def test_capture_archive_listing_does_not_raise():
|
|||
archive='archive',
|
||||
storage_config=flexmock(),
|
||||
local_borg_version=flexmock(),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_list_archive_calls_borg_with_parameters():
|
||||
def test_list_archive_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
|
@ -281,6 +314,7 @@ def test_list_archive_calls_borg_with_parameters():
|
|||
first=None,
|
||||
last=None,
|
||||
)
|
||||
global_arguments = flexmock(log_json=False)
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module).should_receive('make_list_command').with_args(
|
||||
|
@ -288,6 +322,7 @@ def test_list_archive_calls_borg_with_parameters():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
|
@ -305,6 +340,7 @@ def test_list_archive_calls_borg_with_parameters():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
|
||||
|
||||
|
@ -322,6 +358,7 @@ def test_list_archive_with_archive_and_json_errors():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -340,6 +377,7 @@ def test_list_archive_calls_borg_with_local_path():
|
|||
first=None,
|
||||
last=None,
|
||||
)
|
||||
global_arguments = flexmock(log_json=False)
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module).should_receive('make_list_command').with_args(
|
||||
|
@ -347,6 +385,7 @@ def test_list_archive_calls_borg_with_local_path():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg2',
|
||||
remote_path=None,
|
||||
).and_return(('borg2', 'list', 'repo::archive'))
|
||||
|
@ -364,6 +403,7 @@ def test_list_archive_calls_borg_with_local_path():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -387,7 +427,8 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
|
|||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.rlist).should_receive('make_rlist_command').and_return(('borg', 'list', 'repo'))
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', 'repo'), extra_environment=None,
|
||||
('borg', 'list', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('archive1\narchive2').once()
|
||||
flexmock(module).should_receive('make_list_command').and_return(
|
||||
('borg', 'list', 'repo::archive1')
|
||||
|
@ -412,6 +453,7 @@ def test_list_archive_calls_borg_multiple_times_with_find_paths():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -430,6 +472,7 @@ def test_list_archive_calls_borg_with_archive():
|
|||
first=None,
|
||||
last=None,
|
||||
)
|
||||
global_arguments = flexmock(log_json=False)
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module).should_receive('make_list_command').with_args(
|
||||
|
@ -437,6 +480,7 @@ def test_list_archive_calls_borg_with_archive():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
|
@ -454,6 +498,7 @@ def test_list_archive_calls_borg_with_archive():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
|
||||
|
||||
|
@ -484,6 +529,7 @@ def test_list_archive_without_archive_delegates_to_list_repository():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -514,16 +560,27 @@ def test_list_archive_with_borg_features_without_archive_delegates_to_list_repos
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
list_arguments=list_arguments,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'archive_filter_flag', ('prefix', 'match_archives', 'sort_by', 'first', 'last',),
|
||||
'archive_filter_flag',
|
||||
(
|
||||
'prefix',
|
||||
'match_archives',
|
||||
'sort_by',
|
||||
'first',
|
||||
'last',
|
||||
),
|
||||
)
|
||||
def test_list_archive_with_archive_ignores_archive_filter_flag(archive_filter_flag,):
|
||||
def test_list_archive_with_archive_ignores_archive_filter_flag(
|
||||
archive_filter_flag,
|
||||
):
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.logger).answer = lambda message: None
|
||||
global_arguments = flexmock(log_json=False)
|
||||
default_filter_flags = {
|
||||
'prefix': None,
|
||||
'match_archives': None,
|
||||
|
@ -543,6 +600,7 @@ def test_list_archive_with_archive_ignores_archive_filter_flag(archive_filter_fl
|
|||
list_arguments=argparse.Namespace(
|
||||
archive='archive', paths=None, json=False, find_paths=None, **default_filter_flags
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', 'repo::archive'))
|
||||
|
@ -562,11 +620,19 @@ def test_list_archive_with_archive_ignores_archive_filter_flag(archive_filter_fl
|
|||
list_arguments=argparse.Namespace(
|
||||
archive='archive', paths=None, json=False, find_paths=None, **altered_filter_flags
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'archive_filter_flag', ('prefix', 'match_archives', 'sort_by', 'first', 'last',),
|
||||
'archive_filter_flag',
|
||||
(
|
||||
'prefix',
|
||||
'match_archives',
|
||||
'sort_by',
|
||||
'first',
|
||||
'last',
|
||||
),
|
||||
)
|
||||
def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes_it_to_rlist(
|
||||
archive_filter_flag,
|
||||
|
@ -583,6 +649,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
|||
}
|
||||
altered_filter_flags = {**default_filter_flags, **{archive_filter_flag: 'foo'}}
|
||||
glob_paths = ('**/*foo.txt*/**',)
|
||||
global_arguments = flexmock(log_json=False)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
|
||||
flexmock(module.rlist).should_receive('make_rlist_command').with_args(
|
||||
|
@ -592,12 +659,14 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
|||
rlist_arguments=argparse.Namespace(
|
||||
repository='repo', short=True, format=None, json=None, **altered_filter_flags
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'rlist', '--repo', 'repo'))
|
||||
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'rlist', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'rlist', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('archive1\narchive2').once()
|
||||
|
||||
flexmock(module).should_receive('make_list_command').with_args(
|
||||
|
@ -614,6 +683,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
|||
find_paths=['foo.txt'],
|
||||
**default_filter_flags,
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', '--repo', 'repo', 'archive1'))
|
||||
|
@ -632,6 +702,7 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
|||
find_paths=['foo.txt'],
|
||||
**default_filter_flags,
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'list', '--repo', 'repo', 'archive2'))
|
||||
|
@ -665,4 +736,5 @@ def test_list_archive_with_find_paths_allows_archive_filter_flag_but_only_passes
|
|||
find_paths=['foo.txt'],
|
||||
**altered_filter_flags,
|
||||
),
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
|
|
|
@ -10,7 +10,9 @@ from ..test_verbosity import insert_logging_mock
|
|||
def insert_execute_command_mock(command):
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
command, borg_local_path='borg', extra_environment=None,
|
||||
command,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
).once()
|
||||
|
||||
|
||||
|
@ -19,34 +21,37 @@ def test_mount_archive_calls_borg_with_required_flags():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive=None,
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_with_borg_features_calls_borg_with_repository_and_match_archives_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
insert_execute_command_mock(
|
||||
('borg', 'mount', '--repo', 'repo', '--match-archives', 'archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -57,15 +62,14 @@ def test_mount_archive_without_archive_calls_borg_with_repository_flags_only():
|
|||
)
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -76,15 +80,16 @@ def test_mount_archive_calls_borg_with_path_flags():
|
|||
)
|
||||
insert_execute_command_mock(('borg', 'mount', 'repo::archive', '/mnt', 'path1', 'path2'))
|
||||
|
||||
mount_arguments = flexmock(
|
||||
mount_point='/mnt', options=None, paths=['path1', 'path2'], foreground=False
|
||||
)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=['path1', 'path2'],
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -97,15 +102,14 @@ def test_mount_archive_calls_borg_with_remote_path_flags():
|
|||
('borg', 'mount', '--remote-path', 'borg1', 'repo::archive', '/mnt')
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
@ -117,15 +121,32 @@ def test_mount_archive_calls_borg_with_umask_flags():
|
|||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--umask', '0770', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={'umask': '0770'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_calls_borg_with_log_json_flags():
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module.flags).should_receive('make_repository_archive_flags').and_return(
|
||||
('repo::archive',)
|
||||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--log-json', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
|
@ -136,15 +157,14 @@ def test_mount_archive_calls_borg_with_lock_wait_flags():
|
|||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '--lock-wait', '5', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={'lock_wait': '5'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -156,15 +176,14 @@ def test_mount_archive_with_log_info_calls_borg_with_info_parameter():
|
|||
insert_execute_command_mock(('borg', 'mount', '--info', 'repo::archive', '/mnt'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -176,15 +195,14 @@ def test_mount_archive_with_log_debug_calls_borg_with_debug_flags():
|
|||
insert_execute_command_mock(('borg', 'mount', '--debug', '--show-rc', 'repo::archive', '/mnt'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=False)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -201,15 +219,14 @@ def test_mount_archive_calls_borg_with_foreground_parameter():
|
|||
extra_environment=None,
|
||||
).once()
|
||||
|
||||
mount_arguments = flexmock(mount_point='/mnt', options=None, paths=None, foreground=True)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=True,
|
||||
options=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -220,13 +237,75 @@ def test_mount_archive_calls_borg_with_options_flags():
|
|||
)
|
||||
insert_execute_command_mock(('borg', 'mount', '-o', 'super_mount', 'repo::archive', '/mnt'))
|
||||
|
||||
mount_arguments = flexmock(
|
||||
mount_point='/mnt', options='super_mount', paths=None, foreground=False
|
||||
)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive='archive',
|
||||
mount_point='/mnt',
|
||||
paths=None,
|
||||
foreground=False,
|
||||
options='super_mount',
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_mount_archive_with_date_based_matching_calls_borg_with_date_based_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
(
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--match-archives',
|
||||
None,
|
||||
)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
(
|
||||
'borg',
|
||||
'mount',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--match-archives',
|
||||
None,
|
||||
'--repo',
|
||||
'repo',
|
||||
'/mnt',
|
||||
),
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
mount_arguments = flexmock(
|
||||
mount_point='/mnt',
|
||||
options=None,
|
||||
paths=None,
|
||||
foreground=False,
|
||||
newer='1d',
|
||||
newest='1y',
|
||||
older='1m',
|
||||
oldest='1w',
|
||||
)
|
||||
module.mount_archive(
|
||||
repository_path='repo',
|
||||
archive=None,
|
||||
mount_arguments=mount_arguments,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -110,23 +110,26 @@ def test_make_prune_flags_without_prefix_uses_archive_name_format_instead():
|
|||
PRUNE_COMMAND = ('borg', 'prune', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3')
|
||||
|
||||
|
||||
def test_prune_archives_calls_borg_with_parameters():
|
||||
def test_prune_archives_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('repo',), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_prune_archives_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
|
@ -134,16 +137,19 @@ def test_prune_archives_with_log_info_calls_borg_with_info_parameter():
|
|||
insert_execute_command_mock(PRUNE_COMMAND + ('--info', 'repo'), logging.INFO)
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
dry_run=False,
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||
def test_prune_archives_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
|
@ -151,28 +157,34 @@ def test_prune_archives_with_log_debug_calls_borg_with_debug_parameter():
|
|||
insert_execute_command_mock(PRUNE_COMMAND + ('--debug', '--show-rc', 'repo'), logging.INFO)
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
dry_run=False,
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_parameter():
|
||||
def test_prune_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--dry-run', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
dry_run=True,
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
|
@ -183,68 +195,78 @@ def test_prune_archives_with_local_path_calls_borg_via_local_path():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(('borg1',) + PRUNE_COMMAND[1:] + ('repo',), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
def test_prune_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--remote-path', 'borg1', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_stats_calls_borg_with_stats_parameter_and_answer_output_log_level():
|
||||
def test_prune_archives_with_stats_calls_borg_with_stats_flag_and_answer_output_log_level():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--stats', 'repo'), module.borgmatic.logger.ANSWER)
|
||||
|
||||
prune_arguments = flexmock(stats=True, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
stats=True,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_files_calls_borg_with_list_parameter_and_answer_output_log_level():
|
||||
def test_prune_archives_with_files_calls_borg_with_list_flag_and_answer_output_log_level():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--list', 'repo'), module.borgmatic.logger.ANSWER)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=True)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
list_archives=True,
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
|
||||
def test_prune_archives_with_umask_calls_borg_with_umask_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
storage_config = {'umask': '077'}
|
||||
|
@ -252,16 +274,38 @@ def test_prune_archives_with_umask_calls_borg_with_umask_parameters():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--umask', '077', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
def test_prune_archives_with_log_json_calls_borg_with_log_json_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--log-json', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
storage_config = {'lock_wait': 5}
|
||||
|
@ -269,12 +313,15 @@ def test_prune_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--lock-wait', '5', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config=storage_config,
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
|
@ -285,10 +332,77 @@ def test_prune_archives_with_extra_borg_options_calls_borg_with_extra_options():
|
|||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
insert_execute_command_mock(PRUNE_COMMAND + ('--extra', '--options', 'repo'), logging.INFO)
|
||||
|
||||
prune_arguments = flexmock(stats=False, list_archives=False)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={'extra_borg_options': {'prune': '--extra --options'}},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
||||
|
||||
def test_prune_archives_with_date_based_matching_calls_borg_with_date_based_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module).should_receive('make_prune_flags').and_return(BASE_PRUNE_FLAGS)
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
(
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--match-archives',
|
||||
None,
|
||||
)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
(
|
||||
'borg',
|
||||
'prune',
|
||||
'--keep-daily',
|
||||
'1',
|
||||
'--keep-weekly',
|
||||
'2',
|
||||
'--keep-monthly',
|
||||
'3',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--match-archives',
|
||||
None,
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
output_log_level=logging.INFO,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
prune_arguments = flexmock(
|
||||
stats=False, list_archives=False, newer='1d', newest='1y', older='1m', oldest='1w'
|
||||
)
|
||||
module.prune_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
retention_config=flexmock(),
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
prune_arguments=prune_arguments,
|
||||
)
|
||||
|
|
|
@ -36,13 +36,19 @@ def test_create_repository_calls_borg_with_flags():
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -51,13 +57,19 @@ def test_create_repository_with_dry_run_skips_borg_call():
|
|||
insert_rinfo_command_not_found_mock()
|
||||
flexmock(module).should_receive('execute_command').never()
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=True,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -65,7 +77,12 @@ def test_create_repository_with_dry_run_skips_borg_call():
|
|||
def test_create_repository_raises_for_borg_rcreate_error():
|
||||
insert_rinfo_command_not_found_mock()
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').and_raise(
|
||||
module.subprocess.CalledProcessError(2, 'borg rcreate')
|
||||
|
@ -77,6 +94,7 @@ def test_create_repository_raises_for_borg_rcreate_error():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -84,13 +102,19 @@ def test_create_repository_raises_for_borg_rcreate_error():
|
|||
def test_create_repository_skips_creation_when_repository_already_exists():
|
||||
insert_rinfo_command_found_mock()
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -106,6 +130,7 @@ def test_create_repository_raises_for_unknown_rinfo_command_error():
|
|||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -114,13 +139,19 @@ def test_create_repository_with_source_repository_calls_borg_with_other_repo_fla
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--other-repo', 'other.borg', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
source_repository='other.borg',
|
||||
)
|
||||
|
@ -130,13 +161,19 @@ def test_create_repository_with_copy_crypt_key_calls_borg_with_copy_crypt_key_fl
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--copy-crypt-key', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
copy_crypt_key=True,
|
||||
)
|
||||
|
@ -146,13 +183,19 @@ def test_create_repository_with_append_only_calls_borg_with_append_only_flag():
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--append-only', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
append_only=True,
|
||||
)
|
||||
|
@ -162,13 +205,19 @@ def test_create_repository_with_storage_quota_calls_borg_with_storage_quota_flag
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--storage-quota', '5G', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
storage_quota='5G',
|
||||
)
|
||||
|
@ -178,13 +227,19 @@ def test_create_repository_with_make_parent_dirs_calls_borg_with_make_parent_dir
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--make-parent-dirs', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
make_parent_dirs=True,
|
||||
)
|
||||
|
@ -195,13 +250,19 @@ def test_create_repository_with_log_info_calls_borg_with_info_flag():
|
|||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--info', '--repo', 'repo'))
|
||||
insert_logging_mock(logging.INFO)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -211,13 +272,61 @@ def test_create_repository_with_log_debug_calls_borg_with_debug_flag():
|
|||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--debug', '--repo', 'repo'))
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
||||
def test_create_repository_with_log_json_calls_borg_with_log_json_flag():
|
||||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--log-json', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
||||
def test_create_repository_with_lock_wait_calls_borg_with_lock_wait_flag():
|
||||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--lock-wait', '5', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={'lock_wait': 5},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
||||
|
@ -226,13 +335,19 @@ def test_create_repository_with_local_path_calls_borg_via_local_path():
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(('borg1',) + RCREATE_COMMAND[1:] + ('--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
local_path='borg1',
|
||||
)
|
||||
|
@ -242,13 +357,19 @@ def test_create_repository_with_remote_path_calls_borg_with_remote_path_flag():
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--remote-path', 'borg1', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
@ -258,12 +379,18 @@ def test_create_repository_with_extra_borg_options_calls_borg_with_extra_options
|
|||
insert_rinfo_command_not_found_mock()
|
||||
insert_rcreate_command_mock(RCREATE_COMMAND + ('--extra', '--options', '--repo', 'repo'))
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
|
||||
module.create_repository(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={'extra_borg_options': {'rcreate': '--extra --options'}},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
encryption_mode='repokey',
|
||||
)
|
||||
|
|
|
@ -7,11 +7,16 @@ from borgmatic.borg import rinfo as module
|
|||
from ..test_verbosity import insert_logging_mock
|
||||
|
||||
|
||||
def test_display_repository_info_calls_borg_with_parameters():
|
||||
def test_display_repository_info_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--repo', 'repo'),
|
||||
|
@ -25,6 +30,7 @@ def test_display_repository_info_calls_borg_with_parameters():
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -46,14 +52,20 @@ def test_display_repository_info_without_borg_features_calls_borg_with_info_sub_
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
|
||||
def test_display_repository_info_with_log_info_calls_borg_with_info_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--info', '--repo', 'repo'),
|
||||
|
@ -67,6 +79,7 @@ def test_display_repository_info_with_log_info_calls_borg_with_info_parameter():
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -74,10 +87,16 @@ def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_out
|
|||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
@ -86,16 +105,22 @@ def test_display_repository_info_with_log_info_and_json_suppresses_most_borg_out
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
|
||||
|
||||
def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter():
|
||||
def test_display_repository_info_with_log_debug_calls_borg_with_debug_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--debug', '--show-rc', '--repo', 'repo'),
|
||||
|
@ -110,6 +135,7 @@ def test_display_repository_info_with_log_debug_calls_borg_with_debug_parameter(
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -117,10 +143,16 @@ def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_ou
|
|||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
@ -129,19 +161,26 @@ def test_display_repository_info_with_log_debug_and_json_suppresses_most_borg_ou
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
|
||||
|
||||
def test_display_repository_info_with_json_calls_borg_with_json_parameter():
|
||||
def test_display_repository_info_with_json_calls_borg_with_json_flag():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'), extra_environment=None,
|
||||
('borg', 'rinfo', '--json', '--repo', 'repo'),
|
||||
extra_environment=None,
|
||||
).and_return('[]')
|
||||
|
||||
json_output = module.display_repository_info(
|
||||
|
@ -149,6 +188,7 @@ def test_display_repository_info_with_json_calls_borg_with_json_parameter():
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=True),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert json_output == '[]'
|
||||
|
@ -158,7 +198,12 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
|
|||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg1', 'rinfo', '--repo', 'repo'),
|
||||
|
@ -172,15 +217,21 @@ def test_display_repository_info_with_local_path_calls_borg_via_local_path():
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--remote-path', 'borg1', '--repo', 'repo'),
|
||||
|
@ -194,16 +245,49 @@ def test_display_repository_info_with_remote_path_calls_borg_with_remote_path_pa
|
|||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
def test_display_repository_info_with_log_json_calls_borg_with_log_json_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.display_repository_info(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
storage_config = {'lock_wait': 5}
|
||||
flexmock(module.feature).should_receive('available').and_return(True)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo',))
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(
|
||||
(
|
||||
'--repo',
|
||||
'repo',
|
||||
)
|
||||
)
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'rinfo', '--lock-wait', '5', '--repo', 'repo'),
|
||||
|
@ -217,4 +301,5 @@ def test_display_repository_info_with_lock_wait_calls_borg_with_lock_wait_parame
|
|||
storage_config=storage_config,
|
||||
local_borg_version='2.3.4',
|
||||
rinfo_arguments=flexmock(json=False),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
|
|
@ -20,48 +20,75 @@ def test_resolve_archive_name_passes_through_non_latest_archive_name():
|
|||
archive = 'myhost-2030-01-01T14:41:17.647620'
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name('repo', archive, storage_config={}, local_borg_version='1.2.3')
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
archive,
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
== archive
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_calls_borg_with_parameters():
|
||||
def test_resolve_archive_name_calls_borg_with_flags():
|
||||
expected_archive = 'archive-name'
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS, extra_environment=None,
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return(expected_archive + '\n')
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name('repo', 'latest', storage_config={}, local_borg_version='1.2.3')
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_with_log_info_calls_borg_without_info_parameter():
|
||||
def test_resolve_archive_name_with_log_info_calls_borg_without_info_flag():
|
||||
expected_archive = 'archive-name'
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS, extra_environment=None,
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return(expected_archive + '\n')
|
||||
insert_logging_mock(logging.INFO)
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name('repo', 'latest', storage_config={}, local_borg_version='1.2.3')
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_with_log_debug_calls_borg_without_debug_parameter():
|
||||
def test_resolve_archive_name_with_log_debug_calls_borg_without_debug_flag():
|
||||
expected_archive = 'archive-name'
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS, extra_environment=None,
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return(expected_archive + '\n')
|
||||
insert_logging_mock(logging.DEBUG)
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name('repo', 'latest', storage_config={}, local_borg_version='1.2.3')
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
@ -70,18 +97,24 @@ def test_resolve_archive_name_with_local_path_calls_borg_via_local_path():
|
|||
expected_archive = 'archive-name'
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg1', 'list') + BORG_LIST_LATEST_ARGUMENTS, extra_environment=None,
|
||||
('borg1', 'list') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return(expected_archive + '\n')
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name(
|
||||
'repo', 'latest', storage_config={}, local_borg_version='1.2.3', local_path='borg1'
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg1',
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||
def test_resolve_archive_name_with_remote_path_calls_borg_with_remote_path_flags():
|
||||
expected_archive = 'archive-name'
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
|
@ -91,7 +124,12 @@ def test_resolve_archive_name_with_remote_path_calls_borg_with_remote_path_param
|
|||
|
||||
assert (
|
||||
module.resolve_archive_name(
|
||||
'repo', 'latest', storage_config={}, local_borg_version='1.2.3', remote_path='borg1'
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg1',
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
@ -100,14 +138,42 @@ def test_resolve_archive_name_with_remote_path_calls_borg_with_remote_path_param
|
|||
def test_resolve_archive_name_without_archives_raises():
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS, extra_environment=None,
|
||||
('borg', 'list') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return('')
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.resolve_archive_name('repo', 'latest', storage_config={}, local_borg_version='1.2.3')
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||
def test_resolve_archive_name_with_log_json_calls_borg_with_log_json_flags():
|
||||
expected_archive = 'archive-name'
|
||||
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
('borg', 'list', '--log-json') + BORG_LIST_LATEST_ARGUMENTS,
|
||||
extra_environment=None,
|
||||
).and_return(expected_archive + '\n')
|
||||
|
||||
assert (
|
||||
module.resolve_archive_name(
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
||||
|
||||
def test_resolve_archive_name_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
expected_archive = 'archive-name'
|
||||
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
|
@ -118,7 +184,11 @@ def test_resolve_archive_name_with_lock_wait_calls_borg_with_lock_wait_parameter
|
|||
|
||||
assert (
|
||||
module.resolve_archive_name(
|
||||
'repo', 'latest', storage_config={'lock_wait': 'okay'}, local_borg_version='1.2.3'
|
||||
'repo',
|
||||
'latest',
|
||||
storage_config={'lock_wait': 'okay'},
|
||||
local_borg_version='1.2.3',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
== expected_archive
|
||||
)
|
||||
|
@ -140,6 +210,7 @@ def test_make_rlist_command_includes_log_info():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--info', 'repo')
|
||||
|
@ -161,6 +232,7 @@ def test_make_rlist_command_includes_json_but_not_info():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
@ -182,6 +254,7 @@ def test_make_rlist_command_includes_log_debug():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--debug', '--show-rc', 'repo')
|
||||
|
@ -203,6 +276,7 @@ def test_make_rlist_command_includes_json_but_not_debug():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
@ -223,11 +297,35 @@ def test_make_rlist_command_includes_json():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=True, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--json', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_includes_log_json():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
||||
('--log-json',)
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_rlist_command(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--log-json', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_includes_lock_wait():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(()).and_return(
|
||||
('--lock-wait', '5')
|
||||
|
@ -245,6 +343,7 @@ def test_make_rlist_command_includes_lock_wait():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--lock-wait', '5', 'repo')
|
||||
|
@ -265,6 +364,7 @@ def test_make_rlist_command_includes_local_path():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -288,6 +388,7 @@ def test_make_rlist_command_includes_remote_path():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -309,6 +410,7 @@ def test_make_rlist_command_transforms_prefix_into_match_archives():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix='foo'),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
@ -327,6 +429,7 @@ def test_make_rlist_command_prefers_prefix_over_archive_name_format():
|
|||
storage_config={'archive_name_format': 'bar-{now}'}, # noqa: FS003
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(archive=None, paths=None, json=False, prefix='foo'),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:foo*', 'repo')
|
||||
|
@ -347,6 +450,7 @@ def test_make_rlist_command_transforms_archive_name_format_into_match_archives()
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'sh:bar-*', 'repo')
|
||||
|
@ -367,6 +471,7 @@ def test_make_rlist_command_includes_short():
|
|||
rlist_arguments=flexmock(
|
||||
archive=None, paths=None, json=False, prefix=None, match_archives=None, short=True
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--short', 'repo')
|
||||
|
@ -374,7 +479,15 @@ def test_make_rlist_command_includes_short():
|
|||
|
||||
@pytest.mark.parametrize(
|
||||
'argument_name',
|
||||
('sort_by', 'first', 'last', 'exclude', 'exclude_from', 'pattern', 'patterns_from',),
|
||||
(
|
||||
'sort_by',
|
||||
'first',
|
||||
'last',
|
||||
'exclude',
|
||||
'exclude_from',
|
||||
'pattern',
|
||||
'patterns_from',
|
||||
),
|
||||
)
|
||||
def test_make_rlist_command_includes_additional_flags(argument_name):
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
|
@ -400,18 +513,21 @@ def test_make_rlist_command_includes_additional_flags(argument_name):
|
|||
format=None,
|
||||
**{argument_name: 'value'},
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--' + argument_name.replace('_', '-'), 'value', 'repo')
|
||||
|
||||
|
||||
def test_make_rlist_command_with_match_archives_calls_borg_with_match_archives_parameters():
|
||||
def test_make_rlist_command_with_match_archives_calls_borg_with_match_archives_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
'foo-*', None, '1.2.3',
|
||||
'foo-*',
|
||||
None,
|
||||
'1.2.3',
|
||||
).and_return(('--match-archives', 'foo-*'))
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
@ -429,15 +545,17 @@ def test_make_rlist_command_with_match_archives_calls_borg_with_match_archives_p
|
|||
find_paths=None,
|
||||
format=None,
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == ('borg', 'list', '--match-archives', 'foo-*', 'repo')
|
||||
|
||||
|
||||
def test_list_repository_calls_borg_with_parameters():
|
||||
def test_list_repository_calls_borg_with_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
rlist_arguments = argparse.Namespace(json=False)
|
||||
global_arguments = flexmock()
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
flexmock(module).should_receive('make_rlist_command').with_args(
|
||||
|
@ -445,6 +563,7 @@ def test_list_repository_calls_borg_with_parameters():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'rlist', 'repo'))
|
||||
|
@ -461,6 +580,7 @@ def test_list_repository_calls_borg_with_parameters():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
|
||||
|
||||
|
@ -468,6 +588,7 @@ def test_list_repository_with_json_returns_borg_output():
|
|||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
rlist_arguments = argparse.Namespace(json=True)
|
||||
global_arguments = flexmock()
|
||||
json_output = flexmock()
|
||||
|
||||
flexmock(module.feature).should_receive('available').and_return(False)
|
||||
|
@ -476,6 +597,7 @@ def test_list_repository_with_json_returns_borg_output():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=global_arguments,
|
||||
local_path='borg',
|
||||
remote_path=None,
|
||||
).and_return(('borg', 'rlist', 'repo'))
|
||||
|
@ -488,6 +610,50 @@ def test_list_repository_with_json_returns_borg_output():
|
|||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=rlist_arguments,
|
||||
global_arguments=global_arguments,
|
||||
)
|
||||
== json_output
|
||||
)
|
||||
|
||||
|
||||
def test_make_rlist_command_with_date_based_matching_calls_borg_with_date_based_flags():
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').with_args(
|
||||
None, None, '1.2.3'
|
||||
).and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
('--newer', '1d', '--newest', '1y', '--older', '1m', '--oldest', '1w')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('repo',))
|
||||
|
||||
command = module.make_rlist_command(
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='1.2.3',
|
||||
rlist_arguments=flexmock(
|
||||
archive=None,
|
||||
paths=None,
|
||||
json=False,
|
||||
prefix=None,
|
||||
match_archives=None,
|
||||
newer='1d',
|
||||
newest='1y',
|
||||
older='1m',
|
||||
oldest='1w',
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
assert command == (
|
||||
'borg',
|
||||
'list',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'repo',
|
||||
)
|
||||
|
|
|
@ -32,6 +32,7 @@ def test_transfer_archives_calls_borg_with_flags():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -62,6 +63,7 @@ def test_transfer_archives_with_dry_run_calls_borg_with_dry_run_flag():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -89,6 +91,7 @@ def test_transfer_archives_with_log_info_calls_borg_with_info_flag():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -117,6 +120,7 @@ def test_transfer_archives_with_log_debug_calls_borg_with_debug_flag():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -146,6 +150,7 @@ def test_transfer_archives_with_archive_calls_borg_with_match_archives_flag():
|
|||
transfer_arguments=flexmock(
|
||||
archive='archive', progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -175,6 +180,7 @@ def test_transfer_archives_with_match_archives_calls_borg_with_match_archives_fl
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives='sh:foo*', source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -204,6 +210,7 @@ def test_transfer_archives_with_archive_name_format_calls_borg_with_match_archiv
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -231,6 +238,7 @@ def test_transfer_archives_with_local_path_calls_borg_via_local_path():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
local_path='borg2',
|
||||
)
|
||||
|
||||
|
@ -262,10 +270,42 @@ def test_transfer_archives_with_remote_path_calls_borg_with_remote_path_flags():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
remote_path='borg2',
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_log_json_calls_borg_with_log_json_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags').with_args('log-json', True).and_return(
|
||||
('--log-json',)
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(())
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
('borg', 'transfer', '--log-json', '--repo', 'repo'),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=True),
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.logging).ANSWER = module.borgmatic.logger.ANSWER
|
||||
|
@ -294,6 +334,7 @@ def test_transfer_archives_with_lock_wait_calls_borg_with_lock_wait_flags():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -321,6 +362,7 @@ def test_transfer_archives_with_progress_calls_borg_with_progress_flag():
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=True, match_archives=None, source_repository=None
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -356,6 +398,7 @@ def test_transfer_archives_passes_through_arguments_to_borg(argument_name):
|
|||
source_repository=None,
|
||||
**{argument_name: 'value'},
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
|
@ -385,4 +428,53 @@ def test_transfer_archives_with_source_repository_calls_borg_with_other_repo_fla
|
|||
transfer_arguments=flexmock(
|
||||
archive=None, progress=None, match_archives=None, source_repository='other'
|
||||
),
|
||||
global_arguments=flexmock(log_json=False),
|
||||
)
|
||||
|
||||
|
||||
def test_transfer_archives_with_date_based_matching_calls_borg_with_date_based_flags():
|
||||
flexmock(module.borgmatic.logger).should_receive('add_custom_log_levels')
|
||||
flexmock(module.flags).should_receive('make_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_match_archives_flags').and_return(())
|
||||
flexmock(module.flags).should_receive('make_flags_from_arguments').and_return(
|
||||
('--newer', '1d', '--newest', '1y', '--older', '1m', '--oldest', '1w')
|
||||
)
|
||||
flexmock(module.flags).should_receive('make_repository_flags').and_return(('--repo', 'repo'))
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command').with_args(
|
||||
(
|
||||
'borg',
|
||||
'transfer',
|
||||
'--newer',
|
||||
'1d',
|
||||
'--newest',
|
||||
'1y',
|
||||
'--older',
|
||||
'1m',
|
||||
'--oldest',
|
||||
'1w',
|
||||
'--repo',
|
||||
'repo',
|
||||
),
|
||||
output_log_level=module.borgmatic.logger.ANSWER,
|
||||
output_file=None,
|
||||
borg_local_path='borg',
|
||||
extra_environment=None,
|
||||
)
|
||||
|
||||
module.transfer_archives(
|
||||
dry_run=False,
|
||||
repository_path='repo',
|
||||
storage_config={},
|
||||
local_borg_version='2.3.4',
|
||||
global_arguments=flexmock(log_json=False),
|
||||
transfer_arguments=flexmock(
|
||||
archive=None,
|
||||
progress=None,
|
||||
source_repository='other',
|
||||
newer='1d',
|
||||
newest='1y',
|
||||
older='1m',
|
||||
oldest='1w',
|
||||
),
|
||||
)
|
||||
|
|
|
@ -15,7 +15,8 @@ def insert_execute_command_and_capture_output_mock(
|
|||
):
|
||||
flexmock(module.environment).should_receive('make_environment')
|
||||
flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
||||
command, extra_environment=None,
|
||||
command,
|
||||
extra_environment=None,
|
||||
).once().and_return(version_output)
|
||||
|
||||
|
||||
|
|
|
@ -229,7 +229,8 @@ def test_run_configuration_retries_hard_error():
|
|||
).and_return([flexmock()])
|
||||
error_logs = [flexmock()]
|
||||
flexmock(module).should_receive('log_error_records').with_args(
|
||||
'foo: Error running actions for repository', OSError,
|
||||
'foo: Error running actions for repository',
|
||||
OSError,
|
||||
).and_return(error_logs)
|
||||
config = {'location': {'repositories': [{'path': 'foo'}]}, 'storage': {'retries': 1}}
|
||||
arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
from argparse import Action
|
||||
from collections import namedtuple
|
||||
from typing import Tuple
|
||||
|
||||
import pytest
|
||||
from flexmock import flexmock
|
||||
|
||||
from borgmatic.commands import completion as module
|
||||
|
||||
OptionType = namedtuple('OptionType', ['file', 'choice', 'unknown_required'])
|
||||
TestCase = Tuple[Action, OptionType]
|
||||
|
||||
test_data = [
|
||||
(Action('--flag', 'flag'), OptionType(file=False, choice=False, unknown_required=False)),
|
||||
*(
|
||||
(
|
||||
Action('--flag', 'flag', metavar=metavar),
|
||||
OptionType(file=True, choice=False, unknown_required=False),
|
||||
)
|
||||
for metavar in ('FILENAME', 'PATH')
|
||||
),
|
||||
(
|
||||
Action('--flag', dest='config_paths'),
|
||||
OptionType(file=True, choice=False, unknown_required=False),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', metavar='OTHER'),
|
||||
OptionType(file=False, choice=False, unknown_required=False),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', choices=['a', 'b']),
|
||||
OptionType(file=False, choice=True, unknown_required=False),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', choices=['a', 'b'], type=str),
|
||||
OptionType(file=False, choice=True, unknown_required=True),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', choices=None),
|
||||
OptionType(file=False, choice=False, unknown_required=False),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', required=True),
|
||||
OptionType(file=False, choice=False, unknown_required=True),
|
||||
),
|
||||
*(
|
||||
(
|
||||
Action('--flag', 'flag', nargs=nargs),
|
||||
OptionType(file=False, choice=False, unknown_required=True),
|
||||
)
|
||||
for nargs in ('+', '*')
|
||||
),
|
||||
*(
|
||||
(
|
||||
Action('--flag', 'flag', metavar=metavar),
|
||||
OptionType(file=False, choice=False, unknown_required=True),
|
||||
)
|
||||
for metavar in ('PATTERN', 'KEYS', 'N')
|
||||
),
|
||||
*(
|
||||
(
|
||||
Action('--flag', 'flag', type=type, default=None),
|
||||
OptionType(file=False, choice=False, unknown_required=True),
|
||||
)
|
||||
for type in (int, str)
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', type=int, default=1),
|
||||
OptionType(file=False, choice=False, unknown_required=False),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', type=str, required=True, metavar='PATH'),
|
||||
OptionType(file=True, choice=False, unknown_required=True),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', type=str, required=True, metavar='PATH', default='/dev/null'),
|
||||
OptionType(file=True, choice=False, unknown_required=True),
|
||||
),
|
||||
(
|
||||
Action('--flag', 'flag', type=str, required=False, metavar='PATH', default='/dev/null'),
|
||||
OptionType(file=True, choice=False, unknown_required=False),
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action, option_type', test_data)
|
||||
def test_has_file_options_detects_file_options(action: Action, option_type: OptionType):
|
||||
assert module.has_file_options(action) == option_type.file
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action, option_type', test_data)
|
||||
def test_has_choice_options_detects_choice_options(action: Action, option_type: OptionType):
|
||||
assert module.has_choice_options(action) == option_type.choice
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action, option_type', test_data)
|
||||
def test_has_unknown_required_param_options_detects_unknown_required_param_options(
|
||||
action: Action, option_type: OptionType
|
||||
):
|
||||
assert module.has_unknown_required_param_options(action) == option_type.unknown_required
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action, option_type', test_data)
|
||||
def test_has_exact_options_detects_exact_options(action: Action, option_type: OptionType):
|
||||
assert module.has_exact_options(action) == (True in option_type)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('action, option_type', test_data)
|
||||
def test_exact_options_completion_produces_reasonable_completions(
|
||||
action: Action, option_type: OptionType
|
||||
):
|
||||
completion = module.exact_options_completion(action)
|
||||
if True in option_type:
|
||||
assert completion.startswith('\ncomplete -c borgmatic')
|
||||
else:
|
||||
assert completion == ''
|
||||
|
||||
|
||||
def test_exact_options_completion_raises_for_unexpected_action():
|
||||
flexmock(module).should_receive('has_exact_options').and_return(True)
|
||||
flexmock(module).should_receive('has_file_options').and_return(False)
|
||||
flexmock(module).should_receive('has_choice_options').and_return(False)
|
||||
flexmock(module).should_receive('has_unknown_required_param_options').and_return(False)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
module.exact_options_completion(Action('--unknown', dest='unknown'))
|
||||
|
||||
|
||||
def test_dedent_strip_as_tuple_does_not_raise():
|
||||
module.dedent_strip_as_tuple(
|
||||
'''
|
||||
a
|
||||
b
|
||||
'''
|
||||
)
|
|
@ -21,13 +21,21 @@ from borgmatic.config import normalize as module
|
|||
{'location': {'source_directories': ['foo', 'bar']}},
|
||||
False,
|
||||
),
|
||||
({'location': None}, {'location': None}, False,),
|
||||
(
|
||||
{'location': None},
|
||||
{'location': None},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'storage': {'compression': 'yes_please'}},
|
||||
{'storage': {'compression': 'yes_please'}},
|
||||
False,
|
||||
),
|
||||
({'storage': None}, {'storage': None}, False,),
|
||||
(
|
||||
{'storage': None},
|
||||
{'storage': None},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'hooks': {'healthchecks': 'https://example.com'}},
|
||||
{'hooks': {'healthchecks': {'ping_url': 'https://example.com'}}},
|
||||
|
@ -48,10 +56,9 @@ from borgmatic.config import normalize as module
|
|||
{'hooks': {'cronhub': {'ping_url': 'https://example.com'}}},
|
||||
False,
|
||||
),
|
||||
({'hooks': None}, {'hooks': None}, False,),
|
||||
(
|
||||
{'consistency': {'checks': ['archives']}},
|
||||
{'consistency': {'checks': [{'name': 'archives'}]}},
|
||||
{'hooks': None},
|
||||
{'hooks': None},
|
||||
False,
|
||||
),
|
||||
(
|
||||
|
@ -59,9 +66,26 @@ from borgmatic.config import normalize as module
|
|||
{'consistency': {'checks': [{'name': 'archives'}]}},
|
||||
False,
|
||||
),
|
||||
({'consistency': None}, {'consistency': None}, False,),
|
||||
({'location': {'numeric_owner': False}}, {'location': {'numeric_ids': False}}, False,),
|
||||
({'location': {'bsd_flags': False}}, {'location': {'flags': False}}, False,),
|
||||
(
|
||||
{'consistency': {'checks': ['archives']}},
|
||||
{'consistency': {'checks': [{'name': 'archives'}]}},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'consistency': None},
|
||||
{'consistency': None},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'location': {'numeric_owner': False}},
|
||||
{'location': {'numeric_ids': False}},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'location': {'bsd_flags': False}},
|
||||
{'location': {'flags': False}},
|
||||
False,
|
||||
),
|
||||
(
|
||||
{'storage': {'remote_rate_limit': False}},
|
||||
{'storage': {'upload_rate_limit': False}},
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue