mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-06 16:23:00 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6cb901d083 | ||
|
|
096be14230 | ||
|
|
bb8b1e58e8 | ||
|
|
06261d8c86 | ||
|
|
869cccf884 | ||
|
|
0defaf9cb5 | ||
|
|
60b1f9921d | ||
|
|
f61bc91b0f | ||
|
|
ed2c6053de | ||
|
|
2cffa8deaa | ||
|
|
f0581271f6 | ||
|
|
99522234ea | ||
|
|
67f2862fb1 | ||
|
|
1c0dc3f904 | ||
|
|
b94dbff216 | ||
|
|
7388c723cd | ||
|
|
128be3c17d | ||
|
|
4c30c94258 | ||
|
|
20b8b45aeb | ||
|
|
2dd899f287 | ||
|
|
a13cc0ab17 | ||
|
|
620f9e64d6 | ||
|
|
25c320b281 | ||
|
|
f19eec56ac | ||
|
|
7cbcff2e9b | ||
|
|
9f6407ada6 | ||
|
|
e933ecf046 | ||
|
|
4010a2ed77 | ||
|
|
2f36096e1a | ||
|
|
82ec45e375 | ||
|
|
37362150fe | ||
|
|
a7ba97803f | ||
|
|
31dc903877 | ||
|
|
8943867433 | ||
|
|
d9cb110563 | ||
|
|
32113cee67 | ||
|
|
a621ce199a | ||
|
|
1f524d6c87 | ||
|
|
0320d449ec | ||
|
|
30f007687a | ||
|
|
adf7856162 | ||
|
|
f9dce8b2d3 | ||
|
|
15cb6270ef | ||
|
|
ed14fdbac9 | ||
|
|
8650a15db1 | ||
|
|
6a10022543 | ||
|
|
52e4f48eb9 | ||
|
|
f5e1e8bec9 | ||
|
|
a291477c19 | ||
|
|
1c88dda76a | ||
|
|
0b59c22c23 | ||
|
|
576377e2b2 | ||
|
|
6ff1867312 | ||
|
|
3cb52423d2 | ||
|
|
5a5b6491ac | ||
|
|
4272c6b077 |
+3
-2
@@ -3,7 +3,8 @@ pipeline:
|
|||||||
image: python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}
|
image: python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}
|
||||||
pull: true
|
pull: true
|
||||||
commands:
|
commands:
|
||||||
- pip install tox
|
- python -m pip install --upgrade pip==19.1.1
|
||||||
|
- pip install tox==3.10.0
|
||||||
- tox
|
- tox
|
||||||
- apk add --no-cache borgbackup
|
- apk add --no-cache borgbackup
|
||||||
- tox -e end-to-end
|
- tox -e end-to-end
|
||||||
@@ -11,7 +12,7 @@ pipeline:
|
|||||||
matrix:
|
matrix:
|
||||||
ALPINE_VERSION:
|
ALPINE_VERSION:
|
||||||
- 3.7
|
- 3.7
|
||||||
- 3.8
|
- 3.9
|
||||||
PYTHON_VERSION:
|
PYTHON_VERSION:
|
||||||
- 3.5
|
- 3.5
|
||||||
- 3.6
|
- 3.6
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ Johannes Feichtner: Support for user hooks
|
|||||||
Michele Lazzeri: Custom archive names
|
Michele Lazzeri: Custom archive names
|
||||||
Nick Whyte: Support prefix filtering for archive consistency checks
|
Nick Whyte: Support prefix filtering for archive consistency checks
|
||||||
newtonne: Read encryption password from external file
|
newtonne: Read encryption password from external file
|
||||||
Robin `ypid` Schneider: Support additional options of Borg
|
Robin `ypid` Schneider: Support additional options of Borg and add validate-borgmatic-config command
|
||||||
Scott Squires: Custom archive names
|
Scott Squires: Custom archive names
|
||||||
Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option
|
Thomas LÉVEIL: Support for a keep_minutely prune option. Support for the --json option
|
||||||
|
|||||||
@@ -1,3 +1,38 @@
|
|||||||
|
1.3.4
|
||||||
|
* Part of #125: Color borgmatic (but not Borg) output when using an interactive terminal.
|
||||||
|
# #166: Run tests for all installed versions of Python.
|
||||||
|
* #168: Update README with continuous integration badge.
|
||||||
|
* #169: Automatically sort Python imports in code.
|
||||||
|
* Document installing borgmatic with pip install --user instead of a system Python install.
|
||||||
|
* Get more reproducible builds by pinning the versions of pip and tox used to run tests.
|
||||||
|
* Factor out build/test configuration from tox.ini file.
|
||||||
|
|
||||||
|
1.3.3
|
||||||
|
* Add validate-borgmatic-config command, useful for validating borgmatic config generated by
|
||||||
|
configuration management or even edited by hand.
|
||||||
|
|
||||||
|
1.3.2
|
||||||
|
* #160: Fix for hooks executing when using --dry-run. Now hooks are skipped during a dry run.
|
||||||
|
|
||||||
|
1.3.1
|
||||||
|
* #155: Fix for invalid JSON output when using multiple borgmatic configuration files.
|
||||||
|
* #157: Fix for seemingly random filename ordering when running through a directory of
|
||||||
|
configuration files.
|
||||||
|
* Fix for empty JSON output when using --create --json.
|
||||||
|
* Now capturing Borg output only when --json flag is used. Previously, borgmatic delayed Borg
|
||||||
|
output even without the --json flag.
|
||||||
|
|
||||||
|
1.3.0
|
||||||
|
* #148: Configuration file includes and merging via "!include" tag to support reuse of common
|
||||||
|
options across configuration files.
|
||||||
|
|
||||||
|
1.2.18
|
||||||
|
* #147: Support for Borg create/extract --numeric-owner flag via "numeric_owner" option in
|
||||||
|
borgmatic's location section.
|
||||||
|
|
||||||
|
1.2.17
|
||||||
|
* #140: List the files within an archive via --list --archive option.
|
||||||
|
|
||||||
1.2.16
|
1.2.16
|
||||||
* #119: Include a sample borgmatic configuration file in the documentation.
|
* #119: Include a sample borgmatic configuration file in the documentation.
|
||||||
* #123: Support for Borg archive restoration via borgmatic --extract command-line flag.
|
* #123: Support for Borg archive restoration via borgmatic --extract command-line flag.
|
||||||
@@ -36,8 +71,8 @@
|
|||||||
* #108: Support for Borg create --progress via borgmatic command-line flag.
|
* #108: Support for Borg create --progress via borgmatic command-line flag.
|
||||||
|
|
||||||
1.2.10
|
1.2.10
|
||||||
* #105: Support for Borg --chunker-params create option via "chunker_params" in borgmatic's storage
|
* #105: Support for Borg --chunker-params create option via "chunker_params" option in borgmatic's
|
||||||
section.
|
storage section.
|
||||||
|
|
||||||
1.2.9
|
1.2.9
|
||||||
* #102: Fix for syntax error that occurred in Python 3.5 and below.
|
* #102: Fix for syntax error that occurred in Python 3.5 and below.
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
title: borgmatic
|
title: borgmatic
|
||||||
permalink: borgmatic/index.html
|
permalink: borgmatic/index.html
|
||||||
---
|
---
|
||||||
|
<a href="https://build.torsion.org/witten/borgmatic" alt="build status"></a>
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
<img src="https://projects.torsion.org/witten/borgmatic/raw/branch/master/static/borgmatic.png" width="150px" style="float: right; padding-left: 1em;">
|
<img src="https://projects.torsion.org/witten/borgmatic/raw/branch/master/static/borgmatic.png" alt="borgmatic logo" width="150px" style="float: right; padding-left: 1em;">
|
||||||
|
|
||||||
borgmatic is a simple Python wrapper script for the
|
borgmatic is a simple Python wrapper script for the
|
||||||
[Borg](https://www.borgbackup.org/) backup software that initiates a backup,
|
[Borg](https://www.borgbackup.org/) backup software that initiates a backup,
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from borgmatic.borg import extract
|
from borgmatic.borg import extract
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
DEFAULT_CHECKS = ('repository', 'archives')
|
DEFAULT_CHECKS = ('repository', 'archives')
|
||||||
DEFAULT_PREFIX = '{hostname}-'
|
DEFAULT_PREFIX = '{hostname}-'
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _parse_checks(consistency_config):
|
def _parse_checks(consistency_config):
|
||||||
|
|||||||
@@ -2,11 +2,12 @@ import glob
|
|||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
from borgmatic.borg.execute import execute_command
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _expand_directory(directory):
|
def _expand_directory(directory):
|
||||||
@@ -107,7 +108,7 @@ def create_archive(
|
|||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a
|
Given vebosity/dry-run flags, a local or remote repository path, a location config dict, and a
|
||||||
storage config dict, create a Borg archive.
|
storage config dict, create a Borg archive and return Borg's JSON output (if any).
|
||||||
'''
|
'''
|
||||||
sources = _expand_directories(location_config['source_directories'])
|
sources = _expand_directories(location_config['source_directories'])
|
||||||
|
|
||||||
@@ -141,6 +142,7 @@ def create_archive(
|
|||||||
+ (('--compression', compression) if compression else ())
|
+ (('--compression', compression) if compression else ())
|
||||||
+ (('--remote-ratelimit', str(remote_rate_limit)) if remote_rate_limit else ())
|
+ (('--remote-ratelimit', str(remote_rate_limit)) if remote_rate_limit else ())
|
||||||
+ (('--one-file-system',) if location_config.get('one_file_system') else ())
|
+ (('--one-file-system',) if location_config.get('one_file_system') else ())
|
||||||
|
+ (('--numeric-owner',) if location_config.get('numeric_owner') else ())
|
||||||
+ (('--read-special',) if location_config.get('read_special') else ())
|
+ (('--read-special',) if location_config.get('read_special') else ())
|
||||||
+ (('--nobsdflags',) if location_config.get('bsd_flags') is False else ())
|
+ (('--nobsdflags',) if location_config.get('bsd_flags') is False else ())
|
||||||
+ (('--files-cache', files_cache) if files_cache else ())
|
+ (('--files-cache', files_cache) if files_cache else ())
|
||||||
@@ -156,5 +158,4 @@ def create_archive(
|
|||||||
+ (('--json',) if json else ())
|
+ (('--json',) if json else ())
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug(' '.join(full_command))
|
return execute_command(full_command, capture_output=json)
|
||||||
subprocess.check_call(full_command)
|
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def execute_command(full_command, capture_output=False):
|
||||||
|
'''
|
||||||
|
Execute the given command (a sequence of command/argument strings). If capture output is True,
|
||||||
|
then return the command's output as a string.
|
||||||
|
'''
|
||||||
|
logger.debug(' '.join(full_command))
|
||||||
|
|
||||||
|
if capture_output:
|
||||||
|
output = subprocess.check_output(full_command)
|
||||||
|
return output.decode() if output is not None else None
|
||||||
|
else:
|
||||||
|
subprocess.check_call(full_command)
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None):
|
def extract_last_archive_dry_run(repository, lock_wait=None, local_path='borg', remote_path=None):
|
||||||
@@ -57,6 +58,7 @@ def extract_archive(
|
|||||||
repository,
|
repository,
|
||||||
archive,
|
archive,
|
||||||
restore_paths,
|
restore_paths,
|
||||||
|
location_config,
|
||||||
storage_config,
|
storage_config,
|
||||||
local_path='borg',
|
local_path='borg',
|
||||||
remote_path=None,
|
remote_path=None,
|
||||||
@@ -64,8 +66,8 @@ def extract_archive(
|
|||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Given a dry-run flag, a local or remote repository path, an archive name, zero or more paths to
|
Given a dry-run flag, a local or remote repository path, an archive name, zero or more paths to
|
||||||
restore from the archive, and a storage configuration dict, extract the archive into the current
|
restore from the archive, and location/storage configuration dicts, extract the archive into the
|
||||||
directory.
|
current directory.
|
||||||
'''
|
'''
|
||||||
umask = storage_config.get('umask', None)
|
umask = storage_config.get('umask', None)
|
||||||
lock_wait = storage_config.get('lock_wait', None)
|
lock_wait = storage_config.get('lock_wait', None)
|
||||||
@@ -74,6 +76,7 @@ def extract_archive(
|
|||||||
(local_path, 'extract', '::'.join((repository, archive)))
|
(local_path, 'extract', '::'.join((repository, archive)))
|
||||||
+ (tuple(restore_paths) if restore_paths else ())
|
+ (tuple(restore_paths) if restore_paths else ())
|
||||||
+ (('--remote-path', remote_path) if remote_path else ())
|
+ (('--remote-path', remote_path) if remote_path else ())
|
||||||
|
+ (('--numeric-owner',) if location_config.get('numeric_owner') else ())
|
||||||
+ (('--umask', str(umask)) if umask else ())
|
+ (('--umask', str(umask)) if umask else ())
|
||||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import logging
|
import logging
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
from borgmatic.borg.execute import execute_command
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def display_archives_info(
|
def display_archives_info(
|
||||||
repository, storage_config, local_path='borg', remote_path=None, json=False
|
repository, storage_config, local_path='borg', remote_path=None, json=False
|
||||||
):
|
):
|
||||||
'''
|
'''
|
||||||
Given a local or remote repository path, and a storage config dict,
|
Given a local or remote repository path, and a storage config dict, display summary information
|
||||||
display summary information for Borg archives in the repository.
|
for Borg archives in the repository or return JSON summary information.
|
||||||
'''
|
'''
|
||||||
lock_wait = storage_config.get('lock_wait', None)
|
lock_wait = storage_config.get('lock_wait', None)
|
||||||
|
|
||||||
@@ -23,7 +24,4 @@ def display_archives_info(
|
|||||||
+ (('--json',) if json else ())
|
+ (('--json',) if json else ())
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.debug(' '.join(full_command))
|
return execute_command(full_command, capture_output=json)
|
||||||
|
|
||||||
output = subprocess.check_output(full_command)
|
|
||||||
return output.decode() if output is not None else None
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def initialize_repository(
|
def initialize_repository(
|
||||||
|
|||||||
+13
-11
@@ -1,26 +1,28 @@
|
|||||||
import logging
|
import logging
|
||||||
import subprocess
|
|
||||||
|
from borgmatic.borg.execute import execute_command
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
def list_archives(
|
||||||
|
repository, storage_config, archive=None, local_path='borg', remote_path=None, json=False
|
||||||
|
):
|
||||||
def list_archives(repository, storage_config, local_path='borg', remote_path=None, json=False):
|
|
||||||
'''
|
'''
|
||||||
Given a local or remote repository path, and a storage config dict,
|
Given a local or remote repository path and a storage config dict, display the output of listing
|
||||||
list Borg archives in the repository.
|
Borg archives in the repository or return JSON output. Or, if an archive name is given, listing
|
||||||
|
the files in that archive.
|
||||||
'''
|
'''
|
||||||
lock_wait = storage_config.get('lock_wait', None)
|
lock_wait = storage_config.get('lock_wait', None)
|
||||||
|
|
||||||
full_command = (
|
full_command = (
|
||||||
(local_path, 'list', repository)
|
(local_path, 'list', '::'.join((repository, archive)) if archive else repository)
|
||||||
+ (('--remote-path', remote_path) if remote_path else ())
|
+ (('--remote-path', remote_path) if remote_path else ())
|
||||||
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
+ (('--lock-wait', str(lock_wait)) if lock_wait else ())
|
||||||
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
+ (('--info',) if logger.getEffectiveLevel() == logging.INFO else ())
|
||||||
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
+ (('--debug', '--show-rc') if logger.isEnabledFor(logging.DEBUG) else ())
|
||||||
+ (('--json',) if json else ())
|
+ (('--json',) if json else ())
|
||||||
)
|
)
|
||||||
logger.debug(' '.join(full_command))
|
|
||||||
|
|
||||||
output = subprocess.check_output(full_command)
|
return execute_command(full_command, capture_output=json)
|
||||||
return output.decode() if output is not None else None
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def _make_prune_flags(retention_config):
|
def _make_prune_flags(retention_config):
|
||||||
|
|||||||
+116
-96
@@ -1,31 +1,29 @@
|
|||||||
from argparse import ArgumentParser
|
|
||||||
import collections
|
import collections
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
from subprocess import CalledProcessError
|
|
||||||
import sys
|
import sys
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from subprocess import CalledProcessError
|
||||||
|
|
||||||
|
import colorama
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
from borgmatic.borg import (
|
from borgmatic.borg import check as borg_check
|
||||||
check as borg_check,
|
from borgmatic.borg import create as borg_create
|
||||||
create as borg_create,
|
from borgmatic.borg import environment as borg_environment
|
||||||
environment as borg_environment,
|
from borgmatic.borg import extract as borg_extract
|
||||||
prune as borg_prune,
|
from borgmatic.borg import info as borg_info
|
||||||
extract as borg_extract,
|
from borgmatic.borg import init as borg_init
|
||||||
list as borg_list,
|
from borgmatic.borg import list as borg_list
|
||||||
info as borg_info,
|
from borgmatic.borg import prune as borg_prune
|
||||||
init as borg_init,
|
|
||||||
)
|
|
||||||
from borgmatic.commands import hook
|
from borgmatic.commands import hook
|
||||||
from borgmatic.config import checks, collect, convert, validate
|
from borgmatic.config import checks, collect, convert, validate
|
||||||
|
from borgmatic.logger import get_logger, should_do_markup
|
||||||
from borgmatic.signals import configure_signals
|
from borgmatic.signals import configure_signals
|
||||||
from borgmatic.verbosity import verbosity_to_log_level
|
from borgmatic.verbosity import verbosity_to_log_level
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
LEGACY_CONFIG_PATH = '/etc/borgmatic/config'
|
||||||
|
|
||||||
@@ -102,27 +100,49 @@ def parse_arguments(*arguments):
|
|||||||
help='Create a repository with a fixed storage quota',
|
help='Create a repository with a fixed storage quota',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
prune_group = parser.add_argument_group('options for --prune')
|
||||||
|
stats_argument = prune_group.add_argument(
|
||||||
|
'--stats',
|
||||||
|
dest='stats',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help='Display statistics of archive',
|
||||||
|
)
|
||||||
|
|
||||||
create_group = parser.add_argument_group('options for --create')
|
create_group = parser.add_argument_group('options for --create')
|
||||||
create_group.add_argument(
|
progress_argument = create_group.add_argument(
|
||||||
'--progress',
|
'--progress',
|
||||||
dest='progress',
|
dest='progress',
|
||||||
default=False,
|
default=False,
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Display progress for each file as it is backed up',
|
help='Display progress for each file as it is processed',
|
||||||
|
)
|
||||||
|
create_group._group_actions.append(stats_argument)
|
||||||
|
json_argument = create_group.add_argument(
|
||||||
|
'--json', dest='json', default=False, action='store_true', help='Output results as JSON'
|
||||||
)
|
)
|
||||||
|
|
||||||
extract_group = parser.add_argument_group('options for --extract')
|
extract_group = parser.add_argument_group('options for --extract')
|
||||||
extract_group.add_argument(
|
repository_argument = extract_group.add_argument(
|
||||||
'--repository',
|
'--repository',
|
||||||
help='Path of repository to restore from, defaults to the configured repository if there is only one',
|
help='Path of repository to use, defaults to the configured repository if there is only one',
|
||||||
)
|
)
|
||||||
extract_group.add_argument('--archive', help='Name of archive to restore')
|
archive_argument = extract_group.add_argument('--archive', help='Name of archive to operate on')
|
||||||
extract_group.add_argument(
|
extract_group.add_argument(
|
||||||
'--restore-path',
|
'--restore-path',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
dest='restore_paths',
|
dest='restore_paths',
|
||||||
help='Paths to restore from archive, defaults to the entire archive',
|
help='Paths to restore from archive, defaults to the entire archive',
|
||||||
)
|
)
|
||||||
|
extract_group._group_actions.append(progress_argument)
|
||||||
|
|
||||||
|
list_group = parser.add_argument_group('options for --list')
|
||||||
|
list_group._group_actions.append(repository_argument)
|
||||||
|
list_group._group_actions.append(archive_argument)
|
||||||
|
list_group._group_actions.append(json_argument)
|
||||||
|
|
||||||
|
info_group = parser.add_argument_group('options for --info')
|
||||||
|
info_group._group_actions.append(json_argument)
|
||||||
|
|
||||||
common_group = parser.add_argument_group('common options')
|
common_group = parser.add_argument_group('common options')
|
||||||
common_group.add_argument(
|
common_group.add_argument(
|
||||||
@@ -140,20 +160,6 @@ def parse_arguments(*arguments):
|
|||||||
dest='excludes_filename',
|
dest='excludes_filename',
|
||||||
help='Deprecated in favor of exclude_patterns within configuration',
|
help='Deprecated in favor of exclude_patterns within configuration',
|
||||||
)
|
)
|
||||||
common_group.add_argument(
|
|
||||||
'--stats',
|
|
||||||
dest='stats',
|
|
||||||
default=False,
|
|
||||||
action='store_true',
|
|
||||||
help='Display statistics of archive with --create or --prune option',
|
|
||||||
)
|
|
||||||
common_group.add_argument(
|
|
||||||
'--json',
|
|
||||||
dest='json',
|
|
||||||
default=False,
|
|
||||||
action='store_true',
|
|
||||||
help='Output results from the --create, --list, or --info options as json',
|
|
||||||
)
|
|
||||||
common_group.add_argument(
|
common_group.add_argument(
|
||||||
'-n',
|
'-n',
|
||||||
'--dry-run',
|
'--dry-run',
|
||||||
@@ -161,6 +167,9 @@ def parse_arguments(*arguments):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Go through the motions, but do not actually write to any repositories',
|
help='Go through the motions, but do not actually write to any repositories',
|
||||||
)
|
)
|
||||||
|
common_group.add_argument(
|
||||||
|
'-nc', '--no-color', dest='no_color', action='store_true', help='Disable colored output'
|
||||||
|
)
|
||||||
common_group.add_argument(
|
common_group.add_argument(
|
||||||
'-v',
|
'-v',
|
||||||
'--verbosity',
|
'--verbosity',
|
||||||
@@ -196,10 +205,15 @@ def parse_arguments(*arguments):
|
|||||||
raise ValueError('The --encryption option is required with the --init option')
|
raise ValueError('The --encryption option is required with the --init option')
|
||||||
|
|
||||||
if not args.extract:
|
if not args.extract:
|
||||||
if args.repository:
|
if not args.list:
|
||||||
raise ValueError('The --repository option can only be used with the --extract option')
|
if args.repository:
|
||||||
if args.archive:
|
raise ValueError(
|
||||||
raise ValueError('The --archive option can only be used with the --extract option')
|
'The --repository option can only be used with the --extract and --list options'
|
||||||
|
)
|
||||||
|
if args.archive:
|
||||||
|
raise ValueError(
|
||||||
|
'The --archive option can only be used with the --extract and --list options'
|
||||||
|
)
|
||||||
if args.restore_paths:
|
if args.restore_paths:
|
||||||
raise ValueError('The --restore-path option can only be used with the --extract option')
|
raise ValueError('The --restore-path option can only be used with the --extract option')
|
||||||
if args.extract and not args.archive:
|
if args.extract and not args.archive:
|
||||||
@@ -245,6 +259,8 @@ def run_configuration(config_filename, config, args): # pragma: no cover
|
|||||||
'''
|
'''
|
||||||
Given a config filename and the corresponding parsed config dict, execute its defined pruning,
|
Given a config filename and the corresponding parsed config dict, execute its defined pruning,
|
||||||
backups, consistency checks, and/or other actions.
|
backups, consistency checks, and/or other actions.
|
||||||
|
|
||||||
|
Yield JSON output strings from executing any actions that produce JSON.
|
||||||
'''
|
'''
|
||||||
(location, storage, retention, consistency, hooks) = (
|
(location, storage, retention, consistency, hooks) = (
|
||||||
config.get(section_name, {})
|
config.get(section_name, {})
|
||||||
@@ -257,56 +273,42 @@ def run_configuration(config_filename, config, args): # pragma: no cover
|
|||||||
borg_environment.initialize(storage)
|
borg_environment.initialize(storage)
|
||||||
|
|
||||||
if args.create:
|
if args.create:
|
||||||
hook.execute_hook(hooks.get('before_backup'), config_filename, 'pre-backup')
|
hook.execute_hook(
|
||||||
|
hooks.get('before_backup'), config_filename, 'pre-backup', args.dry_run
|
||||||
|
)
|
||||||
|
|
||||||
_run_commands(
|
for repository_path in location['repositories']:
|
||||||
args=args,
|
yield from run_actions(
|
||||||
consistency=consistency,
|
args=args,
|
||||||
local_path=local_path,
|
location=location,
|
||||||
location=location,
|
storage=storage,
|
||||||
remote_path=remote_path,
|
retention=retention,
|
||||||
retention=retention,
|
consistency=consistency,
|
||||||
storage=storage,
|
local_path=local_path,
|
||||||
)
|
remote_path=remote_path,
|
||||||
|
repository_path=repository_path,
|
||||||
|
)
|
||||||
|
|
||||||
if args.create:
|
if args.create:
|
||||||
hook.execute_hook(hooks.get('after_backup'), config_filename, 'post-backup')
|
hook.execute_hook(
|
||||||
|
hooks.get('after_backup'), config_filename, 'post-backup', args.dry_run
|
||||||
|
)
|
||||||
except (OSError, CalledProcessError):
|
except (OSError, CalledProcessError):
|
||||||
hook.execute_hook(hooks.get('on_error'), config_filename, 'on-error')
|
hook.execute_hook(hooks.get('on_error'), config_filename, 'on-error', args.dry_run)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
def _run_commands(*, args, consistency, local_path, location, remote_path, retention, storage):
|
def run_actions(
|
||||||
json_results = []
|
*, args, location, storage, retention, consistency, local_path, remote_path, repository_path
|
||||||
for unexpanded_repository in location['repositories']:
|
|
||||||
_run_commands_on_repository(
|
|
||||||
args=args,
|
|
||||||
consistency=consistency,
|
|
||||||
json_results=json_results,
|
|
||||||
local_path=local_path,
|
|
||||||
location=location,
|
|
||||||
remote_path=remote_path,
|
|
||||||
retention=retention,
|
|
||||||
storage=storage,
|
|
||||||
unexpanded_repository=unexpanded_repository,
|
|
||||||
)
|
|
||||||
if args.json:
|
|
||||||
sys.stdout.write(json.dumps(json_results))
|
|
||||||
|
|
||||||
|
|
||||||
def _run_commands_on_repository(
|
|
||||||
*,
|
|
||||||
args,
|
|
||||||
consistency,
|
|
||||||
json_results,
|
|
||||||
local_path,
|
|
||||||
location,
|
|
||||||
remote_path,
|
|
||||||
retention,
|
|
||||||
storage,
|
|
||||||
unexpanded_repository
|
|
||||||
): # pragma: no cover
|
): # pragma: no cover
|
||||||
repository = os.path.expanduser(unexpanded_repository)
|
'''
|
||||||
|
Given parsed command-line arguments as an argparse.ArgumentParser instance, several different
|
||||||
|
configuration dicts, local and remote paths to Borg, and a repository name, run all actions
|
||||||
|
from the command-line arguments on the given repository.
|
||||||
|
|
||||||
|
Yield JSON output strings from executing any actions that produce JSON.
|
||||||
|
'''
|
||||||
|
repository = os.path.expanduser(repository_path)
|
||||||
dry_run_label = ' (dry run; not making any changes)' if args.dry_run else ''
|
dry_run_label = ' (dry run; not making any changes)' if args.dry_run else ''
|
||||||
if args.init:
|
if args.init:
|
||||||
logger.info('{}: Initializing repository'.format(repository))
|
logger.info('{}: Initializing repository'.format(repository))
|
||||||
@@ -331,7 +333,7 @@ def _run_commands_on_repository(
|
|||||||
)
|
)
|
||||||
if args.create:
|
if args.create:
|
||||||
logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
|
logger.info('{}: Creating archive{}'.format(repository, dry_run_label))
|
||||||
borg_create.create_archive(
|
json_output = borg_create.create_archive(
|
||||||
args.dry_run,
|
args.dry_run,
|
||||||
repository,
|
repository,
|
||||||
location,
|
location,
|
||||||
@@ -340,7 +342,10 @@ def _run_commands_on_repository(
|
|||||||
remote_path=remote_path,
|
remote_path=remote_path,
|
||||||
progress=args.progress,
|
progress=args.progress,
|
||||||
stats=args.stats,
|
stats=args.stats,
|
||||||
|
json=args.json,
|
||||||
)
|
)
|
||||||
|
if json_output:
|
||||||
|
yield json.loads(json_output)
|
||||||
if args.check and checks.repository_enabled_for_checks(repository, consistency):
|
if args.check and checks.repository_enabled_for_checks(repository, consistency):
|
||||||
logger.info('{}: Running consistency checks'.format(repository))
|
logger.info('{}: Running consistency checks'.format(repository))
|
||||||
borg_check.check_archives(
|
borg_check.check_archives(
|
||||||
@@ -354,29 +359,32 @@ def _run_commands_on_repository(
|
|||||||
repository,
|
repository,
|
||||||
args.archive,
|
args.archive,
|
||||||
args.restore_paths,
|
args.restore_paths,
|
||||||
|
location,
|
||||||
storage,
|
storage,
|
||||||
local_path=local_path,
|
local_path=local_path,
|
||||||
remote_path=remote_path,
|
remote_path=remote_path,
|
||||||
progress=args.progress,
|
progress=args.progress,
|
||||||
)
|
)
|
||||||
if args.list:
|
if args.list:
|
||||||
logger.info('{}: Listing archives'.format(repository))
|
if args.repository is None or repository == args.repository:
|
||||||
output = borg_list.list_archives(
|
logger.info('{}: Listing archives'.format(repository))
|
||||||
repository, storage, local_path=local_path, remote_path=remote_path, json=args.json
|
json_output = borg_list.list_archives(
|
||||||
)
|
repository,
|
||||||
if args.json:
|
storage,
|
||||||
json_results.append(json.loads(output))
|
args.archive,
|
||||||
else:
|
local_path=local_path,
|
||||||
sys.stdout.write(output)
|
remote_path=remote_path,
|
||||||
|
json=args.json,
|
||||||
|
)
|
||||||
|
if json_output:
|
||||||
|
yield json.loads(json_output)
|
||||||
if args.info:
|
if args.info:
|
||||||
logger.info('{}: Displaying summary info for archives'.format(repository))
|
logger.info('{}: Displaying summary info for archives'.format(repository))
|
||||||
output = borg_info.display_archives_info(
|
json_output = borg_info.display_archives_info(
|
||||||
repository, storage, local_path=local_path, remote_path=remote_path, json=args.json
|
repository, storage, local_path=local_path, remote_path=remote_path, json=args.json
|
||||||
)
|
)
|
||||||
if args.json:
|
if json_output:
|
||||||
json_results.append(json.loads(output))
|
yield json.loads(json_output)
|
||||||
else:
|
|
||||||
sys.stdout.write(output)
|
|
||||||
|
|
||||||
|
|
||||||
def collect_configuration_run_summary_logs(config_filenames, args):
|
def collect_configuration_run_summary_logs(config_filenames, args):
|
||||||
@@ -384,10 +392,14 @@ def collect_configuration_run_summary_logs(config_filenames, args):
|
|||||||
Given a sequence of configuration filenames and parsed command-line arguments as an
|
Given a sequence of configuration filenames and parsed command-line arguments as an
|
||||||
argparse.ArgumentParser instance, run each configuration file and yield a series of
|
argparse.ArgumentParser instance, run each configuration file and yield a series of
|
||||||
logging.LogRecord instances containing summary information about each run.
|
logging.LogRecord instances containing summary information about each run.
|
||||||
|
|
||||||
|
As a side effect of running through these configuration files, output their JSON results, if
|
||||||
|
any, to stdout.
|
||||||
'''
|
'''
|
||||||
# Dict mapping from config filename to corresponding parsed config dict.
|
# Dict mapping from config filename to corresponding parsed config dict.
|
||||||
configs = collections.OrderedDict()
|
configs = collections.OrderedDict()
|
||||||
|
|
||||||
|
# Parse and load each configuration file.
|
||||||
for config_filename in config_filenames:
|
for config_filename in config_filenames:
|
||||||
try:
|
try:
|
||||||
logger.info('{}: Parsing configuration file'.format(config_filename))
|
logger.info('{}: Parsing configuration file'.format(config_filename))
|
||||||
@@ -403,16 +415,19 @@ def collect_configuration_run_summary_logs(config_filenames, args):
|
|||||||
)
|
)
|
||||||
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
||||||
|
|
||||||
if args.extract:
|
# Run cross-file validation checks.
|
||||||
|
if args.extract or (args.list and args.archive):
|
||||||
try:
|
try:
|
||||||
validate.guard_configuration_contains_repository(args.repository, configs)
|
validate.guard_configuration_contains_repository(args.repository, configs)
|
||||||
except ValueError as error:
|
except ValueError as error:
|
||||||
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Execute the actions corresponding to each configuration file.
|
||||||
|
json_results = []
|
||||||
for config_filename, config in configs.items():
|
for config_filename, config in configs.items():
|
||||||
try:
|
try:
|
||||||
run_configuration(config_filename, config, args)
|
json_results.extend(list(run_configuration(config_filename, config, args)))
|
||||||
yield logging.makeLogRecord(
|
yield logging.makeLogRecord(
|
||||||
dict(
|
dict(
|
||||||
levelno=logging.INFO,
|
levelno=logging.INFO,
|
||||||
@@ -428,6 +443,9 @@ def collect_configuration_run_summary_logs(config_filenames, args):
|
|||||||
)
|
)
|
||||||
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error))
|
||||||
|
|
||||||
|
if json_results:
|
||||||
|
sys.stdout.write(json.dumps(json_results))
|
||||||
|
|
||||||
if not config_filenames:
|
if not config_filenames:
|
||||||
yield logging.makeLogRecord(
|
yield logging.makeLogRecord(
|
||||||
dict(
|
dict(
|
||||||
@@ -455,6 +473,8 @@ def main(): # pragma: no cover
|
|||||||
logger.critical(error)
|
logger.critical(error)
|
||||||
exit_with_help_link()
|
exit_with_help_link()
|
||||||
|
|
||||||
|
colorama.init(autoreset=True, strip=not should_do_markup(args.no_color))
|
||||||
|
|
||||||
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
from argparse import ArgumentParser
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from ruamel import yaml
|
from ruamel import yaml
|
||||||
|
|
||||||
from borgmatic.config import convert, generate, legacy, validate
|
from borgmatic.config import convert, generate, legacy, validate
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_SOURCE_CONFIG_FILENAME = '/etc/borgmatic/config'
|
DEFAULT_SOURCE_CONFIG_FILENAME = '/etc/borgmatic/config'
|
||||||
DEFAULT_SOURCE_EXCLUDES_FILENAME = '/etc/borgmatic/excludes'
|
DEFAULT_SOURCE_EXCLUDES_FILENAME = '/etc/borgmatic/excludes'
|
||||||
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
from argparse import ArgumentParser
|
|
||||||
import sys
|
import sys
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from borgmatic.config import generate, validate
|
from borgmatic.config import generate, validate
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
DEFAULT_DESTINATION_CONFIG_FILENAME = '/etc/borgmatic/config.yaml'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,34 @@
|
|||||||
import logging
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def execute_hook(commands, config_filename, description):
|
def execute_hook(commands, config_filename, description, dry_run):
|
||||||
|
'''
|
||||||
|
|
||||||
|
Given a list of hook commands to execute, a config filename, a hook description, and whether
|
||||||
|
this is a dry run, run the given commands. Or, don't run them if this is a dry run.
|
||||||
|
'''
|
||||||
if not commands:
|
if not commands:
|
||||||
logger.debug('{}: No commands to run for {} hook'.format(config_filename, description))
|
logger.debug('{}: No commands to run for {} hook'.format(config_filename, description))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
dry_run_label = ' (dry run; not actually running hooks)' if dry_run else ''
|
||||||
|
|
||||||
if len(commands) == 1:
|
if len(commands) == 1:
|
||||||
logger.info('{}: Running command for {} hook'.format(config_filename, description))
|
logger.info(
|
||||||
|
'{}: Running command for {} hook{}'.format(config_filename, description, dry_run_label)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(
|
logger.info(
|
||||||
'{}: Running {} commands for {} hook'.format(
|
'{}: Running {} commands for {} hook{}'.format(
|
||||||
config_filename, len(commands), description
|
config_filename, len(commands), description, dry_run_label
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
for command in commands:
|
for command in commands:
|
||||||
logger.debug('{}: Hook command: {}'.format(config_filename, command))
|
logger.debug('{}: Hook command: {}'.format(config_filename, command))
|
||||||
subprocess.check_call(command, shell=True)
|
if not dry_run:
|
||||||
|
subprocess.check_call(command, shell=True)
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
from borgmatic.config import collect, validate
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_arguments(*arguments):
|
||||||
|
'''
|
||||||
|
Given command-line arguments with which this script was invoked, parse the arguments and return
|
||||||
|
them as an ArgumentParser instance.
|
||||||
|
'''
|
||||||
|
config_paths = collect.get_default_config_paths()
|
||||||
|
|
||||||
|
parser = ArgumentParser(description='Validate borgmatic configuration file(s).')
|
||||||
|
parser.add_argument(
|
||||||
|
'-c',
|
||||||
|
'--config',
|
||||||
|
nargs='+',
|
||||||
|
dest='config_paths',
|
||||||
|
default=config_paths,
|
||||||
|
help='Configuration filenames or directories, defaults to: {}'.format(
|
||||||
|
' '.join(config_paths)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser.parse_args(arguments)
|
||||||
|
|
||||||
|
|
||||||
|
def main(): # pragma: no cover
|
||||||
|
args = parse_arguments(*sys.argv[1:])
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
||||||
|
|
||||||
|
config_filenames = tuple(collect.collect_config_filenames(args.config_paths))
|
||||||
|
if len(config_filenames) == 0:
|
||||||
|
logger.critical('No files to validate found')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
found_issues = False
|
||||||
|
for config_filename in config_filenames:
|
||||||
|
try:
|
||||||
|
validate.parse_configuration(config_filename, validate.schema_filename())
|
||||||
|
except (ValueError, OSError, validate.Validation_error) as error:
|
||||||
|
logging.critical('{}: Error parsing configuration file'.format(config_filename))
|
||||||
|
logging.critical(error)
|
||||||
|
found_issues = True
|
||||||
|
|
||||||
|
if found_issues:
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
'All given configuration files are valid: {}'.format(', '.join(config_filenames))
|
||||||
|
)
|
||||||
@@ -41,7 +41,7 @@ def collect_config_filenames(config_paths):
|
|||||||
yield path
|
yield path
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for filename in os.listdir(path):
|
for filename in sorted(os.listdir(path)):
|
||||||
full_filename = os.path.join(path, filename)
|
full_filename = os.path.join(path, filename)
|
||||||
if full_filename.endswith('.yaml') and not os.path.isdir(full_filename):
|
if full_filename.endswith('.yaml') and not os.path.isdir(full_filename):
|
||||||
yield full_filename
|
yield full_filename
|
||||||
|
|||||||
@@ -64,9 +64,9 @@ def convert_legacy_parsed_config(source_config, source_excludes, schema):
|
|||||||
return destination_config
|
return destination_config
|
||||||
|
|
||||||
|
|
||||||
class LegacyConfigurationNotUpgraded(FileNotFoundError):
|
class Legacy_configuration_not_upgraded(FileNotFoundError):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(LegacyConfigurationNotUpgraded, self).__init__(
|
super(Legacy_configuration_not_upgraded, self).__init__(
|
||||||
'''borgmatic changed its configuration file format in version 1.1.0 from INI-style
|
'''borgmatic changed its configuration file format in version 1.1.0 from INI-style
|
||||||
to YAML. This better supports validation, and has a more natural way to express
|
to YAML. This better supports validation, and has a more natural way to express
|
||||||
lists of values. To upgrade your existing configuration, run:
|
lists of values. To upgrade your existing configuration, run:
|
||||||
@@ -83,7 +83,7 @@ instead of the old one.'''
|
|||||||
def guard_configuration_upgraded(source_config_filename, destination_config_filenames):
|
def guard_configuration_upgraded(source_config_filename, destination_config_filenames):
|
||||||
'''
|
'''
|
||||||
If legacy source configuration exists but no destination upgraded configs do, raise
|
If legacy source configuration exists but no destination upgraded configs do, raise
|
||||||
LegacyConfigurationNotUpgraded.
|
Legacy_configuration_not_upgraded.
|
||||||
|
|
||||||
The idea is that we want to alert the user about upgrading their config if they haven't already.
|
The idea is that we want to alert the user about upgrading their config if they haven't already.
|
||||||
'''
|
'''
|
||||||
@@ -92,4 +92,4 @@ def guard_configuration_upgraded(source_config_filename, destination_config_file
|
|||||||
)
|
)
|
||||||
|
|
||||||
if os.path.exists(source_config_filename) and not destination_config_exists:
|
if os.path.exists(source_config_filename) and not destination_config_exists:
|
||||||
raise LegacyConfigurationNotUpgraded()
|
raise Legacy_configuration_not_upgraded()
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
|
|
||||||
from ruamel import yaml
|
from ruamel import yaml
|
||||||
|
|
||||||
|
|
||||||
INDENT = 4
|
INDENT = 4
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from collections import OrderedDict, namedtuple
|
from collections import OrderedDict, namedtuple
|
||||||
from configparser import RawConfigParser
|
from configparser import RawConfigParser
|
||||||
|
|
||||||
|
|
||||||
Section_format = namedtuple('Section_format', ('name', 'options'))
|
Section_format = namedtuple('Section_format', ('name', 'options'))
|
||||||
Config_option = namedtuple('Config_option', ('name', 'value_type', 'required'))
|
Config_option = namedtuple('Config_option', ('name', 'value_type', 'required'))
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def load_configuration(filename):
|
||||||
|
'''
|
||||||
|
Load the given configuration file and return its contents as a data structure of nested dicts
|
||||||
|
and lists.
|
||||||
|
|
||||||
|
Raise ruamel.yaml.error.YAMLError if something goes wrong parsing the YAML, or RecursionError
|
||||||
|
if there are too many recursive includes.
|
||||||
|
'''
|
||||||
|
yaml = ruamel.yaml.YAML(typ='safe')
|
||||||
|
yaml.Constructor = Include_constructor
|
||||||
|
|
||||||
|
return yaml.load(open(filename))
|
||||||
|
|
||||||
|
|
||||||
|
def include_configuration(loader, filename_node):
|
||||||
|
'''
|
||||||
|
Load the given YAML filename (ignoring the given loader so we can use our own), and return its
|
||||||
|
contents as a data structure of nested dicts and lists.
|
||||||
|
'''
|
||||||
|
return load_configuration(os.path.expanduser(filename_node.value))
|
||||||
|
|
||||||
|
|
||||||
|
class Include_constructor(ruamel.yaml.SafeConstructor):
|
||||||
|
'''
|
||||||
|
A YAML "constructor" (a ruamel.yaml concept) that supports a custom "!include" tag for including
|
||||||
|
separate YAML configuration files. Example syntax: `retention: !include common.yaml`
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, preserve_quotes=None, loader=None):
|
||||||
|
super(Include_constructor, self).__init__(preserve_quotes, loader)
|
||||||
|
self.add_constructor('!include', include_configuration)
|
||||||
|
|
||||||
|
def flatten_mapping(self, node):
|
||||||
|
'''
|
||||||
|
Support the special case of shallow merging included configuration into an existing mapping
|
||||||
|
using the YAML '<<' merge key. Example syntax:
|
||||||
|
|
||||||
|
```
|
||||||
|
retention:
|
||||||
|
keep_daily: 1
|
||||||
|
<<: !include common.yaml
|
||||||
|
```
|
||||||
|
'''
|
||||||
|
representer = ruamel.yaml.representer.SafeRepresenter()
|
||||||
|
|
||||||
|
for index, (key_node, value_node) in enumerate(node.value):
|
||||||
|
if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include':
|
||||||
|
included_value = representer.represent_mapping(
|
||||||
|
tag='tag:yaml.org,2002:map', mapping=self.construct_object(value_node)
|
||||||
|
)
|
||||||
|
node.value[index] = (key_node, included_value)
|
||||||
|
|
||||||
|
super(Include_constructor, self).flatten_mapping(node)
|
||||||
@@ -32,6 +32,10 @@ map:
|
|||||||
type: bool
|
type: bool
|
||||||
desc: Stay in same file system (do not cross mount points). Defaults to false.
|
desc: Stay in same file system (do not cross mount points). Defaults to false.
|
||||||
example: true
|
example: true
|
||||||
|
numeric_owner:
|
||||||
|
type: bool
|
||||||
|
desc: Only store/extract numeric user and group identifiers. Defaults to false.
|
||||||
|
example: true
|
||||||
read_special:
|
read_special:
|
||||||
type: bool
|
type: bool
|
||||||
desc: |
|
desc: |
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ import logging
|
|||||||
import pkg_resources
|
import pkg_resources
|
||||||
import pykwalify.core
|
import pykwalify.core
|
||||||
import pykwalify.errors
|
import pykwalify.errors
|
||||||
from ruamel import yaml
|
import ruamel.yaml
|
||||||
|
|
||||||
|
from borgmatic.config import load
|
||||||
|
from borgmatic.logger import get_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = get_logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def schema_filename():
|
def schema_filename():
|
||||||
@@ -87,9 +89,9 @@ def parse_configuration(config_filename, schema_filename):
|
|||||||
logging.getLogger('pykwalify').setLevel(logging.ERROR)
|
logging.getLogger('pykwalify').setLevel(logging.ERROR)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config = yaml.safe_load(open(config_filename))
|
config = load.load_configuration(config_filename)
|
||||||
schema = yaml.safe_load(open(schema_filename))
|
schema = load.load_configuration(schema_filename)
|
||||||
except yaml.error.YAMLError as error:
|
except (ruamel.yaml.error.YAMLError, RecursionError) as error:
|
||||||
raise Validation_error(config_filename, (str(error),))
|
raise Validation_error(config_filename, (str(error),))
|
||||||
|
|
||||||
# pykwalify gets angry if the example field is not a string. So rather than bend to its will,
|
# pykwalify gets angry if the example field is not a string. So rather than bend to its will,
|
||||||
@@ -130,7 +132,7 @@ def guard_configuration_contains_repository(repository, configurations):
|
|||||||
|
|
||||||
if count > 1:
|
if count > 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Can\'t determine which repository to extract. Use --repository option to disambiguate'.format(
|
'Can\'t determine which repository to use. Use --repository option to disambiguate'.format(
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import colorama
|
||||||
|
|
||||||
|
|
||||||
|
def to_bool(arg):
|
||||||
|
'''
|
||||||
|
Return a boolean value based on `arg`.
|
||||||
|
'''
|
||||||
|
if arg is None or isinstance(arg, bool):
|
||||||
|
return arg
|
||||||
|
|
||||||
|
if isinstance(arg, str):
|
||||||
|
arg = arg.lower()
|
||||||
|
|
||||||
|
if arg in ('yes', 'on', '1', 'true', 1):
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def should_do_markup(no_color):
|
||||||
|
'''
|
||||||
|
Determine if we should enable colorama marking up.
|
||||||
|
'''
|
||||||
|
if no_color:
|
||||||
|
return False
|
||||||
|
|
||||||
|
py_colors = os.environ.get('PY_COLORS', None)
|
||||||
|
|
||||||
|
if py_colors is not None:
|
||||||
|
return to_bool(py_colors)
|
||||||
|
|
||||||
|
return sys.stdout.isatty() and os.environ.get('TERM') != 'dumb'
|
||||||
|
|
||||||
|
|
||||||
|
LOG_LEVEL_TO_COLOR = {
|
||||||
|
logging.CRITICAL: colorama.Fore.RED,
|
||||||
|
logging.ERROR: colorama.Fore.RED,
|
||||||
|
logging.WARN: colorama.Fore.YELLOW,
|
||||||
|
logging.INFO: colorama.Fore.GREEN,
|
||||||
|
logging.DEBUG: colorama.Fore.CYAN,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Borgmatic_logger(logging.Logger):
|
||||||
|
def critical(self, msg, *args, **kwargs):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(logging.CRITICAL)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).critical(color_text(color, msg), *args, **kwargs)
|
||||||
|
|
||||||
|
def error(self, msg, *args, **kwargs):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(logging.ERROR)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).error(color_text(color, msg), *args, **kwargs)
|
||||||
|
|
||||||
|
def warn(self, msg, *args, **kwargs):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(logging.WARN)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).warn(color_text(color, msg), *args, **kwargs)
|
||||||
|
|
||||||
|
def info(self, msg, *args, **kwargs):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(logging.INFO)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).info(color_text(color, msg), *args, **kwargs)
|
||||||
|
|
||||||
|
def debug(self, msg, *args, **kwargs):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(logging.DEBUG)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).debug(color_text(color, msg), *args, **kwargs)
|
||||||
|
|
||||||
|
def handle(self, record):
|
||||||
|
color = LOG_LEVEL_TO_COLOR.get(record.levelno)
|
||||||
|
colored_record = logging.makeLogRecord(
|
||||||
|
dict(levelno=record.levelno, msg=color_text(color, record.msg))
|
||||||
|
)
|
||||||
|
|
||||||
|
return super(Borgmatic_logger, self).handle(colored_record)
|
||||||
|
|
||||||
|
|
||||||
|
def get_logger(name=None):
|
||||||
|
'''
|
||||||
|
Build a logger with the given name.
|
||||||
|
'''
|
||||||
|
logging.setLoggerClass(Borgmatic_logger)
|
||||||
|
logger = logging.getLogger(name)
|
||||||
|
logger.propagate = False
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
|
def color_text(color, message):
|
||||||
|
'''
|
||||||
|
Give colored text.
|
||||||
|
'''
|
||||||
|
if not color:
|
||||||
|
return message
|
||||||
|
|
||||||
|
return '{}{}{}'.format(color, message, colorama.Style.RESET_ALL)
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
VERBOSITY_WARNING = 0
|
VERBOSITY_WARNING = 0
|
||||||
VERBOSITY_SOME = 1
|
VERBOSITY_SOME = 1
|
||||||
VERBOSITY_LOTS = 2
|
VERBOSITY_LOTS = 2
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ you're in the `borgmatic/` working copy, install tox, which is used for
|
|||||||
setting up testing environments:
|
setting up testing environments:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 install tox
|
pip3 install --user tox
|
||||||
```
|
```
|
||||||
|
|
||||||
Finally, to actually run tests, run:
|
Finally, to actually run tests, run:
|
||||||
@@ -91,6 +91,12 @@ formatter and [Flake8](http://flake8.pycqa.org/en/latest/) code checker, so
|
|||||||
certain code style requirements will be enforced when running automated tests.
|
certain code style requirements will be enforced when running automated tests.
|
||||||
See the Black and Flake8 documentation for more information.
|
See the Black and Flake8 documentation for more information.
|
||||||
|
|
||||||
|
## Continuous integration
|
||||||
|
|
||||||
|
Each pull request triggers a continuous integration build which runs the test
|
||||||
|
suite. You can view these builds on
|
||||||
|
[build.torsion.org](https://build.torsion.org/witten/borgmatic), and they're
|
||||||
|
also linked from the commits list on each pull request.
|
||||||
|
|
||||||
## Related documentation
|
## Related documentation
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,85 @@ configuration paths on the command-line with borgmatic's `--config` option.
|
|||||||
See `borgmatic --help` for more information.
|
See `borgmatic --help` for more information.
|
||||||
|
|
||||||
|
|
||||||
|
## Configuration includes
|
||||||
|
|
||||||
|
Once you have multiple different configuration files, you might want to share
|
||||||
|
common configuration options across these files with having to copy and paste
|
||||||
|
them. To achieve this, you can put fragments of common configuration options
|
||||||
|
into a file, and then include or inline that file into one or more borgmatic
|
||||||
|
configuration files.
|
||||||
|
|
||||||
|
Let's say that you want to include common retention configuration across all
|
||||||
|
of your configuration files. You could do that in each configuration file with
|
||||||
|
the following:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
location:
|
||||||
|
...
|
||||||
|
|
||||||
|
retention:
|
||||||
|
!include /etc/borgmatic/common_retention.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
And then the contents of `common_retention.yaml` could be:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
keep_hourly: 24
|
||||||
|
keep_daily: 7
|
||||||
|
```
|
||||||
|
|
||||||
|
To prevent borgmatic from trying to load these configuration fragments by
|
||||||
|
themselves and complaining that they are not valid configuration files, you
|
||||||
|
should put them in a directory other than `/etc/borgmatic.d/`. (A subdirectory
|
||||||
|
is fine.)
|
||||||
|
|
||||||
|
Note that this form of include must be a YAML value rather than a key. For
|
||||||
|
example, this will not work:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
location:
|
||||||
|
...
|
||||||
|
|
||||||
|
# Don't do this. It won't work!
|
||||||
|
!include /etc/borgmatic/common_retention.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
But if you do want to merge in a YAML key and its values, keep reading!
|
||||||
|
|
||||||
|
|
||||||
|
## Include merging
|
||||||
|
|
||||||
|
If you need to get even fancier and pull in common configuration options while
|
||||||
|
potentially overriding individual options, you can perform a YAML merge of
|
||||||
|
included configuration using the YAML `<<` key. For instance, here's an
|
||||||
|
example of a main configuration file that pulls in two retention options via
|
||||||
|
an include, and then overrides one of them locally:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
location:
|
||||||
|
...
|
||||||
|
|
||||||
|
retention:
|
||||||
|
keep_daily: 5
|
||||||
|
<<: !include /etc/borgmatic/common_retention.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
This is what `common_retention.yaml` might look like:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
keep_hourly: 24
|
||||||
|
keep_daily: 7
|
||||||
|
```
|
||||||
|
|
||||||
|
Once this include gets merged in, the resulting configuration would have a
|
||||||
|
`keep_hourly` value of `24` and an overridden `keep_daily` value of `5`.
|
||||||
|
|
||||||
|
When there is a collision of an option between the local file and the merged
|
||||||
|
include, the local file's option takes precedent. And note that this is a
|
||||||
|
shallow merge rather than a deep merge, so the merging does not descend into
|
||||||
|
nested values.
|
||||||
|
|
||||||
|
|
||||||
## Related documentation
|
## Related documentation
|
||||||
|
|
||||||
* [Set up backups with borgmatic](../../docs/how-to/set-up-backups.md)
|
* [Set up backups with borgmatic](../../docs/how-to/set-up-backups.md)
|
||||||
|
|||||||
@@ -7,23 +7,31 @@ To get up and running, first [install
|
|||||||
Borg](https://borgbackup.readthedocs.io/en/latest/installation.html), at
|
Borg](https://borgbackup.readthedocs.io/en/latest/installation.html), at
|
||||||
least version 1.1.
|
least version 1.1.
|
||||||
|
|
||||||
Then, run the following command to download and install borgmatic:
|
Borgmatic consumes configurations in `/etc/borgmatic/` and `/etc/borgmatic.d/`
|
||||||
|
by default. Therefore, we show how to install borgmatic for the root user which
|
||||||
|
will have access permissions for these locations by default.
|
||||||
|
|
||||||
|
Run the following commands to download and install borgmatic:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 install --upgrade borgmatic
|
sudo pip3 install --user --upgrade borgmatic
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This is a [recommended user site
|
||||||
|
installation](https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site).
|
||||||
|
You will need to ensure that `/root/.local/bin` is available on your `$PATH` so
|
||||||
|
that the borgmatic executable is available.
|
||||||
|
|
||||||
Note that your pip binary may have a different name than "pip3". Make sure
|
Note that your pip binary may have a different name than "pip3". Make sure
|
||||||
you're using Python 3, as borgmatic does not support Python 2.
|
you're using Python 3, as borgmatic does not support Python 2.
|
||||||
|
|
||||||
|
|
||||||
### Other ways to install
|
### Other ways to install
|
||||||
|
|
||||||
Along with the above process, you have several other options for installing
|
Along with the above process, you have several other options for installing
|
||||||
borgmatic:
|
borgmatic:
|
||||||
|
|
||||||
* [Docker image](https://hub.docker.com/r/monachus/borgmatic/)
|
* [Docker base image](https://hub.docker.com/r/monachus/borgmatic/)
|
||||||
* [Another Docker image](https://hub.docker.com/r/b3vis/borgmatic/)
|
* [Docker image with support for scheduled backups](https://hub.docker.com/r/b3vis/borgmatic/)
|
||||||
* [Debian](https://tracker.debian.org/pkg/borgmatic)
|
* [Debian](https://tracker.debian.org/pkg/borgmatic)
|
||||||
* [Ubuntu](https://launchpad.net/ubuntu/+source/borgmatic)
|
* [Ubuntu](https://launchpad.net/ubuntu/+source/borgmatic)
|
||||||
* [Fedora](https://bodhi.fedoraproject.org/updates/?search=borgmatic)
|
* [Fedora](https://bodhi.fedoraproject.org/updates/?search=borgmatic)
|
||||||
@@ -45,9 +53,14 @@ not in your system `PATH`. Try looking in `/usr/local/bin/`.
|
|||||||
|
|
||||||
This generates a sample configuration file at /etc/borgmatic/config.yaml (by
|
This generates a sample configuration file at /etc/borgmatic/config.yaml (by
|
||||||
default). You should edit the file to suit your needs, as the values are
|
default). You should edit the file to suit your needs, as the values are
|
||||||
representative. All fields are optional except where indicated, so feel free
|
representative. All options are optional except where indicated, so feel free
|
||||||
to ignore anything you don't need.
|
to ignore anything you don't need.
|
||||||
|
|
||||||
|
Note that the configuration file is organized into distinct sections, each
|
||||||
|
with a section name like `location:` or `storage:`. So take care that if you
|
||||||
|
uncomment a particular option, also uncomment its containing section name, or
|
||||||
|
else borgmatic won't recognize the option.
|
||||||
|
|
||||||
You can also get the same sample configuration file from the [configuration
|
You can also get the same sample configuration file from the [configuration
|
||||||
reference](../../docs/reference/configuration.md), the authoritative set of
|
reference](../../docs/reference/configuration.md), the authoritative set of
|
||||||
all configuration options. This is handy if borgmatic has added new options
|
all configuration options. This is handy if borgmatic has added new options
|
||||||
@@ -71,6 +84,23 @@ FAQ](http://borgbackup.readthedocs.io/en/stable/faq.html#how-can-i-specify-the-e
|
|||||||
for more info.
|
for more info.
|
||||||
|
|
||||||
|
|
||||||
|
### Validation
|
||||||
|
|
||||||
|
If you'd like to validate that your borgmatic configuration is valid, the
|
||||||
|
following command is available for that:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo validate-borgmatic-config
|
||||||
|
```
|
||||||
|
|
||||||
|
This command's exit status (`$?` in Bash) is zero when configuration is valid
|
||||||
|
and non-zero otherwise.
|
||||||
|
|
||||||
|
Validating configuration can be useful if you generate your configuration
|
||||||
|
files via configuration management, or you just want to double check that your
|
||||||
|
hand edits are valid.
|
||||||
|
|
||||||
|
|
||||||
## Initialization
|
## Initialization
|
||||||
|
|
||||||
Before you can create backups with borgmatic, you first need to initialize a
|
Before you can create backups with borgmatic, you first need to initialize a
|
||||||
@@ -157,6 +187,12 @@ sudo systemctl start borgmatic.timer
|
|||||||
Feel free to modify the timer file based on how frequently you'd like
|
Feel free to modify the timer file based on how frequently you'd like
|
||||||
borgmatic to run.
|
borgmatic to run.
|
||||||
|
|
||||||
|
## Colored Output
|
||||||
|
|
||||||
|
Borgmatic uses [colorama](https://pypi.org/project/colorama/) to produce
|
||||||
|
colored terminal output by default. It is disabled when a non-interactive
|
||||||
|
terminal is detected (like a cron job). Otherwise, it can be disabled by
|
||||||
|
passing `--no-color` or by setting the environment variable `PY_COLORS=False`.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ In general, all you should need to do to upgrade borgmatic is run the
|
|||||||
following:
|
following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 install --upgrade borgmatic
|
sudo pip3 install --user --upgrade borgmatic
|
||||||
```
|
```
|
||||||
|
|
||||||
See below about special cases.
|
See below about special cases.
|
||||||
@@ -25,14 +25,14 @@ already running borgmatic with Python 3, then you can upgrade borgmatic
|
|||||||
in-place:
|
in-place:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 install --upgrade borgmatic
|
sudo pip3 install --user --upgrade borgmatic
|
||||||
```
|
```
|
||||||
|
|
||||||
But if you were running borgmatic with Python 2, uninstall and reinstall instead:
|
But if you were running borgmatic with Python 2, uninstall and reinstall instead:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip uninstall borgmatic
|
sudo pip uninstall borgmatic
|
||||||
sudo pip3 install borgmatic
|
sudo pip3 install --user borgmatic
|
||||||
```
|
```
|
||||||
|
|
||||||
The pip binary names for different versions of Python can differ, so the above
|
The pip binary names for different versions of Python can differ, so the above
|
||||||
@@ -67,7 +67,7 @@ from atticmatic to borgmatic by running the following commands:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo pip3 uninstall atticmatic
|
sudo pip3 uninstall atticmatic
|
||||||
sudo pip3 install borgmatic
|
sudo pip3 install --user borgmatic
|
||||||
```
|
```
|
||||||
|
|
||||||
That's it! borgmatic will continue using your /etc/borgmatic configuration
|
That's it! borgmatic will continue using your /etc/borgmatic configuration
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[tool.black]
|
||||||
|
line-length = 100
|
||||||
|
skip-string-normalization = true
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
# You can drop this file into /etc/cron.d/ to run borgmatic nightly.
|
# You can drop this file into /etc/cron.d/ to run borgmatic nightly.
|
||||||
|
|
||||||
0 3 * * * PATH=$PATH:/usr/bin /usr/bin/borgmatic
|
0 3 * * * PATH=$PATH:/usr/bin /root/.local/bin/borgmatic
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# You can drop this file into /etc/cron.d/ to run borgmatic nightly.
|
# You can drop this file into /etc/cron.d/ to run borgmatic nightly.
|
||||||
|
|
||||||
0 3 * * * root PATH=$PATH:/usr/local/bin /usr/local/bin/borgmatic
|
0 3 * * * root PATH=$PATH:/usr/local/bin /root/.local/bin/borgmatic
|
||||||
|
|||||||
@@ -3,4 +3,4 @@ Description=borgmatic backup
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
ExecStart=/usr/local/bin/borgmatic
|
ExecStart=/root/.local/bin/borgmatic
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
#!/usr/bin/env sh
|
|
||||||
|
|
||||||
if which black; then
|
|
||||||
black --skip-string-normalization --line-length 100 --check .
|
|
||||||
else
|
|
||||||
echo "Skipping black due to not being installed."
|
|
||||||
fi
|
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Temporary work around for https://github.com/pypa/pip/issues/6434
|
||||||
|
python -m pip install --upgrade pip==19.1.1
|
||||||
|
python -m pip install --no-use-pep517 $*
|
||||||
|
|
||||||
@@ -1,2 +1,18 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
description-file=README.md
|
description-file=README.md
|
||||||
|
|
||||||
|
[tool:pytest]
|
||||||
|
testpaths = tests
|
||||||
|
addopts = --cov-report term-missing:skip-covered --cov=borgmatic --ignore=tests/end-to-end
|
||||||
|
|
||||||
|
[flake8]
|
||||||
|
ignore = E501,W503
|
||||||
|
exclude = *.*/*
|
||||||
|
|
||||||
|
[tool:isort]
|
||||||
|
force_single_line = False
|
||||||
|
include_trailing_comma = True
|
||||||
|
known_first_party = borgmatic
|
||||||
|
line_length = 100
|
||||||
|
multi_line_output = 3
|
||||||
|
skip = .tox
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
|
VERSION = '1.3.4'
|
||||||
VERSION = '1.2.16'
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
@@ -26,9 +25,15 @@ setup(
|
|||||||
'borgmatic = borgmatic.commands.borgmatic:main',
|
'borgmatic = borgmatic.commands.borgmatic:main',
|
||||||
'upgrade-borgmatic-config = borgmatic.commands.convert_config:main',
|
'upgrade-borgmatic-config = borgmatic.commands.convert_config:main',
|
||||||
'generate-borgmatic-config = borgmatic.commands.generate_config:main',
|
'generate-borgmatic-config = borgmatic.commands.generate_config:main',
|
||||||
|
'validate-borgmatic-config = borgmatic.commands.validate_config:main',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
obsoletes=['atticmatic'],
|
obsoletes=['atticmatic'],
|
||||||
install_requires=('pykwalify>=1.6.0,<14.06', 'ruamel.yaml>0.15.0,<0.16.0', 'setuptools'),
|
install_requires=(
|
||||||
|
'pykwalify>=1.6.0,<14.06',
|
||||||
|
'ruamel.yaml>0.15.0,<0.16.0',
|
||||||
|
'setuptools',
|
||||||
|
'colorama>=0.4.1,<0.5',
|
||||||
|
),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ atomicwrites==1.2.1
|
|||||||
attrs==18.2.0
|
attrs==18.2.0
|
||||||
black==18.9b0; python_version >= '3.6'
|
black==18.9b0; python_version >= '3.6'
|
||||||
Click==7.0
|
Click==7.0
|
||||||
|
colorama==0.4.1
|
||||||
coverage==4.5.1
|
coverage==4.5.1
|
||||||
docopt==0.6.2
|
docopt==0.6.2
|
||||||
flake8==3.5.0
|
flake8==3.5.0
|
||||||
flexmock==0.10.2
|
flexmock==0.10.2
|
||||||
|
isort==4.3.19
|
||||||
mccabe==0.6.1
|
mccabe==0.6.1
|
||||||
more-itertools==4.3.0
|
more-itertools==4.3.0
|
||||||
pluggy==0.7.1
|
pluggy==0.7.1
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_config_command_with_valid_configuration_succeeds():
|
||||||
|
with tempfile.TemporaryDirectory() as temporary_directory:
|
||||||
|
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||||
|
|
||||||
|
subprocess.check_call(
|
||||||
|
'generate-borgmatic-config --destination {}'.format(config_path).split(' ')
|
||||||
|
)
|
||||||
|
exit_code = subprocess.call(
|
||||||
|
'validate-borgmatic-config --config {}'.format(config_path).split(' ')
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_config_command_with_invalid_configuration_fails():
|
||||||
|
with tempfile.TemporaryDirectory() as temporary_directory:
|
||||||
|
config_path = os.path.join(temporary_directory, 'test.yaml')
|
||||||
|
|
||||||
|
subprocess.check_call(
|
||||||
|
'generate-borgmatic-config --destination {}'.format(config_path).split(' ')
|
||||||
|
)
|
||||||
|
config = open(config_path).read().replace('keep_daily: 7', 'keep_daily: "7"')
|
||||||
|
config_file = open(config_path, 'w')
|
||||||
|
config_file.write(config)
|
||||||
|
config_file.close()
|
||||||
|
|
||||||
|
exit_code = subprocess.call(
|
||||||
|
'validate-borgmatic-config --config {}'.format(config_path).split(' ')
|
||||||
|
)
|
||||||
|
|
||||||
|
assert exit_code == 1
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.commands import borgmatic as module
|
from borgmatic.commands import borgmatic as module
|
||||||
|
|
||||||
@@ -142,14 +142,28 @@ def test_parse_arguments_disallows_init_and_dry_run():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_disallows_repository_without_extract():
|
def test_parse_arguments_disallows_repository_without_extract_or_list():
|
||||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
module.parse_arguments('--config', 'myconfig', '--repository', 'test.borg')
|
module.parse_arguments('--config', 'myconfig', '--repository', 'test.borg')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_disallows_archive_without_extract():
|
def test_parse_arguments_allows_repository_with_extract():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
|
module.parse_arguments(
|
||||||
|
'--config', 'myconfig', '--extract', '--repository', 'test.borg', '--archive', 'test'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_allows_repository_with_list():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
|
module.parse_arguments('--config', 'myconfig', '--list', '--repository', 'test.borg')
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_disallows_archive_without_extract_or_list():
|
||||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
@@ -169,6 +183,12 @@ def test_parse_arguments_allows_archive_with_extract():
|
|||||||
module.parse_arguments('--config', 'myconfig', '--extract', '--archive', 'test')
|
module.parse_arguments('--config', 'myconfig', '--extract', '--archive', 'test')
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_allows_archive_with_list():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
|
module.parse_arguments('--config', 'myconfig', '--list', '--archive', 'test')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_requires_archive_with_extract():
|
def test_parse_arguments_requires_archive_with_extract():
|
||||||
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
@@ -177,51 +197,73 @@ def test_parse_arguments_requires_archive_with_extract():
|
|||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_allows_progress_and_create():
|
def test_parse_arguments_allows_progress_and_create():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--progress', '--create', '--list')
|
module.parse_arguments('--progress', '--create', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_allows_progress_and_extract():
|
def test_parse_arguments_allows_progress_and_extract():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--progress', '--extract', '--archive', 'test', '--list')
|
module.parse_arguments('--progress', '--extract', '--archive', 'test', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_disallows_progress_without_create():
|
def test_parse_arguments_disallows_progress_without_create():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
module.parse_arguments('--progress', '--list')
|
module.parse_arguments('--progress', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_stats_and_create_flags_does_not_raise():
|
def test_parse_arguments_with_stats_and_create_flags_does_not_raise():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--stats', '--create', '--list')
|
module.parse_arguments('--stats', '--create', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_stats_and_prune_flags_does_not_raise():
|
def test_parse_arguments_with_stats_and_prune_flags_does_not_raise():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--stats', '--prune', '--list')
|
module.parse_arguments('--stats', '--prune', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error():
|
def test_parse_arguments_with_stats_flag_but_no_create_or_prune_flag_raises_value_error():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
module.parse_arguments('--stats', '--list')
|
module.parse_arguments('--stats', '--list')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_just_stats_flag_does_not_raise():
|
def test_parse_arguments_with_just_stats_flag_does_not_raise():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--stats')
|
module.parse_arguments('--stats')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_allows_json_with_list_or_info():
|
def test_parse_arguments_allows_json_with_list_or_info():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
module.parse_arguments('--list', '--json')
|
module.parse_arguments('--list', '--json')
|
||||||
module.parse_arguments('--info', '--json')
|
module.parse_arguments('--info', '--json')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_disallows_json_without_list_or_info():
|
def test_parse_arguments_disallows_json_without_list_or_info():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
module.parse_arguments('--json')
|
module.parse_arguments('--json')
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_disallows_json_with_both_list_and_info():
|
def test_parse_arguments_disallows_json_with_both_list_and_info():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
module.parse_arguments('--list', '--info', '--json')
|
module.parse_arguments('--list', '--info', '--json')
|
||||||
|
|
||||||
|
|
||||||
def test_borgmatic_version_matches_news_version():
|
def test_borgmatic_version_matches_news_version():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
borgmatic_version = subprocess.check_output(('borgmatic', '--version')).decode('ascii')
|
borgmatic_version = subprocess.check_output(('borgmatic', '--version')).decode('ascii')
|
||||||
news_version = open('NEWS').readline()
|
news_version = open('NEWS').readline()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.commands import convert_config as module
|
from borgmatic.commands import convert_config as module
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from borgmatic.commands import validate_config as module
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||||
|
config_paths = ['default']
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(config_paths)
|
||||||
|
|
||||||
|
parser = module.parse_arguments()
|
||||||
|
|
||||||
|
assert parser.config_paths == config_paths
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_multiple_config_paths_parses_as_list():
|
||||||
|
flexmock(module.collect).should_receive('get_default_config_paths').and_return(['default'])
|
||||||
|
|
||||||
|
parser = module.parse_arguments('--config', 'myconfig', 'otherconfig')
|
||||||
|
|
||||||
|
assert parser.config_paths == ['myconfig', 'otherconfig']
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
from io import StringIO
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.config import generate as module
|
from borgmatic.config import generate as module
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from io import StringIO
|
|
||||||
|
|
||||||
from collections import OrderedDict
|
|
||||||
import string
|
import string
|
||||||
|
from collections import OrderedDict
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
from borgmatic.config import legacy as module
|
from borgmatic.config import legacy as module
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from borgmatic.config import load as module
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_configuration_parses_contents():
|
||||||
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
|
builtins.should_receive('open').with_args('config.yaml').and_return('key: value')
|
||||||
|
|
||||||
|
assert module.load_configuration('config.yaml') == {'key': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_configuration_inlines_include():
|
||||||
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
|
builtins.should_receive('open').with_args('include.yaml').and_return('value')
|
||||||
|
builtins.should_receive('open').with_args('config.yaml').and_return(
|
||||||
|
'key: !include include.yaml'
|
||||||
|
)
|
||||||
|
|
||||||
|
assert module.load_configuration('config.yaml') == {'key': 'value'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_configuration_merges_include():
|
||||||
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
|
builtins.should_receive('open').with_args('include.yaml').and_return(
|
||||||
|
'''
|
||||||
|
foo: bar
|
||||||
|
baz: quux
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
builtins.should_receive('open').with_args('config.yaml').and_return(
|
||||||
|
'''
|
||||||
|
foo: override
|
||||||
|
<<: !include include.yaml
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
assert module.load_configuration('config.yaml') == {'foo': 'override', 'baz': 'quux'}
|
||||||
@@ -2,8 +2,8 @@ import io
|
|||||||
import string
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.config import validate as module
|
from borgmatic.config import validate as module
|
||||||
|
|
||||||
@@ -118,6 +118,67 @@ def test_parse_configuration_with_schema_lacking_examples_does_not_raise():
|
|||||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_configuration_inlines_include():
|
||||||
|
mock_config_and_schema(
|
||||||
|
'''
|
||||||
|
location:
|
||||||
|
source_directories:
|
||||||
|
- /home
|
||||||
|
|
||||||
|
repositories:
|
||||||
|
- hostname.borg
|
||||||
|
|
||||||
|
retention:
|
||||||
|
!include include.yaml
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
|
builtins.should_receive('open').with_args('include.yaml').and_return(
|
||||||
|
'''
|
||||||
|
keep_daily: 7
|
||||||
|
keep_hourly: 24
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
result = module.parse_configuration('config.yaml', 'schema.yaml')
|
||||||
|
|
||||||
|
assert result == {
|
||||||
|
'location': {'source_directories': ['/home'], 'repositories': ['hostname.borg']},
|
||||||
|
'retention': {'keep_daily': 7, 'keep_hourly': 24},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_configuration_merges_include():
|
||||||
|
mock_config_and_schema(
|
||||||
|
'''
|
||||||
|
location:
|
||||||
|
source_directories:
|
||||||
|
- /home
|
||||||
|
|
||||||
|
repositories:
|
||||||
|
- hostname.borg
|
||||||
|
|
||||||
|
retention:
|
||||||
|
keep_daily: 1
|
||||||
|
<<: !include include.yaml
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
builtins = flexmock(sys.modules['builtins'])
|
||||||
|
builtins.should_receive('open').with_args('include.yaml').and_return(
|
||||||
|
'''
|
||||||
|
keep_daily: 7
|
||||||
|
keep_hourly: 24
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
|
||||||
|
result = module.parse_configuration('config.yaml', 'schema.yaml')
|
||||||
|
|
||||||
|
assert result == {
|
||||||
|
'location': {'source_directories': ['/home'], 'repositories': ['hostname.borg']},
|
||||||
|
'retention': {'keep_daily': 1, 'keep_hourly': 24},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_parse_configuration_raises_for_missing_config_file():
|
def test_parse_configuration_raises_for_missing_config_file():
|
||||||
with pytest.raises(FileNotFoundError):
|
with pytest.raises(FileNotFoundError):
|
||||||
module.parse_configuration('config.yaml', 'schema.yaml')
|
module.parse_configuration('config.yaml', 'schema.yaml')
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
from subprocess import STDOUT
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
from subprocess import STDOUT
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import check as module
|
from borgmatic.borg import check as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+109
-38
@@ -3,6 +3,7 @@ import logging
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import create as module
|
from borgmatic.borg import create as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
@@ -69,11 +70,6 @@ def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
|
|||||||
module._write_pattern_file([])
|
module._write_pattern_file([])
|
||||||
|
|
||||||
|
|
||||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
|
||||||
subprocess = flexmock(module.subprocess)
|
|
||||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
|
||||||
|
|
||||||
|
|
||||||
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
def test_make_pattern_flags_includes_pattern_filename_when_given():
|
||||||
pattern_flags = module._make_pattern_flags(
|
pattern_flags = module._make_pattern_flags(
|
||||||
location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
|
location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
|
||||||
@@ -169,7 +165,9 @@ def test_create_archive_calls_borg_with_parameters():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND)
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND, capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -192,7 +190,9 @@ def test_create_archive_with_patterns_calls_borg_with_patterns():
|
|||||||
).and_return(None)
|
).and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
|
flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + pattern_flags)
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + pattern_flags, capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -215,7 +215,9 @@ def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
|
|||||||
)
|
)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
|
flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
|
||||||
insert_subprocess_mock(CREATE_COMMAND + exclude_flags)
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + exclude_flags, capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -236,7 +238,9 @@ def test_create_archive_with_log_info_calls_borg_with_info_parameter():
|
|||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--stats'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--stats'), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
@@ -257,8 +261,9 @@ def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
|
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc'),
|
||||||
|
capture_output=False,
|
||||||
)
|
)
|
||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
|
||||||
@@ -281,7 +286,9 @@ def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
|
|||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--dry-run',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--dry-run',), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=True,
|
dry_run=True,
|
||||||
@@ -304,7 +311,9 @@ def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_param
|
|||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--dry-run'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--info', '--dry-run'), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
@@ -328,8 +337,9 @@ def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_para
|
|||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
|
CREATE_COMMAND + ('--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run'),
|
||||||
|
capture_output=False,
|
||||||
)
|
)
|
||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
|
||||||
@@ -351,7 +361,9 @@ def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_inte
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--checkpoint-interval', '600'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--checkpoint-interval', '600'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -371,7 +383,9 @@ def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_param
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--chunker-params', '1,2,3,4'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--chunker-params', '1,2,3,4'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -391,7 +405,9 @@ def test_create_archive_with_compression_calls_borg_with_compression_parameters(
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--compression', 'rle'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -411,7 +427,9 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--remote-ratelimit', '100'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--remote-ratelimit', '100'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -425,13 +443,15 @@ def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameters():
|
def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
|
||||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
||||||
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--one-file-system',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--one-file-system',), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -446,13 +466,38 @@ def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_par
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
|
||||||
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
||||||
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
||||||
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--numeric-owner',), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
dry_run=False,
|
||||||
|
repository='repo',
|
||||||
|
location_config={
|
||||||
|
'source_directories': ['foo', 'bar'],
|
||||||
|
'repositories': ['repo'],
|
||||||
|
'numeric_owner': True,
|
||||||
|
'exclude_patterns': None,
|
||||||
|
},
|
||||||
|
storage_config={},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
|
def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
|
||||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
|
||||||
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
flexmock(module).should_receive('_expand_home_directories').and_return(())
|
||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--read-special',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--read-special',), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -473,7 +518,9 @@ def test_create_archive_with_bsd_flags_true_calls_borg_without_nobsdflags_parame
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND)
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND, capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -494,7 +541,9 @@ def test_create_archive_with_bsd_flags_false_calls_borg_with_nobsdflags_paramete
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--nobsdflags',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--nobsdflags',), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -515,7 +564,9 @@ def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters(
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--files-cache', 'ctime,size'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--files-cache', 'ctime,size'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -536,7 +587,9 @@ def test_create_archive_with_local_path_calls_borg_via_local_path():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(('borg1',) + CREATE_COMMAND[1:])
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg1',) + CREATE_COMMAND[1:], capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -557,7 +610,9 @@ def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters(
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--remote-path', 'borg1'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--remote-path', 'borg1'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -578,7 +633,9 @@ def test_create_archive_with_umask_calls_borg_with_umask_parameters():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--umask', '740'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--umask', '740'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -598,7 +655,9 @@ def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--lock-wait', '5'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--lock-wait', '5'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -618,9 +677,11 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(CREATE_COMMAND + ('--json',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
CREATE_COMMAND + ('--json',), capture_output=True
|
||||||
|
).and_return('[]')
|
||||||
|
|
||||||
module.create_archive(
|
json_output = module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
repository='repo',
|
repository='repo',
|
||||||
location_config={
|
location_config={
|
||||||
@@ -632,6 +693,8 @@ def test_create_archive_with_json_calls_borg_with_json_parameter():
|
|||||||
json=True,
|
json=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assert json_output == '[]'
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_source_directories_glob_expands():
|
def test_create_archive_with_source_directories_glob_expands():
|
||||||
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
|
flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
|
||||||
@@ -639,8 +702,9 @@ def test_create_archive_with_source_directories_glob_expands():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food')
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
||||||
|
capture_output=False,
|
||||||
)
|
)
|
||||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
|
||||||
|
|
||||||
@@ -662,7 +726,9 @@ def test_create_archive_with_non_matching_source_directories_glob_passes_through
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'), capture_output=False
|
||||||
|
)
|
||||||
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
@@ -683,8 +749,9 @@ def test_create_archive_with_glob_calls_borg_with_expanded_directories():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food')
|
('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
|
||||||
|
capture_output=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
@@ -705,7 +772,9 @@ def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
@@ -725,7 +794,9 @@ def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
|
|||||||
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
flexmock(module).should_receive('_write_pattern_file').and_return(None)
|
||||||
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
flexmock(module).should_receive('_make_pattern_flags').and_return(())
|
||||||
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
flexmock(module).should_receive('_make_exclude_flags').and_return(())
|
||||||
insert_subprocess_mock(('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.create_archive(
|
module.create_archive(
|
||||||
dry_run=False,
|
dry_run=False,
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from borgmatic.borg import execute as module
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_command_calls_full_command():
|
||||||
|
full_command = ['foo', 'bar']
|
||||||
|
subprocess = flexmock(module.subprocess)
|
||||||
|
subprocess.should_receive('check_call').with_args(full_command).once()
|
||||||
|
|
||||||
|
output = module.execute_command(full_command)
|
||||||
|
|
||||||
|
assert output is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_command_captures_output():
|
||||||
|
full_command = ['foo', 'bar']
|
||||||
|
expected_output = '[]'
|
||||||
|
subprocess = flexmock(module.subprocess)
|
||||||
|
subprocess.should_receive('check_output').with_args(full_command).and_return(
|
||||||
|
flexmock(decode=lambda: expected_output)
|
||||||
|
).once()
|
||||||
|
|
||||||
|
output = module.execute_command(full_command, capture_output=True)
|
||||||
|
|
||||||
|
assert output == expected_output
|
||||||
@@ -4,6 +4,7 @@ import sys
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import extract as module
|
from borgmatic.borg import extract as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
@@ -111,6 +112,7 @@ def test_extract_archive_calls_borg_with_restore_path_parameters():
|
|||||||
repository='repo',
|
repository='repo',
|
||||||
archive='archive',
|
archive='archive',
|
||||||
restore_paths=['path1', 'path2'],
|
restore_paths=['path1', 'path2'],
|
||||||
|
location_config={},
|
||||||
storage_config={},
|
storage_config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -123,11 +125,25 @@ def test_extract_archive_calls_borg_with_remote_path_parameters():
|
|||||||
repository='repo',
|
repository='repo',
|
||||||
archive='archive',
|
archive='archive',
|
||||||
restore_paths=None,
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
storage_config={},
|
storage_config={},
|
||||||
remote_path='borg1',
|
remote_path='borg1',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_archive_calls_borg_with_numeric_owner_parameter():
|
||||||
|
insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--numeric-owner'))
|
||||||
|
|
||||||
|
module.extract_archive(
|
||||||
|
dry_run=False,
|
||||||
|
repository='repo',
|
||||||
|
archive='archive',
|
||||||
|
restore_paths=None,
|
||||||
|
location_config={'numeric_owner': True},
|
||||||
|
storage_config={},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_extract_archive_calls_borg_with_umask_parameters():
|
def test_extract_archive_calls_borg_with_umask_parameters():
|
||||||
insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--umask', '0770'))
|
insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--umask', '0770'))
|
||||||
|
|
||||||
@@ -136,6 +152,7 @@ def test_extract_archive_calls_borg_with_umask_parameters():
|
|||||||
repository='repo',
|
repository='repo',
|
||||||
archive='archive',
|
archive='archive',
|
||||||
restore_paths=None,
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
storage_config={'umask': '0770'},
|
storage_config={'umask': '0770'},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -148,6 +165,7 @@ def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
|||||||
repository='repo',
|
repository='repo',
|
||||||
archive='archive',
|
archive='archive',
|
||||||
restore_paths=None,
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
storage_config={'lock_wait': '5'},
|
storage_config={'lock_wait': '5'},
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -157,7 +175,12 @@ def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
|||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
|
|
||||||
module.extract_archive(
|
module.extract_archive(
|
||||||
dry_run=False, repository='repo', archive='archive', restore_paths=None, storage_config={}
|
dry_run=False,
|
||||||
|
repository='repo',
|
||||||
|
archive='archive',
|
||||||
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
|
storage_config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -166,7 +189,12 @@ def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
|||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
|
||||||
module.extract_archive(
|
module.extract_archive(
|
||||||
dry_run=False, repository='repo', archive='archive', restore_paths=None, storage_config={}
|
dry_run=False,
|
||||||
|
repository='repo',
|
||||||
|
archive='archive',
|
||||||
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
|
storage_config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -174,7 +202,12 @@ def test_extract_archive_calls_borg_with_dry_run_parameter():
|
|||||||
insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--dry-run'))
|
insert_subprocess_mock(('borg', 'extract', 'repo::archive', '--dry-run'))
|
||||||
|
|
||||||
module.extract_archive(
|
module.extract_archive(
|
||||||
dry_run=True, repository='repo', archive='archive', restore_paths=None, storage_config={}
|
dry_run=True,
|
||||||
|
repository='repo',
|
||||||
|
archive='archive',
|
||||||
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
|
storage_config={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -186,6 +219,7 @@ def test_extract_archive_calls_borg_with_progress_parameter():
|
|||||||
repository='repo',
|
repository='repo',
|
||||||
archive='archive',
|
archive='archive',
|
||||||
restore_paths=None,
|
restore_paths=None,
|
||||||
|
location_config={},
|
||||||
storage_config={},
|
storage_config={},
|
||||||
progress=True,
|
progress=True,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,56 +3,65 @@ import logging
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import info as module
|
from borgmatic.borg import info as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
|
||||||
subprocess = flexmock(module.subprocess)
|
|
||||||
subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once()
|
|
||||||
|
|
||||||
|
|
||||||
INFO_COMMAND = ('borg', 'info', 'repo')
|
INFO_COMMAND = ('borg', 'info', 'repo')
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_calls_borg_with_parameters():
|
def test_display_archives_info_calls_borg_with_parameters():
|
||||||
insert_subprocess_mock(INFO_COMMAND)
|
flexmock(module).should_receive('execute_command').with_args(INFO_COMMAND, capture_output=False)
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config={})
|
module.display_archives_info(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
def test_display_archives_info_with_log_info_calls_borg_with_info_parameter():
|
||||||
insert_subprocess_mock(INFO_COMMAND + ('--info',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
INFO_COMMAND + ('--info',), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
module.display_archives_info(repository='repo', storage_config={})
|
module.display_archives_info(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
def test_display_archives_info_with_log_debug_calls_borg_with_debug_parameter():
|
||||||
insert_subprocess_mock(INFO_COMMAND + ('--debug', '--show-rc'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
INFO_COMMAND + ('--debug', '--show-rc'), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config={})
|
module.display_archives_info(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
def test_display_archives_info_with_json_calls_borg_with_json_parameter():
|
||||||
insert_subprocess_mock(INFO_COMMAND + ('--json',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
INFO_COMMAND + ('--json',), capture_output=True
|
||||||
|
).and_return('[]')
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config={}, json=True)
|
json_output = module.display_archives_info(repository='repo', storage_config={}, json=True)
|
||||||
|
|
||||||
|
assert json_output == '[]'
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
def test_display_archives_info_with_local_path_calls_borg_via_local_path():
|
||||||
insert_subprocess_mock(('borg1',) + INFO_COMMAND[1:])
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg1',) + INFO_COMMAND[1:], capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config={}, local_path='borg1')
|
module.display_archives_info(repository='repo', storage_config={}, local_path='borg1')
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
|
def test_display_archives_info_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||||
insert_subprocess_mock(INFO_COMMAND + ('--remote-path', 'borg1'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
INFO_COMMAND + ('--remote-path', 'borg1'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config={}, remote_path='borg1')
|
module.display_archives_info(repository='repo', storage_config={}, remote_path='borg1')
|
||||||
|
|
||||||
|
|
||||||
def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
def test_display_archives_info_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||||
storage_config = {'lock_wait': 5}
|
storage_config = {'lock_wait': 5}
|
||||||
insert_subprocess_mock(INFO_COMMAND + ('--lock-wait', '5'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
INFO_COMMAND + ('--lock-wait', '5'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.display_archives_info(repository='repo', storage_config=storage_config)
|
module.display_archives_info(repository='repo', storage_config=storage_config)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import logging
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import init as module
|
from borgmatic.borg import init as module
|
||||||
from ..test_verbosity import insert_logging_mock
|
|
||||||
|
|
||||||
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
INFO_REPOSITORY_EXISTS_RESPONSE_CODE = 0
|
INFO_REPOSITORY_EXISTS_RESPONSE_CODE = 0
|
||||||
INFO_REPOSITORY_NOT_FOUND_RESPONSE_CODE = 2
|
INFO_REPOSITORY_NOT_FOUND_RESPONSE_CODE = 2
|
||||||
|
|||||||
@@ -3,57 +3,75 @@ import logging
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import list as module
|
from borgmatic.borg import list as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
|
||||||
subprocess = flexmock(module.subprocess)
|
|
||||||
subprocess.should_receive('check_output').with_args(check_call_command, **kwargs).once()
|
|
||||||
|
|
||||||
|
|
||||||
LIST_COMMAND = ('borg', 'list', 'repo')
|
LIST_COMMAND = ('borg', 'list', 'repo')
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_calls_borg_with_parameters():
|
def test_list_archives_calls_borg_with_parameters():
|
||||||
insert_subprocess_mock(LIST_COMMAND)
|
flexmock(module).should_receive('execute_command').with_args(LIST_COMMAND, capture_output=False)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={})
|
module.list_archives(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_log_info_calls_borg_with_info_parameter():
|
def test_list_archives_with_log_info_calls_borg_with_info_parameter():
|
||||||
insert_subprocess_mock(LIST_COMMAND + ('--info',))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
LIST_COMMAND + ('--info',), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.INFO)
|
insert_logging_mock(logging.INFO)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={})
|
module.list_archives(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
|
def test_list_archives_with_log_debug_calls_borg_with_debug_parameter():
|
||||||
insert_subprocess_mock(LIST_COMMAND + ('--debug', '--show-rc'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
LIST_COMMAND + ('--debug', '--show-rc'), capture_output=False
|
||||||
|
)
|
||||||
insert_logging_mock(logging.DEBUG)
|
insert_logging_mock(logging.DEBUG)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={})
|
module.list_archives(repository='repo', storage_config={})
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_json_calls_borg_with_json_parameter():
|
def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
||||||
insert_subprocess_mock(LIST_COMMAND + ('--json',))
|
storage_config = {'lock_wait': 5}
|
||||||
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
LIST_COMMAND + ('--lock-wait', '5'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={}, json=True)
|
module.list_archives(repository='repo', storage_config=storage_config)
|
||||||
|
|
||||||
|
|
||||||
|
def test_list_archives_with_archive_calls_borg_with_archive_parameter():
|
||||||
|
storage_config = {}
|
||||||
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg', 'list', 'repo::archive'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
|
module.list_archives(repository='repo', storage_config=storage_config, archive='archive')
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_local_path_calls_borg_via_local_path():
|
def test_list_archives_with_local_path_calls_borg_via_local_path():
|
||||||
insert_subprocess_mock(('borg1',) + LIST_COMMAND[1:])
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
('borg1',) + LIST_COMMAND[1:], capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={}, local_path='borg1')
|
module.list_archives(repository='repo', storage_config={}, local_path='borg1')
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
def test_list_archives_with_remote_path_calls_borg_with_remote_path_parameters():
|
||||||
insert_subprocess_mock(LIST_COMMAND + ('--remote-path', 'borg1'))
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
|
LIST_COMMAND + ('--remote-path', 'borg1'), capture_output=False
|
||||||
|
)
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config={}, remote_path='borg1')
|
module.list_archives(repository='repo', storage_config={}, remote_path='borg1')
|
||||||
|
|
||||||
|
|
||||||
def test_list_archives_with_lock_wait_calls_borg_with_lock_wait_parameters():
|
def test_list_archives_with_json_calls_borg_with_json_parameter():
|
||||||
storage_config = {'lock_wait': 5}
|
flexmock(module).should_receive('execute_command').with_args(
|
||||||
insert_subprocess_mock(LIST_COMMAND + ('--lock-wait', '5'))
|
LIST_COMMAND + ('--json',), capture_output=True
|
||||||
|
).and_return('[]')
|
||||||
|
|
||||||
module.list_archives(repository='repo', storage_config=storage_config)
|
json_output = module.list_archives(repository='repo', storage_config={}, json=True)
|
||||||
|
|
||||||
|
assert json_output == '[]'
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from collections import OrderedDict
|
|||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.borg import prune as module
|
from borgmatic.borg import prune as module
|
||||||
|
|
||||||
from ..test_verbosity import insert_logging_mock
|
from ..test_verbosity import insert_logging_mock
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,71 +1,27 @@
|
|||||||
import json
|
|
||||||
import sys
|
|
||||||
|
|
||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.commands import borgmatic as module
|
from borgmatic.commands import borgmatic as module
|
||||||
|
|
||||||
|
|
||||||
def test_run_commands_handles_multiple_json_outputs_in_array():
|
|
||||||
(
|
|
||||||
flexmock(module)
|
|
||||||
.should_receive('_run_commands_on_repository')
|
|
||||||
.times(3)
|
|
||||||
.replace_with(
|
|
||||||
lambda args, consistency, json_results, local_path, location, remote_path, retention, storage, unexpanded_repository: json_results.append(
|
|
||||||
{"whatever": unexpanded_repository}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
(
|
|
||||||
flexmock(sys.stdout)
|
|
||||||
.should_call("write")
|
|
||||||
.with_args(
|
|
||||||
json.dumps(
|
|
||||||
json.loads(
|
|
||||||
'''
|
|
||||||
[
|
|
||||||
{"whatever": "fake_repo1"},
|
|
||||||
{"whatever": "fake_repo2"},
|
|
||||||
{"whatever": "fake_repo3"}
|
|
||||||
]
|
|
||||||
'''
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
module._run_commands(
|
|
||||||
args=flexmock(json=True),
|
|
||||||
consistency=None,
|
|
||||||
local_path=None,
|
|
||||||
location={'repositories': ['fake_repo1', 'fake_repo2', 'fake_repo3']},
|
|
||||||
remote_path=None,
|
|
||||||
retention=None,
|
|
||||||
storage=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_collect_configuration_run_summary_logs_info_for_success():
|
def test_collect_configuration_run_summary_logs_info_for_success():
|
||||||
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
flexmock(module).should_receive('run_configuration')
|
flexmock(module).should_receive('run_configuration').and_return([])
|
||||||
args = flexmock(extract=False)
|
args = flexmock(extract=False, list=False)
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
assert any(log for log in logs if log.levelno == module.logging.INFO)
|
assert all(log for log in logs if log.levelno == module.logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def test_collect_configuration_run_summary_logs_info_for_success_with_extract():
|
def test_collect_configuration_run_summary_logs_info_for_success_with_extract():
|
||||||
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
|
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
|
||||||
flexmock(module).should_receive('run_configuration')
|
flexmock(module).should_receive('run_configuration').and_return([])
|
||||||
args = flexmock(extract=True, repository='repo')
|
args = flexmock(extract=True, list=False, repository='repo')
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
assert any(log for log in logs if log.levelno == module.logging.INFO)
|
assert all(log for log in logs if log.levelno == module.logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def test_collect_configuration_run_summary_logs_critical_for_extract_with_repository_error():
|
def test_collect_configuration_run_summary_logs_critical_for_extract_with_repository_error():
|
||||||
@@ -73,16 +29,38 @@ def test_collect_configuration_run_summary_logs_critical_for_extract_with_reposi
|
|||||||
flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
|
flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
|
||||||
ValueError
|
ValueError
|
||||||
)
|
)
|
||||||
args = flexmock(extract=True, repository='repo')
|
args = flexmock(extract=True, list=False, repository='repo')
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
|
assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
|
||||||
|
|
||||||
|
|
||||||
|
def test_collect_configuration_run_summary_logs_critical_for_list_with_archive_and_repository_error():
|
||||||
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
|
flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
|
||||||
|
ValueError
|
||||||
|
)
|
||||||
|
args = flexmock(extract=False, list=True, repository='repo', archive='test')
|
||||||
|
|
||||||
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
|
assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
|
||||||
|
|
||||||
|
|
||||||
|
def test_collect_configuration_run_summary_logs_info_for_success_with_list():
|
||||||
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
|
flexmock(module).should_receive('run_configuration').and_return([])
|
||||||
|
args = flexmock(extract=False, list=True, repository='repo', archive=None)
|
||||||
|
|
||||||
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
|
assert all(log for log in logs if log.levelno == module.logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
def test_collect_configuration_run_summary_logs_critical_for_parse_error():
|
def test_collect_configuration_run_summary_logs_critical_for_parse_error():
|
||||||
flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError)
|
flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError)
|
||||||
args = flexmock(extract=False)
|
args = flexmock(extract=False, list=False)
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
@@ -93,7 +71,7 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error():
|
|||||||
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
|
flexmock(module.validate).should_receive('guard_configuration_contains_repository')
|
||||||
flexmock(module).should_receive('run_configuration').and_raise(ValueError)
|
flexmock(module).should_receive('run_configuration').and_raise(ValueError)
|
||||||
args = flexmock(extract=False)
|
args = flexmock(extract=False, list=False)
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args))
|
||||||
|
|
||||||
@@ -102,9 +80,22 @@ def test_collect_configuration_run_summary_logs_critical_for_run_error():
|
|||||||
|
|
||||||
def test_collect_configuration_run_summary_logs_critical_for_missing_configs():
|
def test_collect_configuration_run_summary_logs_critical_for_missing_configs():
|
||||||
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}})
|
||||||
flexmock(module).should_receive('run_configuration')
|
flexmock(module).should_receive('run_configuration').and_return([])
|
||||||
args = flexmock(config_paths=(), extract=False)
|
args = flexmock(config_paths=(), extract=False, list=False)
|
||||||
|
|
||||||
logs = tuple(module.collect_configuration_run_summary_logs(config_filenames=(), args=args))
|
logs = tuple(module.collect_configuration_run_summary_logs(config_filenames=(), args=args))
|
||||||
|
|
||||||
assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
|
assert any(log for log in logs if log.levelno == module.logging.CRITICAL)
|
||||||
|
|
||||||
|
|
||||||
|
def test_collect_configuration_run_summary_logs_outputs_merged_json_results():
|
||||||
|
flexmock(module.validate).should_receive('parse_configuration').and_return(
|
||||||
|
{'test.yaml': {}, 'test2.yaml': {}}
|
||||||
|
)
|
||||||
|
flexmock(module).should_receive('run_configuration').and_return(['foo', 'bar']).and_return(
|
||||||
|
['baz']
|
||||||
|
)
|
||||||
|
flexmock(module.sys.stdout).should_receive('write').with_args('["foo", "bar", "baz"]').once()
|
||||||
|
args = flexmock(extract=False, list=False)
|
||||||
|
|
||||||
|
tuple(module.collect_configuration_run_summary_logs(('test.yaml', 'test2.yaml'), args=args))
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ def test_execute_hook_invokes_each_command():
|
|||||||
subprocess = flexmock(module.subprocess)
|
subprocess = flexmock(module.subprocess)
|
||||||
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
||||||
|
|
||||||
module.execute_hook([':'], 'config.yaml', 'pre-backup')
|
module.execute_hook([':'], 'config.yaml', 'pre-backup', dry_run=False)
|
||||||
|
|
||||||
|
|
||||||
def test_execute_hook_with_multiple_commands_invokes_each_command():
|
def test_execute_hook_with_multiple_commands_invokes_each_command():
|
||||||
@@ -15,8 +15,15 @@ def test_execute_hook_with_multiple_commands_invokes_each_command():
|
|||||||
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
subprocess.should_receive('check_call').with_args(':', shell=True).once()
|
||||||
subprocess.should_receive('check_call').with_args('true', shell=True).once()
|
subprocess.should_receive('check_call').with_args('true', shell=True).once()
|
||||||
|
|
||||||
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup')
|
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_execute_hook_with_dry_run_skips_commands():
|
||||||
|
subprocess = flexmock(module.subprocess)
|
||||||
|
subprocess.should_receive('check_call').never()
|
||||||
|
|
||||||
|
module.execute_hook([':', 'true'], 'config.yaml', 'pre-backup', dry_run=True)
|
||||||
|
|
||||||
|
|
||||||
def test_execute_hook_with_empty_commands_does_not_raise():
|
def test_execute_hook_with_empty_commands_does_not_raise():
|
||||||
module.execute_hook([], 'config.yaml', 'post-backup')
|
module.execute_hook([], 'config.yaml', 'post-backup', dry_run=False)
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.config import collect as module
|
from borgmatic.config import collect as module
|
||||||
@@ -37,7 +39,10 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno
|
|||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar').and_return(True)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar').and_return(True)
|
||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.yaml').and_return(False)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.yaml').and_return(False)
|
||||||
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar', 'baz.yaml'])
|
flexmock(module.os).should_receive('listdir')
|
||||||
|
flexmock(sys.modules['builtins']).should_receive('sorted').and_return(
|
||||||
|
['foo.yaml', 'bar', 'baz.yaml']
|
||||||
|
)
|
||||||
|
|
||||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||||
|
|
||||||
@@ -56,7 +61,10 @@ def test_collect_config_filenames_collects_files_from_given_directories_and_igno
|
|||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/foo.yaml').and_return(False)
|
||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/bar.yaml~').and_return(False)
|
||||||
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False)
|
mock_path.should_receive('isdir').with_args('/etc/borgmatic.d/baz.txt').and_return(False)
|
||||||
flexmock(module.os).should_receive('listdir').and_return(['foo.yaml', 'bar.yaml~', 'baz.txt'])
|
flexmock(module.os).should_receive('listdir')
|
||||||
|
flexmock(sys.modules['builtins']).should_receive('sorted').and_return(
|
||||||
|
['foo.yaml', 'bar.yaml~', 'baz.txt']
|
||||||
|
)
|
||||||
|
|
||||||
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
config_filenames = tuple(module.collect_config_filenames(config_paths))
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
from collections import defaultdict, OrderedDict, namedtuple
|
|
||||||
import os
|
import os
|
||||||
|
from collections import OrderedDict, defaultdict, namedtuple
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.config import convert as module
|
from borgmatic.config import convert as module
|
||||||
|
|
||||||
|
|
||||||
Parsed_config = namedtuple('Parsed_config', ('location', 'storage', 'retention', 'consistency'))
|
Parsed_config = namedtuple('Parsed_config', ('location', 'storage', 'retention', 'consistency'))
|
||||||
|
|
||||||
|
|
||||||
@@ -91,7 +90,7 @@ def test_guard_configuration_upgraded_raises_when_only_source_config_present():
|
|||||||
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
flexmock(os.path).should_receive('exists').with_args('config.yaml').and_return(False)
|
||||||
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(False)
|
flexmock(os.path).should_receive('exists').with_args('other.yaml').and_return(False)
|
||||||
|
|
||||||
with pytest.raises(module.LegacyConfigurationNotUpgraded):
|
with pytest.raises(module.Legacy_configuration_not_upgraded):
|
||||||
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
module.guard_configuration_upgraded('config', ('config.yaml', 'other.yaml'))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
from borgmatic.config import legacy as module
|
from borgmatic.config import legacy as module
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import pytest
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from borgmatic import logger as module
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('bool_val', (True, 'yes', 'on', '1', 'true', 'True', 1))
|
||||||
|
def test_to_bool_parses_true_values(bool_val):
|
||||||
|
assert module.to_bool(bool_val)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('bool_val', (False, 'no', 'off', '0', 'false', 'False', 0))
|
||||||
|
def test_to_bool_parses_false_values(bool_val):
|
||||||
|
assert not module.to_bool(bool_val)
|
||||||
|
|
||||||
|
|
||||||
|
def test_to_bool_passes_none_through():
|
||||||
|
assert module.to_bool(None) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_do_markup_respects_no_color_value():
|
||||||
|
assert module.should_do_markup(no_color=True) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_do_markup_respects_PY_COLORS_environment_variable():
|
||||||
|
flexmock(module.os.environ).should_receive('get').and_return('True')
|
||||||
|
flexmock(module).should_receive('to_bool').and_return(True)
|
||||||
|
|
||||||
|
assert module.should_do_markup(no_color=False) is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_do_markup_prefers_no_color_value_to_PY_COLORS():
|
||||||
|
flexmock(module.os.environ).should_receive('get').and_return('True')
|
||||||
|
flexmock(module).should_receive('to_bool').and_return(True)
|
||||||
|
|
||||||
|
assert module.should_do_markup(no_color=True) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_do_markup_respects_stdout_tty_value():
|
||||||
|
flexmock(module.os.environ).should_receive('get').and_return(None)
|
||||||
|
|
||||||
|
assert module.should_do_markup(no_color=False) is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_do_markup_prefers_PY_COLORS_to_stdout_tty_value():
|
||||||
|
flexmock(module.os.environ).should_receive('get').and_return('True')
|
||||||
|
flexmock(module).should_receive('to_bool').and_return(True)
|
||||||
|
|
||||||
|
assert module.should_do_markup(no_color=False) is True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('method_name', ('critical', 'error', 'warn', 'info', 'debug'))
|
||||||
|
def test_borgmatic_logger_log_method_does_not_raise(method_name):
|
||||||
|
flexmock(module).should_receive('color_text')
|
||||||
|
flexmock(module.logging.Logger).should_receive(method_name)
|
||||||
|
|
||||||
|
getattr(module.Borgmatic_logger('test'), method_name)(msg='hi')
|
||||||
|
|
||||||
|
|
||||||
|
def test_borgmatic_logger_handle_does_not_raise():
|
||||||
|
flexmock(module).should_receive('color_text')
|
||||||
|
flexmock(module.logging.Logger).should_receive('handle')
|
||||||
|
|
||||||
|
module.Borgmatic_logger('test').handle(
|
||||||
|
module.logging.makeLogRecord(dict(levelno=module.logging.CRITICAL, msg='hi'))
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_color_text_does_not_raise():
|
||||||
|
module.color_text(module.colorama.Fore.RED, 'hi')
|
||||||
|
|
||||||
|
|
||||||
|
def test_color_text_without_color_does_not_raise():
|
||||||
|
module.color_text(None, 'hi')
|
||||||
@@ -1,27 +1,32 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = py3
|
envlist = py35,py36,py37
|
||||||
|
skip_missing_interpreters = True
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
minversion = 3.10.0
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
deps = -rtest_requirements.txt
|
deps = -rtest_requirements.txt
|
||||||
whitelist_externals = sh
|
whitelist_externals = sh
|
||||||
|
install_command =
|
||||||
|
sh scripts/pip {opts} {packages}
|
||||||
commands =
|
commands =
|
||||||
py.test --cov-report term-missing:skip-covered --cov=borgmatic --ignore=tests/end-to-end \
|
pytest
|
||||||
tests []
|
py36,py37: black --check .
|
||||||
sh scripts/black
|
isort --recursive --check-only --settings-path setup.cfg .
|
||||||
flake8 .
|
flake8 .
|
||||||
|
|
||||||
[testenv:black]
|
[testenv:black]
|
||||||
basepython = python3.7
|
basepython = python3.7
|
||||||
commands =
|
commands =
|
||||||
black --skip-string-normalization --line-length 100 .
|
black .
|
||||||
|
|
||||||
[testenv:end-to-end]
|
[testenv:end-to-end]
|
||||||
deps = -rtest_requirements.txt
|
deps = -rtest_requirements.txt
|
||||||
commands =
|
commands =
|
||||||
py.test tests/end-to-end []
|
pytest tests/end-to-end
|
||||||
|
|
||||||
[flake8]
|
[testenv:isort]
|
||||||
ignore = E501,W503
|
deps = {[testenv]deps}
|
||||||
exclude = *.*/*
|
commands =
|
||||||
|
isort {posargs:--recursive} --settings-path setup.cfg .
|
||||||
|
|||||||
Reference in New Issue
Block a user