mirror of
https://github.com/borgmatic-collective/borgmatic.git
synced 2026-08-06 16:23:00 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2456fc67f1 | ||
|
|
8a58b72934 | ||
|
|
6dc0173b74 | ||
|
|
5c58f85be1 | ||
|
|
3a9e32a411 | ||
|
|
30f6ec4f7d | ||
|
|
c67ab09e4d | ||
|
|
5299046b6b | ||
|
|
204e515bf7 | ||
|
|
1334da99e2 | ||
|
|
996ca19dac | ||
|
|
61969d17a2 | ||
|
|
d041e23d35 | ||
|
|
e996e09657 | ||
|
|
9c06874073 | ||
|
|
f5e0e10143 | ||
|
|
952a691f60 | ||
|
|
f94181480c | ||
|
|
c27b4a3497 | ||
|
|
58d33503a1 | ||
|
|
38322a3f6f | ||
|
|
52ab7cb881 | ||
|
|
17ac63aae6 | ||
|
|
1f1c8fdaba | ||
|
|
ce6196a5c6 | ||
|
|
6b0aa13856 | ||
|
|
d25db4cd0d | ||
|
|
7097ed67a6 | ||
|
|
52d5240fa0 | ||
|
|
5bf3a4875c | ||
|
|
d9125451f5 | ||
|
|
c3613e0637 | ||
|
|
c8f1af635f | ||
|
|
cfd61dc1d1 | ||
|
|
7750d2568c | ||
|
|
4e4f8c2670 |
@@ -6,3 +6,18 @@ b31d51b633701554e84f996cc0c73bad2990780b 0.0.5
|
|||||||
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
||||||
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
aa8a807f4ba28f0652764ed14713ffea2fd6922d 0.0.5
|
||||||
569aef47a9b25c55b13753f94706f5d330219995 0.0.5
|
569aef47a9b25c55b13753f94706f5d330219995 0.0.5
|
||||||
|
569aef47a9b25c55b13753f94706f5d330219995 0.0.5
|
||||||
|
a03495a8e8b471da63b5e2ae79d3ff9065839c2a 0.0.5
|
||||||
|
7ea93ca83f426ec0a608a68580c72c0775b81f86 0.0.6
|
||||||
|
cf4c7065f0711deda1cba878398bc05390e2c3f9 0.0.7
|
||||||
|
38d72677343f0a5d6845f4ac50d6778397083d45 0.1.0
|
||||||
|
ac5dfa01e9d14d09845f5e94c2c679e21c5eb2f9 0.1.1
|
||||||
|
ac5dfa01e9d14d09845f5e94c2c679e21c5eb2f9 0.1.1
|
||||||
|
7b6c87dca7ea312b2257ac1b46857b3f8c56b39c 0.1.1
|
||||||
|
83067f995dd391e38544a7722dc3b254b59c5521 0.1.2
|
||||||
|
acc7fb61566fe8028c179f43ecc735c851220b06 0.1.3
|
||||||
|
6dda59c12de88f060eb7244e6d330173985a9639 0.1.4
|
||||||
|
6dda59c12de88f060eb7244e6d330173985a9639 0.1.4
|
||||||
|
e58246fc92bb22c2b2fd8b86a1227de69d2d0315 0.1.4
|
||||||
|
0afff209b902698c2266986129d6dc9f5f913101 0.1.5
|
||||||
|
4c63f3d90ec2bf6af1714a3acec84654a7c9edf3 0.1.6
|
||||||
|
|||||||
@@ -1,3 +1,47 @@
|
|||||||
|
0.1.7
|
||||||
|
|
||||||
|
* #11: Fixed parsing of punctuation in configuration file.
|
||||||
|
* Better error message when configuration file is missing.
|
||||||
|
|
||||||
|
0.1.6
|
||||||
|
|
||||||
|
* #9: New configuration option for the encryption passphrase.
|
||||||
|
* #10: Support for Borg's new archive compression feature.
|
||||||
|
|
||||||
|
0.1.5
|
||||||
|
|
||||||
|
* Changes to support release on PyPI. Now pip installable by name!
|
||||||
|
|
||||||
|
0.1.4
|
||||||
|
|
||||||
|
* Adding test that setup.py version matches release version.
|
||||||
|
|
||||||
|
0.1.3
|
||||||
|
|
||||||
|
* #1: Add support for "borg check --last N" to Borg backend.
|
||||||
|
|
||||||
|
0.1.2
|
||||||
|
|
||||||
|
* As a convenience to new users, allow a missing default excludes file.
|
||||||
|
* New issue tracker, linked from documentation.
|
||||||
|
|
||||||
|
0.1.1
|
||||||
|
|
||||||
|
* Adding borgmatic cron example, and updating documentation to refer to it.
|
||||||
|
|
||||||
|
0.1.0
|
||||||
|
|
||||||
|
* New "borgmatic" command to support Borg backup software, a fork of Attic.
|
||||||
|
|
||||||
|
0.0.7
|
||||||
|
|
||||||
|
* Flag for multiple levels of verbosity: some, and lots.
|
||||||
|
* Improved mocking of Python builtins in unit tests.
|
||||||
|
|
||||||
|
0.0.6
|
||||||
|
|
||||||
|
* New configuration section for customizing which Attic consistency checks run, if any.
|
||||||
|
|
||||||
0.0.5
|
0.0.5
|
||||||
|
|
||||||
* Fixed regression with --verbose output being buffered. This means dropping the helpful error
|
* Fixed regression with --verbose output being buffered. This means dropping the helpful error
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
title: Atticmatic
|
title: Atticmatic
|
||||||
date:
|
|
||||||
save_as: atticmatic/index.html
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
atticmatic is a simple Python wrapper script for the [Attic backup
|
atticmatic is a simple Python wrapper script for the
|
||||||
software](https://attic-backup.org/) that initiates a backup, prunes any old
|
[Attic](https://attic-backup.org/) and
|
||||||
backups according to a retention policy, and validates backups for
|
[Borg](https://borgbackup.github.io/borgbackup/) backup software that
|
||||||
consistency. The script supports specifying your settings in a declarative
|
initiates a backup, prunes any old backups according to a retention policy,
|
||||||
configuration file rather than having to put them all on the command-line, and
|
and validates backups for consistency. The script supports specifying your
|
||||||
handles common errors.
|
settings in a declarative configuration file rather than having to put them
|
||||||
|
all on the command-line, and handles common errors.
|
||||||
|
|
||||||
Here's an example config file:
|
Here's an example config file:
|
||||||
|
|
||||||
@@ -17,7 +16,7 @@ Here's an example config file:
|
|||||||
# Space-separated list of source directories to backup.
|
# Space-separated list of source directories to backup.
|
||||||
source_directories: /home /etc
|
source_directories: /home /etc
|
||||||
|
|
||||||
# Path to local or remote Attic repository.
|
# Path to local or remote backup repository.
|
||||||
repository: user@backupserver:sourcehostname.attic
|
repository: user@backupserver:sourcehostname.attic
|
||||||
|
|
||||||
[retention]
|
[retention]
|
||||||
@@ -26,6 +25,10 @@ Here's an example config file:
|
|||||||
keep_weekly: 4
|
keep_weekly: 4
|
||||||
keep_monthly: 6
|
keep_monthly: 6
|
||||||
|
|
||||||
|
[consistency]
|
||||||
|
# Consistency checks to run, or "disabled" to prevent checks.
|
||||||
|
checks: repository archives
|
||||||
|
|
||||||
Additionally, exclude patterns can be specified in a separate excludes config
|
Additionally, exclude patterns can be specified in a separate excludes config
|
||||||
file, one pattern per line.
|
file, one pattern per line.
|
||||||
|
|
||||||
@@ -37,29 +40,35 @@ available](https://torsion.org/hg/atticmatic). It's also mirrored on
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
To get up and running with Attic, follow the [Attic Quick
|
To get up and running, follow the [Attic Quick
|
||||||
Start](https://attic-backup.org/quickstart.html) guide to create an Attic
|
Start](https://attic-backup.org/quickstart.html) or the [Borg Quick
|
||||||
|
Start](https://borgbackup.github.io/borgbackup/quickstart.html) to create a
|
||||||
repository on a local or remote host. Note that if you plan to run atticmatic
|
repository on a local or remote host. Note that if you plan to run atticmatic
|
||||||
on a schedule with cron, and you encrypt your attic repository with a
|
on a schedule with cron, and you encrypt your attic repository with a
|
||||||
passphrase instead of a key file, you'll need to set the `ATTIC_PASSPHRASE`
|
passphrase instead of a key file, you'll need to set the atticmatic
|
||||||
environment variable. See [attic's repository encryption
|
`encryption_passphrase` configuration variable. See the repository encryption
|
||||||
documentation](https://attic-backup.org/quickstart.html#encrypted-repos) for
|
section of the Quick Start for more info.
|
||||||
more info.
|
|
||||||
|
|
||||||
If the repository is on a remote host, make sure that your local root user has
|
If the repository is on a remote host, make sure that your local root user has
|
||||||
key-based ssh access to the desired user account on the remote host.
|
key-based ssh access to the desired user account on the remote host.
|
||||||
|
|
||||||
To install atticmatic, run the following command to download and install it:
|
To install atticmatic, run the following command to download and install it:
|
||||||
|
|
||||||
sudo pip install --upgrade hg+https://torsion.org/hg/atticmatic
|
sudo pip install --upgrade atticmatic
|
||||||
|
|
||||||
Then copy the following configuration files:
|
If you are using Attic, copy the following configuration files:
|
||||||
|
|
||||||
sudo cp sample/atticmatic.cron /etc/cron.d/atticmatic
|
sudo cp sample/atticmatic.cron /etc/cron.d/atticmatic
|
||||||
sudo mkdir /etc/atticmatic/
|
sudo mkdir /etc/atticmatic/
|
||||||
sudo cp sample/config sample/excludes /etc/atticmatic/
|
sudo cp sample/config sample/excludes /etc/atticmatic/
|
||||||
|
|
||||||
Lastly, modify those files with your desired configuration.
|
If you are using Borg, copy the files like this instead:
|
||||||
|
|
||||||
|
sudo cp sample/borgmatic.cron /etc/cron.d/borgmatic
|
||||||
|
sudo mkdir /etc/borgmatic/
|
||||||
|
sudo cp sample/config sample/excludes /etc/borgmatic/
|
||||||
|
|
||||||
|
Lastly, modify the /etc files with your desired configuration.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@@ -69,14 +78,23 @@ arguments:
|
|||||||
|
|
||||||
atticmatic
|
atticmatic
|
||||||
|
|
||||||
|
Or, if you're using Borg, use this command instead to make use of the Borg
|
||||||
|
backend:
|
||||||
|
|
||||||
|
borgmatic
|
||||||
|
|
||||||
This will also prune any old backups as per the configured retention policy,
|
This will also prune any old backups as per the configured retention policy,
|
||||||
and check backups for consistency problems due to things like file damage.
|
and check backups for consistency problems due to things like file damage.
|
||||||
|
|
||||||
By default, the backup will proceed silently except in the case of errors. But
|
By default, the backup will proceed silently except in the case of errors. But
|
||||||
if you'd like to to get additional information about the progress of the
|
if you'd like to to get additional information about the progress of the
|
||||||
backup as it proceeds, use the verbose option instead:
|
backup as it proceeds, use the verbosity option:
|
||||||
|
|
||||||
atticmattic --verbose
|
atticmattic --verbosity 1
|
||||||
|
|
||||||
|
Or, for even more progress spew:
|
||||||
|
|
||||||
|
atticmattic --verbosity 2
|
||||||
|
|
||||||
If you'd like to see the available command-line arguments, view the help:
|
If you'd like to see the available command-line arguments, view the help:
|
||||||
|
|
||||||
@@ -115,6 +133,11 @@ This should make the client keep the connection alive while validating
|
|||||||
backups.
|
backups.
|
||||||
|
|
||||||
|
|
||||||
## Feedback
|
## Issues and feedback
|
||||||
|
|
||||||
Questions? Comments? Got a patch? Contact <mailto:witten@torsion.org>.
|
Got an issue or an idea for a feature enhancement? Check out the [atticmatic
|
||||||
|
issue tracker](https://tree.taiga.io/project/witten-atticmatic/issues). In
|
||||||
|
order to create a new issue or comment on an issue, you'll need to [login
|
||||||
|
first](https://tree.taiga.io/login).
|
||||||
|
|
||||||
|
Other questions or comments? Contact <mailto:witten@torsion.org>.
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
from datetime import datetime
|
|
||||||
import os
|
|
||||||
import platform
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def create_archive(excludes_filename, verbose, source_directories, repository):
|
|
||||||
'''
|
|
||||||
Given an excludes filename, a vebosity flag, a space-separated list of source directories, and
|
|
||||||
a local or remote repository path, create an attic archive.
|
|
||||||
'''
|
|
||||||
sources = tuple(source_directories.split(' '))
|
|
||||||
|
|
||||||
command = (
|
|
||||||
'attic', 'create',
|
|
||||||
'--exclude-from', excludes_filename,
|
|
||||||
'{repo}::{hostname}-{timestamp}'.format(
|
|
||||||
repo=repository,
|
|
||||||
hostname=platform.node(),
|
|
||||||
timestamp=datetime.now().isoformat(),
|
|
||||||
),
|
|
||||||
) + sources + (
|
|
||||||
('--verbose', '--stats') if verbose else ()
|
|
||||||
)
|
|
||||||
|
|
||||||
subprocess.check_call(command)
|
|
||||||
|
|
||||||
|
|
||||||
def make_prune_flags(retention_config):
|
|
||||||
'''
|
|
||||||
Given a retention config dict mapping from option name to value, tranform it into an iterable of
|
|
||||||
command-line name-value flag pairs.
|
|
||||||
|
|
||||||
For example, given a retention config of:
|
|
||||||
|
|
||||||
{'keep_weekly': 4, 'keep_monthly': 6}
|
|
||||||
|
|
||||||
This will be returned as an iterable of:
|
|
||||||
|
|
||||||
(
|
|
||||||
('--keep-weekly', '4'),
|
|
||||||
('--keep-monthly', '6'),
|
|
||||||
)
|
|
||||||
'''
|
|
||||||
return (
|
|
||||||
('--' + option_name.replace('_', '-'), str(retention_config[option_name]))
|
|
||||||
for option_name, value in retention_config.items()
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def prune_archives(verbose, repository, retention_config):
|
|
||||||
'''
|
|
||||||
Given a verbosity flag, a local or remote repository path, and a retention config dict, prune
|
|
||||||
attic archives according the the retention policy specified in that configuration.
|
|
||||||
'''
|
|
||||||
command = (
|
|
||||||
'attic', 'prune',
|
|
||||||
repository,
|
|
||||||
) + tuple(
|
|
||||||
element
|
|
||||||
for pair in make_prune_flags(retention_config)
|
|
||||||
for element in pair
|
|
||||||
) + (('--verbose',) if verbose else ())
|
|
||||||
|
|
||||||
subprocess.check_call(command)
|
|
||||||
|
|
||||||
|
|
||||||
def check_archives(verbose, repository):
|
|
||||||
'''
|
|
||||||
Given a verbosity flag and a local or remote repository path, check the contained attic archives
|
|
||||||
for consistency.
|
|
||||||
'''
|
|
||||||
command = (
|
|
||||||
'attic', 'check',
|
|
||||||
repository,
|
|
||||||
) + (('--verbose',) if verbose else ())
|
|
||||||
|
|
||||||
# Attic's check command spews to stdout even without the verbose flag. Suppress it.
|
|
||||||
stdout = None if verbose else open(os.devnull, 'w')
|
|
||||||
|
|
||||||
subprocess.check_call(command, stdout=stdout)
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from atticmatic.backends import shared
|
||||||
|
|
||||||
|
# An atticmatic backend that supports Attic for actually handling backups.
|
||||||
|
|
||||||
|
COMMAND = 'attic'
|
||||||
|
CONFIG_FORMAT = shared.CONFIG_FORMAT
|
||||||
|
|
||||||
|
|
||||||
|
initialize = partial(shared.initialize, command=COMMAND)
|
||||||
|
create_archive = partial(shared.create_archive, command=COMMAND)
|
||||||
|
prune_archives = partial(shared.prune_archives, command=COMMAND)
|
||||||
|
check_archives = partial(shared.check_archives, command=COMMAND)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from atticmatic.config import Section_format, option
|
||||||
|
from atticmatic.backends import shared
|
||||||
|
|
||||||
|
# An atticmatic backend that supports Borg for actually handling backups.
|
||||||
|
|
||||||
|
COMMAND = 'borg'
|
||||||
|
CONFIG_FORMAT = (
|
||||||
|
shared.CONFIG_FORMAT[0], # location
|
||||||
|
Section_format(
|
||||||
|
'storage',
|
||||||
|
(
|
||||||
|
option('encryption_passphrase', required=False),
|
||||||
|
option('compression', required=False),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
shared.CONFIG_FORMAT[2], # retention
|
||||||
|
Section_format(
|
||||||
|
'consistency',
|
||||||
|
(
|
||||||
|
option('checks', required=False),
|
||||||
|
option('check_last', required=False),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
initialize = partial(shared.initialize, command=COMMAND)
|
||||||
|
create_archive = partial(shared.create_archive, command=COMMAND)
|
||||||
|
prune_archives = partial(shared.prune_archives, command=COMMAND)
|
||||||
|
check_archives = partial(shared.check_archives, command=COMMAND)
|
||||||
@@ -0,0 +1,210 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from atticmatic.config import Section_format, option
|
||||||
|
from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||||
|
|
||||||
|
|
||||||
|
# Common backend functionality shared by Attic and Borg. As the two backup
|
||||||
|
# commands diverge, these shared functions will likely need to be replaced
|
||||||
|
# with non-shared functions within atticmatic.backends.attic and
|
||||||
|
# atticmatic.backends.borg.
|
||||||
|
|
||||||
|
|
||||||
|
CONFIG_FORMAT = (
|
||||||
|
Section_format(
|
||||||
|
'location',
|
||||||
|
(
|
||||||
|
option('source_directories'),
|
||||||
|
option('repository'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Section_format(
|
||||||
|
'storage',
|
||||||
|
(
|
||||||
|
option('encryption_passphrase', required=False),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Section_format(
|
||||||
|
'retention',
|
||||||
|
(
|
||||||
|
option('keep_within', required=False),
|
||||||
|
option('keep_hourly', int, required=False),
|
||||||
|
option('keep_daily', int, required=False),
|
||||||
|
option('keep_weekly', int, required=False),
|
||||||
|
option('keep_monthly', int, required=False),
|
||||||
|
option('keep_yearly', int, required=False),
|
||||||
|
option('prefix', required=False),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Section_format(
|
||||||
|
'consistency',
|
||||||
|
(
|
||||||
|
option('checks', required=False),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(storage_config, command):
|
||||||
|
passphrase = storage_config.get('encryption_passphrase')
|
||||||
|
|
||||||
|
if passphrase:
|
||||||
|
os.environ['{}_PASSPHRASE'.format(command.upper())] = passphrase
|
||||||
|
|
||||||
|
|
||||||
|
def create_archive(
|
||||||
|
excludes_filename, verbosity, storage_config, source_directories, repository, command,
|
||||||
|
):
|
||||||
|
'''
|
||||||
|
Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated
|
||||||
|
list of source directories, a local or remote repository path, and a command to run, create an
|
||||||
|
attic archive.
|
||||||
|
'''
|
||||||
|
sources = tuple(source_directories.split(' '))
|
||||||
|
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
|
||||||
|
compression = storage_config.get('compression', None)
|
||||||
|
compression_flags = ('--compression', compression) if compression else ()
|
||||||
|
verbosity_flags = {
|
||||||
|
VERBOSITY_SOME: ('--stats',),
|
||||||
|
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
||||||
|
}.get(verbosity, ())
|
||||||
|
|
||||||
|
full_command = (
|
||||||
|
command, 'create',
|
||||||
|
'{repo}::{hostname}-{timestamp}'.format(
|
||||||
|
repo=repository,
|
||||||
|
hostname=platform.node(),
|
||||||
|
timestamp=datetime.now().isoformat(),
|
||||||
|
),
|
||||||
|
) + sources + exclude_flags + compression_flags + verbosity_flags
|
||||||
|
|
||||||
|
subprocess.check_call(full_command)
|
||||||
|
|
||||||
|
|
||||||
|
def _make_prune_flags(retention_config):
|
||||||
|
'''
|
||||||
|
Given a retention config dict mapping from option name to value, tranform it into an iterable of
|
||||||
|
command-line name-value flag pairs.
|
||||||
|
|
||||||
|
For example, given a retention config of:
|
||||||
|
|
||||||
|
{'keep_weekly': 4, 'keep_monthly': 6}
|
||||||
|
|
||||||
|
This will be returned as an iterable of:
|
||||||
|
|
||||||
|
(
|
||||||
|
('--keep-weekly', '4'),
|
||||||
|
('--keep-monthly', '6'),
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
return (
|
||||||
|
('--' + option_name.replace('_', '-'), str(retention_config[option_name]))
|
||||||
|
for option_name, value in retention_config.items()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def prune_archives(verbosity, repository, retention_config, command):
|
||||||
|
'''
|
||||||
|
Given a verbosity flag, a local or remote repository path, a retention config dict, and a
|
||||||
|
command to run, prune attic archives according the the retention policy specified in that
|
||||||
|
configuration.
|
||||||
|
'''
|
||||||
|
verbosity_flags = {
|
||||||
|
VERBOSITY_SOME: ('--stats',),
|
||||||
|
VERBOSITY_LOTS: ('--verbose', '--stats'),
|
||||||
|
}.get(verbosity, ())
|
||||||
|
|
||||||
|
full_command = (
|
||||||
|
command, 'prune',
|
||||||
|
repository,
|
||||||
|
) + tuple(
|
||||||
|
element
|
||||||
|
for pair in _make_prune_flags(retention_config)
|
||||||
|
for element in pair
|
||||||
|
) + verbosity_flags
|
||||||
|
|
||||||
|
subprocess.check_call(full_command)
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_CHECKS = ('repository', 'archives')
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_checks(consistency_config):
|
||||||
|
'''
|
||||||
|
Given a consistency config with a space-separated "checks" option, transform it to a tuple of
|
||||||
|
named checks to run.
|
||||||
|
|
||||||
|
For example, given a retention config of:
|
||||||
|
|
||||||
|
{'checks': 'repository archives'}
|
||||||
|
|
||||||
|
This will be returned as:
|
||||||
|
|
||||||
|
('repository', 'archives')
|
||||||
|
|
||||||
|
If no "checks" option is present, return the DEFAULT_CHECKS. If the checks value is the string
|
||||||
|
"disabled", return an empty tuple, meaning that no checks should be run.
|
||||||
|
'''
|
||||||
|
checks = consistency_config.get('checks', '').strip()
|
||||||
|
if not checks:
|
||||||
|
return DEFAULT_CHECKS
|
||||||
|
|
||||||
|
return tuple(
|
||||||
|
check for check in consistency_config['checks'].split(' ')
|
||||||
|
if check.lower() not in ('disabled', '')
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _make_check_flags(checks, check_last=None):
|
||||||
|
'''
|
||||||
|
Given a parsed sequence of checks, transform it into tuple of command-line flags.
|
||||||
|
|
||||||
|
For example, given parsed checks of:
|
||||||
|
|
||||||
|
('repository',)
|
||||||
|
|
||||||
|
This will be returned as:
|
||||||
|
|
||||||
|
('--repository-only',)
|
||||||
|
|
||||||
|
Additionally, if a check_last value is given, a "--last" flag will be added. Note that only
|
||||||
|
Borg supports this flag.
|
||||||
|
'''
|
||||||
|
last_flag = ('--last', check_last) if check_last else ()
|
||||||
|
if checks == DEFAULT_CHECKS:
|
||||||
|
return last_flag
|
||||||
|
|
||||||
|
return tuple(
|
||||||
|
'--{}-only'.format(check) for check in checks
|
||||||
|
) + last_flag
|
||||||
|
|
||||||
|
|
||||||
|
def check_archives(verbosity, repository, consistency_config, command):
|
||||||
|
'''
|
||||||
|
Given a verbosity flag, a local or remote repository path, a consistency config dict, and a
|
||||||
|
command to run, check the contained attic archives for consistency.
|
||||||
|
|
||||||
|
If there are no consistency checks to run, skip running them.
|
||||||
|
'''
|
||||||
|
checks = _parse_checks(consistency_config)
|
||||||
|
check_last = consistency_config.get('check_last', None)
|
||||||
|
if not checks:
|
||||||
|
return
|
||||||
|
|
||||||
|
verbosity_flags = {
|
||||||
|
VERBOSITY_SOME: ('--verbose',),
|
||||||
|
VERBOSITY_LOTS: ('--verbose',),
|
||||||
|
}.get(verbosity, ())
|
||||||
|
|
||||||
|
full_command = (
|
||||||
|
command, 'check',
|
||||||
|
repository,
|
||||||
|
) + _make_check_flags(checks, check_last) + verbosity_flags
|
||||||
|
|
||||||
|
# The check command spews to stdout even without the verbose flag. Suppress it.
|
||||||
|
stdout = None if verbosity_flags else open(os.devnull, 'w')
|
||||||
|
|
||||||
|
subprocess.check_call(full_command, stdout=stdout)
|
||||||
+40
-16
@@ -1,51 +1,75 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
from importlib import import_module
|
||||||
|
import os
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from atticmatic.attic import check_archives, create_archive, prune_archives
|
|
||||||
from atticmatic.config import parse_configuration
|
from atticmatic.config import parse_configuration
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONFIG_FILENAME = '/etc/atticmatic/config'
|
DEFAULT_CONFIG_FILENAME_PATTERN = '/etc/{}/config'
|
||||||
DEFAULT_EXCLUDES_FILENAME = '/etc/atticmatic/excludes'
|
DEFAULT_EXCLUDES_FILENAME_PATTERN = '/etc/{}/excludes'
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(*arguments):
|
def parse_arguments(command_name, *arguments):
|
||||||
'''
|
'''
|
||||||
Parse the given command-line arguments and return them as an ArgumentParser instance.
|
Given the name of the command with which this script was invoked and command-line arguments,
|
||||||
|
parse the arguments and return them as an ArgumentParser instance. Use the command name to
|
||||||
|
determine the default configuration and excludes paths.
|
||||||
'''
|
'''
|
||||||
|
config_filename_default = DEFAULT_CONFIG_FILENAME_PATTERN.format(command_name)
|
||||||
|
excludes_filename_default = DEFAULT_EXCLUDES_FILENAME_PATTERN.format(command_name)
|
||||||
|
|
||||||
parser = ArgumentParser()
|
parser = ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-c', '--config',
|
'-c', '--config',
|
||||||
dest='config_filename',
|
dest='config_filename',
|
||||||
default=DEFAULT_CONFIG_FILENAME,
|
default=config_filename_default,
|
||||||
help='Configuration filename',
|
help='Configuration filename',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--excludes',
|
'--excludes',
|
||||||
dest='excludes_filename',
|
dest='excludes_filename',
|
||||||
default=DEFAULT_EXCLUDES_FILENAME,
|
default=excludes_filename_default if os.path.exists(excludes_filename_default) else None,
|
||||||
help='Excludes filename',
|
help='Excludes filename',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'-v', '--verbose',
|
'-v', '--verbosity',
|
||||||
action='store_true',
|
type=int,
|
||||||
help='Display verbose progress information',
|
help='Display verbose progress (1 for some, 2 for lots)',
|
||||||
)
|
)
|
||||||
|
|
||||||
return parser.parse_args(arguments)
|
return parser.parse_args(arguments)
|
||||||
|
|
||||||
|
|
||||||
|
def load_backend(command_name):
|
||||||
|
'''
|
||||||
|
Given the name of the command with which this script was invoked, return the corresponding
|
||||||
|
backend module responsible for actually dealing with backups.
|
||||||
|
'''
|
||||||
|
backend_name = {
|
||||||
|
'atticmatic': 'attic',
|
||||||
|
'borgmatic': 'borg',
|
||||||
|
}.get(command_name, 'attic')
|
||||||
|
|
||||||
|
return import_module('atticmatic.backends.{}'.format(backend_name))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
args = parse_arguments(*sys.argv[1:])
|
command_name = os.path.basename(sys.argv[0])
|
||||||
location_config, retention_config = parse_configuration(args.config_filename)
|
args = parse_arguments(command_name, *sys.argv[1:])
|
||||||
repository = location_config['repository']
|
backend = load_backend(command_name)
|
||||||
|
config = parse_configuration(args.config_filename, backend.CONFIG_FORMAT)
|
||||||
|
repository = config.location['repository']
|
||||||
|
|
||||||
create_archive(args.excludes_filename, args.verbose, **location_config)
|
backend.initialize(config.storage)
|
||||||
prune_archives(args.verbose, repository, retention_config)
|
backend.create_archive(
|
||||||
check_archives(args.verbose, repository)
|
args.excludes_filename, args.verbosity, config.storage, **config.location
|
||||||
|
)
|
||||||
|
backend.prune_archives(args.verbosity, repository, config.retention)
|
||||||
|
backend.check_archives(args.verbosity, repository, config.consistency)
|
||||||
except (ValueError, IOError, CalledProcessError) as error:
|
except (ValueError, IOError, CalledProcessError) as error:
|
||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|||||||
+41
-43
@@ -2,10 +2,10 @@ from collections import OrderedDict, namedtuple
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# Python 2
|
# Python 2
|
||||||
from ConfigParser import ConfigParser
|
from ConfigParser import RawConfigParser
|
||||||
except ImportError:
|
except ImportError:
|
||||||
# Python 3
|
# Python 3
|
||||||
from configparser import ConfigParser
|
from configparser import RawConfigParser
|
||||||
|
|
||||||
|
|
||||||
Section_format = namedtuple('Section_format', ('name', 'options'))
|
Section_format = namedtuple('Section_format', ('name', 'options'))
|
||||||
@@ -20,49 +20,40 @@ def option(name, value_type=str, required=True):
|
|||||||
return Config_option(name, value_type, required)
|
return Config_option(name, value_type, required)
|
||||||
|
|
||||||
|
|
||||||
CONFIG_FORMAT = (
|
|
||||||
Section_format(
|
|
||||||
'location',
|
|
||||||
(
|
|
||||||
option('source_directories'),
|
|
||||||
option('repository'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Section_format(
|
|
||||||
'retention',
|
|
||||||
(
|
|
||||||
option('keep_within', required=False),
|
|
||||||
option('keep_hourly', int, required=False),
|
|
||||||
option('keep_daily', int, required=False),
|
|
||||||
option('keep_weekly', int, required=False),
|
|
||||||
option('keep_monthly', int, required=False),
|
|
||||||
option('keep_yearly', int, required=False),
|
|
||||||
option('prefix', required=False),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def validate_configuration_format(parser, config_format):
|
def validate_configuration_format(parser, config_format):
|
||||||
'''
|
'''
|
||||||
Given an open ConfigParser and an expected config file format, validate that the parsed
|
Given an open RawConfigParser and an expected config file format, validate that the parsed
|
||||||
configuration file has the expected sections, that any required options are present in those
|
configuration file has the expected sections, that any required options are present in those
|
||||||
sections, and that there aren't any unexpected options.
|
sections, and that there aren't any unexpected options.
|
||||||
|
|
||||||
|
A section is required if any of its contained options are required.
|
||||||
|
|
||||||
Raise ValueError if anything is awry.
|
Raise ValueError if anything is awry.
|
||||||
'''
|
'''
|
||||||
section_names = parser.sections()
|
section_names = set(parser.sections())
|
||||||
required_section_names = tuple(section.name for section in config_format)
|
required_section_names = tuple(
|
||||||
|
section.name for section in config_format
|
||||||
|
if any(option.required for option in section.options)
|
||||||
|
)
|
||||||
|
|
||||||
if set(section_names) != set(required_section_names):
|
unknown_section_names = section_names - set(
|
||||||
|
section_format.name for section_format in config_format
|
||||||
|
)
|
||||||
|
if unknown_section_names:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'Expected config sections {} but found sections: {}'.format(
|
'Unknown config sections found: {}'.format(', '.join(unknown_section_names))
|
||||||
', '.join(required_section_names),
|
)
|
||||||
', '.join(section_names)
|
|
||||||
)
|
missing_section_names = set(required_section_names) - section_names
|
||||||
|
if missing_section_names:
|
||||||
|
raise ValueError(
|
||||||
|
'Missing config sections: {}'.format(', '.join(missing_section_names))
|
||||||
)
|
)
|
||||||
|
|
||||||
for section_format in config_format:
|
for section_format in config_format:
|
||||||
|
if section_format.name not in section_names:
|
||||||
|
continue
|
||||||
|
|
||||||
option_names = parser.options(section_format.name)
|
option_names = parser.options(section_format.name)
|
||||||
expected_options = section_format.options
|
expected_options = section_format.options
|
||||||
|
|
||||||
@@ -92,7 +83,7 @@ def validate_configuration_format(parser, config_format):
|
|||||||
|
|
||||||
def parse_section_options(parser, section_format):
|
def parse_section_options(parser, section_format):
|
||||||
'''
|
'''
|
||||||
Given an open ConfigParser and an expected section format, return the option values from that
|
Given an open RawConfigParser and an expected section format, return the option values from that
|
||||||
section as a dict mapping from option name to value. Omit those options that are not present in
|
section as a dict mapping from option name to value. Omit those options that are not present in
|
||||||
the parsed options.
|
the parsed options.
|
||||||
|
|
||||||
@@ -110,19 +101,26 @@ def parse_section_options(parser, section_format):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def parse_configuration(config_filename):
|
def parse_configuration(config_filename, config_format):
|
||||||
'''
|
'''
|
||||||
Given a config filename of the expected format, return the parsed configuration as a tuple of
|
Given a config filename and an expected config file format, return the parsed configuration
|
||||||
(location config, retention config) where each config is a dict of that section's options.
|
as a namedtuple with one attribute for each parsed section.
|
||||||
|
|
||||||
Raise IOError if the file cannot be read, or ValueError if the format is not as expected.
|
Raise IOError if the file cannot be read, or ValueError if the format is not as expected.
|
||||||
'''
|
'''
|
||||||
parser = ConfigParser()
|
parser = RawConfigParser()
|
||||||
parser.readfp(open(config_filename))
|
if not parser.read(config_filename):
|
||||||
|
raise ValueError('Configuration file cannot be opened: {}'.format(config_filename))
|
||||||
|
|
||||||
validate_configuration_format(parser, CONFIG_FORMAT)
|
validate_configuration_format(parser, config_format)
|
||||||
|
|
||||||
return tuple(
|
# Describes a parsed configuration, where each attribute is the name of a configuration file
|
||||||
parse_section_options(parser, section_format)
|
# section and each value is a dict of that section's parsed options.
|
||||||
for section_format in CONFIG_FORMAT
|
Parsed_config = namedtuple('Parsed_config', (section_format.name for section_format in config_format))
|
||||||
|
|
||||||
|
return Parsed_config(
|
||||||
|
*(
|
||||||
|
parse_section_options(parser, section_format)
|
||||||
|
for section_format in config_format
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
from flexmock import flexmock
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def builtins_mock():
|
||||||
|
try:
|
||||||
|
# Python 2
|
||||||
|
return flexmock(sys.modules['__builtin__'])
|
||||||
|
except KeyError:
|
||||||
|
# Python 3
|
||||||
|
return flexmock(sys.modules['builtins'])
|
||||||
@@ -1,40 +1,72 @@
|
|||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from flexmock import flexmock
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
from atticmatic import command as module
|
from atticmatic import command as module
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_no_arguments_uses_defaults():
|
COMMAND_NAME = 'foomatic'
|
||||||
parser = module.parse_arguments()
|
|
||||||
|
|
||||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
|
||||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
def test_parse_arguments_with_no_arguments_uses_defaults():
|
||||||
assert parser.verbose == False
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME)
|
||||||
|
|
||||||
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
def test_parse_arguments_with_filename_arguments_overrides_defaults():
|
||||||
parser = module.parse_arguments('--config', 'myconfig', '--excludes', 'myexcludes')
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME, '--config', 'myconfig', '--excludes', 'myexcludes')
|
||||||
|
|
||||||
assert parser.config_filename == 'myconfig'
|
assert parser.config_filename == 'myconfig'
|
||||||
assert parser.excludes_filename == 'myexcludes'
|
assert parser.excludes_filename == 'myexcludes'
|
||||||
assert parser.verbose == False
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_verbose_flag_overrides_default():
|
def test_parse_arguments_with_missing_default_excludes_file_sets_filename_to_none():
|
||||||
parser = module.parse_arguments('--verbose')
|
flexmock(os.path).should_receive('exists').and_return(False)
|
||||||
|
|
||||||
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME
|
parser = module.parse_arguments(COMMAND_NAME)
|
||||||
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME
|
|
||||||
assert parser.verbose == True
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == None
|
||||||
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_missing_overridden_excludes_file_retains_filename():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(False)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME, '--excludes', 'myexcludes')
|
||||||
|
|
||||||
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == 'myexcludes'
|
||||||
|
assert parser.verbosity == None
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_arguments_with_verbosity_flag_overrides_default():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
|
|
||||||
|
parser = module.parse_arguments(COMMAND_NAME, '--verbosity', '1')
|
||||||
|
|
||||||
|
assert parser.config_filename == module.DEFAULT_CONFIG_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.excludes_filename == module.DEFAULT_EXCLUDES_FILENAME_PATTERN.format(COMMAND_NAME)
|
||||||
|
assert parser.verbosity == 1
|
||||||
|
|
||||||
|
|
||||||
def test_parse_arguments_with_invalid_arguments_exits():
|
def test_parse_arguments_with_invalid_arguments_exits():
|
||||||
|
flexmock(os.path).should_receive('exists').and_return(True)
|
||||||
original_stderr = sys.stderr
|
original_stderr = sys.stderr
|
||||||
sys.stderr = sys.stdout
|
sys.stderr = sys.stdout
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with assert_raises(SystemExit):
|
with assert_raises(SystemExit):
|
||||||
module.parse_arguments('--posix-me-harder')
|
module.parse_arguments(COMMAND_NAME, '--posix-me-harder')
|
||||||
finally:
|
finally:
|
||||||
sys.stderr = original_stderr
|
sys.stderr = original_stderr
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
try:
|
||||||
|
# Python 2
|
||||||
|
from cStringIO import StringIO
|
||||||
|
except ImportError:
|
||||||
|
# Python 3
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
import string
|
||||||
|
|
||||||
|
from atticmatic import config as module
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_section_options_with_punctuation_should_return_section_options():
|
||||||
|
parser = module.RawConfigParser()
|
||||||
|
parser.readfp(StringIO('[section]\nfoo: {}\n'.format(string.punctuation)))
|
||||||
|
|
||||||
|
section_format = module.Section_format(
|
||||||
|
'section',
|
||||||
|
(module.Config_option('foo', str, required=True),),
|
||||||
|
)
|
||||||
|
|
||||||
|
config = module.parse_section_options(parser, section_format)
|
||||||
|
|
||||||
|
assert config == OrderedDict(
|
||||||
|
(
|
||||||
|
('foo', string.punctuation),
|
||||||
|
)
|
||||||
|
)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def test_setup_version_matches_news_version():
|
||||||
|
setup_version = subprocess.check_output(('python', 'setup.py', '--version')).decode('ascii')
|
||||||
|
news_version = open('NEWS').readline()
|
||||||
|
|
||||||
|
assert setup_version == news_version
|
||||||
@@ -0,0 +1,325 @@
|
|||||||
|
from collections import OrderedDict
|
||||||
|
import os
|
||||||
|
|
||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from atticmatic.backends import shared as module
|
||||||
|
from atticmatic.tests.builtins import builtins_mock
|
||||||
|
from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
|
||||||
|
|
||||||
|
|
||||||
|
def test_initialize_with_passphrase_should_set_environment():
|
||||||
|
orig_environ = os.environ
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.environ = {}
|
||||||
|
module.initialize({'encryption_passphrase': 'pass'}, command='attic')
|
||||||
|
assert os.environ.get('ATTIC_PASSPHRASE') == 'pass'
|
||||||
|
finally:
|
||||||
|
os.environ = orig_environ
|
||||||
|
|
||||||
|
|
||||||
|
def test_initialize_without_passphrase_should_not_set_environment():
|
||||||
|
orig_environ = os.environ
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.environ = {}
|
||||||
|
module.initialize({}, command='attic')
|
||||||
|
assert os.environ.get('ATTIC_PASSPHRASE') == None
|
||||||
|
finally:
|
||||||
|
os.environ = orig_environ
|
||||||
|
|
||||||
|
|
||||||
|
def insert_subprocess_mock(check_call_command, **kwargs):
|
||||||
|
subprocess = flexmock()
|
||||||
|
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
||||||
|
flexmock(module).subprocess = subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def insert_subprocess_never():
|
||||||
|
subprocess = flexmock()
|
||||||
|
subprocess.should_receive('check_call').never()
|
||||||
|
flexmock(module).subprocess = subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def insert_platform_mock():
|
||||||
|
flexmock(module.platform).should_receive('node').and_return('host')
|
||||||
|
|
||||||
|
|
||||||
|
def insert_datetime_mock():
|
||||||
|
flexmock(module).datetime = flexmock().should_receive('now').and_return(
|
||||||
|
flexmock().should_receive('isoformat').and_return('now').mock
|
||||||
|
).mock
|
||||||
|
|
||||||
|
|
||||||
|
CREATE_COMMAND_WITHOUT_EXCLUDES = ('attic', 'create', 'repo::host-now', 'foo', 'bar')
|
||||||
|
CREATE_COMMAND = CREATE_COMMAND_WITHOUT_EXCLUDES + ('--exclude-from', 'excludes')
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_should_call_attic_with_parameters():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbosity=None,
|
||||||
|
storage_config={},
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_none_excludes_filename_should_call_attic_without_excludes():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND_WITHOUT_EXCLUDES)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename=None,
|
||||||
|
verbosity=None,
|
||||||
|
storage_config={},
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_verbosity_some_should_call_attic_with_stats_parameter():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND + ('--stats',))
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbosity=VERBOSITY_SOME,
|
||||||
|
storage_config={},
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_verbosity_lots_should_call_attic_with_verbose_parameter():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND + ('--verbose', '--stats'))
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbosity=VERBOSITY_LOTS,
|
||||||
|
storage_config={},
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_compression_should_call_attic_with_compression_parameters():
|
||||||
|
insert_subprocess_mock(CREATE_COMMAND + ('--compression', 'rle'))
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbosity=None,
|
||||||
|
storage_config={'compression': 'rle'},
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
BASE_PRUNE_FLAGS = (
|
||||||
|
('--keep-daily', '1'),
|
||||||
|
('--keep-weekly', '2'),
|
||||||
|
('--keep-monthly', '3'),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_prune_flags_should_return_flags_from_config():
|
||||||
|
retention_config = OrderedDict(
|
||||||
|
(
|
||||||
|
('keep_daily', 1),
|
||||||
|
('keep_weekly', 2),
|
||||||
|
('keep_monthly', 3),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
result = module._make_prune_flags(retention_config)
|
||||||
|
|
||||||
|
assert tuple(result) == BASE_PRUNE_FLAGS
|
||||||
|
|
||||||
|
|
||||||
|
PRUNE_COMMAND = (
|
||||||
|
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly', '3',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prune_archives_should_call_attic_with_parameters():
|
||||||
|
retention_config = flexmock()
|
||||||
|
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||||
|
BASE_PRUNE_FLAGS,
|
||||||
|
)
|
||||||
|
insert_subprocess_mock(PRUNE_COMMAND)
|
||||||
|
|
||||||
|
module.prune_archives(
|
||||||
|
verbosity=None,
|
||||||
|
repository='repo',
|
||||||
|
retention_config=retention_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prune_archives_with_verbosity_some_should_call_attic_with_stats_parameter():
|
||||||
|
retention_config = flexmock()
|
||||||
|
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||||
|
BASE_PRUNE_FLAGS,
|
||||||
|
)
|
||||||
|
insert_subprocess_mock(PRUNE_COMMAND + ('--stats',))
|
||||||
|
|
||||||
|
module.prune_archives(
|
||||||
|
repository='repo',
|
||||||
|
verbosity=VERBOSITY_SOME,
|
||||||
|
retention_config=retention_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_prune_archives_with_verbosity_lots_should_call_attic_with_verbose_parameter():
|
||||||
|
retention_config = flexmock()
|
||||||
|
flexmock(module).should_receive('_make_prune_flags').with_args(retention_config).and_return(
|
||||||
|
BASE_PRUNE_FLAGS,
|
||||||
|
)
|
||||||
|
insert_subprocess_mock(PRUNE_COMMAND + ('--verbose', '--stats',))
|
||||||
|
|
||||||
|
module.prune_archives(
|
||||||
|
repository='repo',
|
||||||
|
verbosity=VERBOSITY_LOTS,
|
||||||
|
retention_config=retention_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_checks_returns_them_as_tuple():
|
||||||
|
checks = module._parse_checks({'checks': 'foo disabled bar'})
|
||||||
|
|
||||||
|
assert checks == ('foo', 'bar')
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_checks_with_missing_value_returns_defaults():
|
||||||
|
checks = module._parse_checks({})
|
||||||
|
|
||||||
|
assert checks == module.DEFAULT_CHECKS
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_checks_with_blank_value_returns_defaults():
|
||||||
|
checks = module._parse_checks({'checks': ''})
|
||||||
|
|
||||||
|
assert checks == module.DEFAULT_CHECKS
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_checks_with_disabled_returns_no_checks():
|
||||||
|
checks = module._parse_checks({'checks': 'disabled'})
|
||||||
|
|
||||||
|
assert checks == ()
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_check_flags_with_checks_returns_flags():
|
||||||
|
flags = module._make_check_flags(('foo', 'bar'))
|
||||||
|
|
||||||
|
assert flags == ('--foo-only', '--bar-only')
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_check_flags_with_default_checks_returns_no_flags():
|
||||||
|
flags = module._make_check_flags(module.DEFAULT_CHECKS)
|
||||||
|
|
||||||
|
assert flags == ()
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_check_flags_with_checks_and_last_returns_flags_including_last():
|
||||||
|
flags = module._make_check_flags(('foo', 'bar'), check_last=3)
|
||||||
|
|
||||||
|
assert flags == ('--foo-only', '--bar-only', '--last', 3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_check_flags_with_last_returns_last_flag():
|
||||||
|
flags = module._make_check_flags(module.DEFAULT_CHECKS, check_last=3)
|
||||||
|
|
||||||
|
assert flags == ('--last', 3)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_archives_should_call_attic_with_parameters():
|
||||||
|
checks = flexmock()
|
||||||
|
check_last = flexmock()
|
||||||
|
consistency_config = flexmock().should_receive('get').and_return(check_last).mock
|
||||||
|
flexmock(module).should_receive('_parse_checks').and_return(checks)
|
||||||
|
flexmock(module).should_receive('_make_check_flags').with_args(checks, check_last).and_return(())
|
||||||
|
stdout = flexmock()
|
||||||
|
insert_subprocess_mock(
|
||||||
|
('attic', 'check', 'repo'),
|
||||||
|
stdout=stdout,
|
||||||
|
)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
builtins_mock().should_receive('open').and_return(stdout)
|
||||||
|
flexmock(module.os).should_receive('devnull')
|
||||||
|
|
||||||
|
module.check_archives(
|
||||||
|
verbosity=None,
|
||||||
|
repository='repo',
|
||||||
|
consistency_config=consistency_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_archives_with_verbosity_some_should_call_attic_with_verbose_parameter():
|
||||||
|
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||||
|
flexmock(module).should_receive('_parse_checks').and_return(flexmock())
|
||||||
|
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||||
|
insert_subprocess_mock(
|
||||||
|
('attic', 'check', 'repo', '--verbose'),
|
||||||
|
stdout=None,
|
||||||
|
)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.check_archives(
|
||||||
|
verbosity=VERBOSITY_SOME,
|
||||||
|
repository='repo',
|
||||||
|
consistency_config=consistency_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_archives_with_verbosity_lots_should_call_attic_with_verbose_parameter():
|
||||||
|
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||||
|
flexmock(module).should_receive('_parse_checks').and_return(flexmock())
|
||||||
|
flexmock(module).should_receive('_make_check_flags').and_return(())
|
||||||
|
insert_subprocess_mock(
|
||||||
|
('attic', 'check', 'repo', '--verbose'),
|
||||||
|
stdout=None,
|
||||||
|
)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
module.check_archives(
|
||||||
|
verbosity=VERBOSITY_LOTS,
|
||||||
|
repository='repo',
|
||||||
|
consistency_config=consistency_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_check_archives_without_any_checks_should_bail():
|
||||||
|
consistency_config = flexmock().should_receive('get').and_return(None).mock
|
||||||
|
flexmock(module).should_receive('_parse_checks').and_return(())
|
||||||
|
insert_subprocess_never()
|
||||||
|
|
||||||
|
module.check_archives(
|
||||||
|
verbosity=None,
|
||||||
|
repository='repo',
|
||||||
|
consistency_config=consistency_config,
|
||||||
|
command='attic',
|
||||||
|
)
|
||||||
@@ -1,144 +0,0 @@
|
|||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
from flexmock import flexmock
|
|
||||||
|
|
||||||
from atticmatic import attic as module
|
|
||||||
|
|
||||||
|
|
||||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
|
||||||
subprocess = flexmock()
|
|
||||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
|
||||||
flexmock(module).subprocess = subprocess
|
|
||||||
|
|
||||||
|
|
||||||
def insert_platform_mock():
|
|
||||||
flexmock(module).platform = flexmock().should_receive('node').and_return('host').mock
|
|
||||||
|
|
||||||
|
|
||||||
def insert_datetime_mock():
|
|
||||||
flexmock(module).datetime = flexmock().should_receive('now').and_return(
|
|
||||||
flexmock().should_receive('isoformat').and_return('now').mock
|
|
||||||
).mock
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_should_call_attic_with_parameters():
|
|
||||||
insert_subprocess_mock(
|
|
||||||
('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar'),
|
|
||||||
)
|
|
||||||
insert_platform_mock()
|
|
||||||
insert_datetime_mock()
|
|
||||||
|
|
||||||
module.create_archive(
|
|
||||||
excludes_filename='excludes',
|
|
||||||
verbose=False,
|
|
||||||
source_directories='foo bar',
|
|
||||||
repository='repo',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_verbose_should_call_attic_with_verbose_parameters():
|
|
||||||
insert_subprocess_mock(
|
|
||||||
(
|
|
||||||
'attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar',
|
|
||||||
'--verbose', '--stats',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
insert_platform_mock()
|
|
||||||
insert_datetime_mock()
|
|
||||||
|
|
||||||
module.create_archive(
|
|
||||||
excludes_filename='excludes',
|
|
||||||
verbose=True,
|
|
||||||
source_directories='foo bar',
|
|
||||||
repository='repo',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
BASE_PRUNE_FLAGS = (
|
|
||||||
('--keep-daily', '1'),
|
|
||||||
('--keep-weekly', '2'),
|
|
||||||
('--keep-monthly', '3'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_make_prune_flags_should_return_flags_from_config():
|
|
||||||
retention_config = OrderedDict(
|
|
||||||
(
|
|
||||||
('keep_daily', 1),
|
|
||||||
('keep_weekly', 2),
|
|
||||||
('keep_monthly', 3),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
result = module.make_prune_flags(retention_config)
|
|
||||||
|
|
||||||
assert tuple(result) == BASE_PRUNE_FLAGS
|
|
||||||
|
|
||||||
|
|
||||||
def test_prune_archives_should_call_attic_with_parameters():
|
|
||||||
retention_config = flexmock()
|
|
||||||
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
||||||
BASE_PRUNE_FLAGS,
|
|
||||||
)
|
|
||||||
insert_subprocess_mock(
|
|
||||||
(
|
|
||||||
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
|
||||||
'3',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
module.prune_archives(
|
|
||||||
verbose=False,
|
|
||||||
repository='repo',
|
|
||||||
retention_config=retention_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_prune_archives_with_verbose_should_call_attic_with_verbose_parameters():
|
|
||||||
retention_config = flexmock()
|
|
||||||
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
|
||||||
BASE_PRUNE_FLAGS,
|
|
||||||
)
|
|
||||||
insert_subprocess_mock(
|
|
||||||
(
|
|
||||||
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
|
||||||
'3', '--verbose',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
module.prune_archives(
|
|
||||||
repository='repo',
|
|
||||||
verbose=True,
|
|
||||||
retention_config=retention_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_archives_should_call_attic_with_parameters():
|
|
||||||
stdout = flexmock()
|
|
||||||
insert_subprocess_mock(
|
|
||||||
('attic', 'check', 'repo'),
|
|
||||||
stdout=stdout,
|
|
||||||
)
|
|
||||||
insert_platform_mock()
|
|
||||||
insert_datetime_mock()
|
|
||||||
flexmock(module).open = lambda filename, mode: stdout
|
|
||||||
flexmock(module).os = flexmock().should_receive('devnull').mock
|
|
||||||
|
|
||||||
module.check_archives(
|
|
||||||
verbose=False,
|
|
||||||
repository='repo',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_check_archives_with_verbose_should_call_attic_with_verbose_parameters():
|
|
||||||
insert_subprocess_mock(
|
|
||||||
('attic', 'check', 'repo', '--verbose'),
|
|
||||||
stdout=None,
|
|
||||||
)
|
|
||||||
insert_platform_mock()
|
|
||||||
insert_datetime_mock()
|
|
||||||
|
|
||||||
module.check_archives(
|
|
||||||
verbose=True,
|
|
||||||
repository='repo',
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
from flexmock import flexmock
|
||||||
|
|
||||||
|
from atticmatic import command as module
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_backend_with_atticmatic_command_should_return_attic_backend():
|
||||||
|
backend = flexmock()
|
||||||
|
(
|
||||||
|
flexmock(module).should_receive('import_module').with_args('atticmatic.backends.attic')
|
||||||
|
.and_return(backend).once()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert module.load_backend('atticmatic') == backend
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_backend_with_unknown_command_should_return_attic_backend():
|
||||||
|
backend = flexmock()
|
||||||
|
(
|
||||||
|
flexmock(module).should_receive('import_module').with_args('atticmatic.backends.attic')
|
||||||
|
.and_return(backend).once()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert module.load_backend('unknownmatic') == backend
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_backend_with_borgmatic_command_should_return_borg_backend():
|
||||||
|
backend = flexmock()
|
||||||
|
(
|
||||||
|
flexmock(module).should_receive('import_module').with_args('atticmatic.backends.borg')
|
||||||
|
.and_return(backend).once()
|
||||||
|
)
|
||||||
|
|
||||||
|
assert module.load_backend('borgmatic') == backend
|
||||||
@@ -41,19 +41,55 @@ def test_validate_configuration_format_with_valid_config_should_not_raise():
|
|||||||
module.validate_configuration_format(parser, config_format)
|
module.validate_configuration_format(parser, config_format)
|
||||||
|
|
||||||
|
|
||||||
def test_validate_configuration_format_with_missing_section_should_raise():
|
def test_validate_configuration_format_with_missing_required_section_should_raise():
|
||||||
parser = flexmock()
|
parser = flexmock()
|
||||||
parser.should_receive('sections').and_return(('section',))
|
parser.should_receive('sections').and_return(('section',))
|
||||||
config_format = (
|
config_format = (
|
||||||
module.Section_format('section', options=()),
|
module.Section_format(
|
||||||
module.Section_format('missing', options=()),
|
'section',
|
||||||
|
options=(
|
||||||
|
module.Config_option('stuff', str, required=True),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
# At least one option in this section is required, so the section is required.
|
||||||
|
module.Section_format(
|
||||||
|
'missing',
|
||||||
|
options=(
|
||||||
|
module.Config_option('such', str, required=False),
|
||||||
|
module.Config_option('things', str, required=True),
|
||||||
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
with assert_raises(ValueError):
|
with assert_raises(ValueError):
|
||||||
module.validate_configuration_format(parser, config_format)
|
module.validate_configuration_format(parser, config_format)
|
||||||
|
|
||||||
|
|
||||||
def test_validate_configuration_format_with_extra_section_should_raise():
|
def test_validate_configuration_format_with_missing_optional_section_should_not_raise():
|
||||||
|
parser = flexmock()
|
||||||
|
parser.should_receive('sections').and_return(('section',))
|
||||||
|
parser.should_receive('options').with_args('section').and_return(('stuff',))
|
||||||
|
config_format = (
|
||||||
|
module.Section_format(
|
||||||
|
'section',
|
||||||
|
options=(
|
||||||
|
module.Config_option('stuff', str, required=True),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
# No options in the section are required, so the section is optional.
|
||||||
|
module.Section_format(
|
||||||
|
'missing',
|
||||||
|
options=(
|
||||||
|
module.Config_option('such', str, required=False),
|
||||||
|
module.Config_option('things', str, required=False),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
module.validate_configuration_format(parser, config_format)
|
||||||
|
|
||||||
|
|
||||||
|
def test_validate_configuration_format_with_unknown_section_should_raise():
|
||||||
parser = flexmock()
|
parser = flexmock()
|
||||||
parser.should_receive('sections').and_return(('section', 'extra'))
|
parser.should_receive('sections').and_return(('section', 'extra'))
|
||||||
config_format = (
|
config_format = (
|
||||||
@@ -139,28 +175,56 @@ def test_parse_section_options_should_return_section_options():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_section_options_for_missing_section_should_return_empty_dict():
|
||||||
|
parser = flexmock()
|
||||||
|
parser.should_receive('get').never()
|
||||||
|
parser.should_receive('getint').never()
|
||||||
|
parser.should_receive('has_option').with_args('section', 'foo').and_return(False)
|
||||||
|
parser.should_receive('has_option').with_args('section', 'bar').and_return(False)
|
||||||
|
|
||||||
|
section_format = module.Section_format(
|
||||||
|
'section',
|
||||||
|
(
|
||||||
|
module.Config_option('foo', str, required=False),
|
||||||
|
module.Config_option('bar', int, required=False),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
config = module.parse_section_options(parser, section_format)
|
||||||
|
|
||||||
|
assert config == OrderedDict()
|
||||||
|
|
||||||
|
|
||||||
def insert_mock_parser():
|
def insert_mock_parser():
|
||||||
parser = flexmock()
|
parser = flexmock()
|
||||||
parser.should_receive('readfp')
|
parser.should_receive('read').and_return([flexmock()])
|
||||||
flexmock(module).open = lambda filename: None
|
module.RawConfigParser = lambda: parser
|
||||||
flexmock(module).ConfigParser = parser
|
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def test_parse_configuration_should_return_section_configs():
|
def test_parse_configuration_should_return_section_configs():
|
||||||
parser = insert_mock_parser()
|
parser = insert_mock_parser()
|
||||||
|
config_format = (flexmock(name='items'), flexmock(name='things'))
|
||||||
mock_module = flexmock(module)
|
mock_module = flexmock(module)
|
||||||
mock_module.should_receive('validate_configuration_format').with_args(
|
mock_module.should_receive('validate_configuration_format').with_args(
|
||||||
parser, module.CONFIG_FORMAT,
|
parser, config_format,
|
||||||
).once()
|
).once()
|
||||||
mock_section_configs = (flexmock(), flexmock())
|
mock_section_configs = (flexmock(), flexmock())
|
||||||
|
|
||||||
for section_format, section_config in zip(module.CONFIG_FORMAT, mock_section_configs):
|
for section_format, section_config in zip(config_format, mock_section_configs):
|
||||||
mock_module.should_receive('parse_section_options').with_args(
|
mock_module.should_receive('parse_section_options').with_args(
|
||||||
parser, section_format,
|
parser, section_format,
|
||||||
).and_return(section_config).once()
|
).and_return(section_config).once()
|
||||||
|
|
||||||
section_configs = module.parse_configuration('filename')
|
parsed_config = module.parse_configuration('filename', config_format)
|
||||||
|
|
||||||
assert section_configs == mock_section_configs
|
assert parsed_config == type(parsed_config)(*mock_section_configs)
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_configuration_with_file_open_error_should_raise():
|
||||||
|
parser = insert_mock_parser()
|
||||||
|
parser.should_receive('read').and_return([])
|
||||||
|
|
||||||
|
with assert_raises(ValueError):
|
||||||
|
module.parse_configuration('filename', config_format=flexmock())
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
VERBOSITY_SOME = 1
|
||||||
|
VERBOSITY_LOTS = 2
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# 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
|
||||||
+23
-4
@@ -2,16 +2,35 @@
|
|||||||
# Space-separated list of source directories to backup.
|
# Space-separated list of source directories to backup.
|
||||||
source_directories: /home /etc
|
source_directories: /home /etc
|
||||||
|
|
||||||
# Path to local or remote Attic repository.
|
# Path to local or remote repository.
|
||||||
repository: user@backupserver:sourcehostname.attic
|
repository: user@backupserver:sourcehostname.attic
|
||||||
|
|
||||||
|
[storage]
|
||||||
|
# Passphrase to unlock the encryption key with. Only use on repositories that
|
||||||
|
# were initialized with passphrase/repokey encryption.
|
||||||
|
#encryption_passphrase: foo
|
||||||
|
# For Borg only, you can specify the type of compression to use when creating
|
||||||
|
# archives. See https://borgbackup.github.io/borgbackup/usage.html#borg-create
|
||||||
|
# for details. Defaults to no compression.
|
||||||
|
#compression: lz4
|
||||||
|
|
||||||
[retention]
|
[retention]
|
||||||
# Retention policy for how many backups to keep in each category.
|
# Retention policy for how many backups to keep in each category. See
|
||||||
# See https://attic-backup.org/usage.html#attic-prune for details.
|
# https://attic-backup.org/usage.html#attic-prune or
|
||||||
#keep_within: 3h
|
# https://borgbackup.github.io/borgbackup/usage.html#borg-prune for details.
|
||||||
|
#keep_within: 3H
|
||||||
#keep_hourly: 24
|
#keep_hourly: 24
|
||||||
keep_daily: 7
|
keep_daily: 7
|
||||||
keep_weekly: 4
|
keep_weekly: 4
|
||||||
keep_monthly: 6
|
keep_monthly: 6
|
||||||
keep_yearly: 1
|
keep_yearly: 1
|
||||||
#prefix: sourcehostname
|
#prefix: sourcehostname
|
||||||
|
|
||||||
|
[consistency]
|
||||||
|
# Space-separated list of consistency checks to run: "repository", "archives",
|
||||||
|
# or both. Defaults to both. Set to "disabled" to disable all consistency
|
||||||
|
# checks. See https://attic-backup.org/usage.html#attic-check or
|
||||||
|
# https://borgbackup.github.io/borgbackup/usage.html#borg-check for details.
|
||||||
|
checks: repository archives
|
||||||
|
# For Borg only, you can restrict the number of checked archives to the last n.
|
||||||
|
#check_last: 3
|
||||||
|
|||||||
@@ -1,2 +1,5 @@
|
|||||||
|
[metadata]
|
||||||
|
description-file=README.md
|
||||||
|
|
||||||
[nosetests]
|
[nosetests]
|
||||||
detailed-errors=1
|
detailed-errors=1
|
||||||
|
|||||||
@@ -1,13 +1,33 @@
|
|||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
|
||||||
|
VERSION = '0.1.7'
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='atticmatic',
|
name='atticmatic',
|
||||||
version='0.0.5',
|
version=VERSION,
|
||||||
description='A wrapper script for Attic backup software that creates and prunes backups',
|
description='A wrapper script for Attic/Borg backup software that creates and prunes backups',
|
||||||
author='Dan Helfman',
|
author='Dan Helfman',
|
||||||
author_email='witten@torsion.org',
|
author_email='witten@torsion.org',
|
||||||
|
url='https://torsion.org/atticmatic',
|
||||||
|
download_url='https://torsion.org/hg/atticmatic/archive/%s.tar.gz' % VERSION,
|
||||||
|
classifiers=(
|
||||||
|
'Development Status :: 5 - Production/Stable',
|
||||||
|
'Environment :: Console',
|
||||||
|
'Intended Audience :: System Administrators',
|
||||||
|
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
|
||||||
|
'Programming Language :: Python',
|
||||||
|
'Topic :: Security :: Cryptography',
|
||||||
|
'Topic :: System :: Archiving :: Backup',
|
||||||
|
),
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
entry_points={'console_scripts': ['atticmatic = atticmatic.command:main']},
|
entry_points={
|
||||||
|
'console_scripts': [
|
||||||
|
'atticmatic = atticmatic.command:main',
|
||||||
|
'borgmatic = atticmatic.command:main',
|
||||||
|
]
|
||||||
|
},
|
||||||
tests_require=(
|
tests_require=(
|
||||||
'flexmock',
|
'flexmock',
|
||||||
'nose',
|
'nose',
|
||||||
|
|||||||
Reference in New Issue
Block a user