Bumping setup.py version.
This commit is contained in:
parent
2639b7105a
commit
aa48b95ee7
6 changed files with 104 additions and 25 deletions
1
NEWS
1
NEWS
|
@ -1,5 +1,6 @@
|
||||||
0.0.4-dev
|
0.0.4-dev
|
||||||
|
|
||||||
|
* Helpful error message about how to create a repository if one is missing.
|
||||||
* Added a troubleshooting section with steps to deal with broken pipes.
|
* Added a troubleshooting section with steps to deal with broken pipes.
|
||||||
* Added nosetests config file (setup.cfg) with defaults.
|
* Added nosetests config file (setup.cfg) with defaults.
|
||||||
|
|
||||||
|
|
31
README.md
31
README.md
|
@ -37,18 +37,6 @@ available](https://torsion.org/hg/atticmatic). It's also mirrored on
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
To get up and running with Attic, follow the [Attic Quick
|
|
||||||
Start](https://attic-backup.org/quickstart.html) guide to create an Attic
|
|
||||||
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
|
|
||||||
passphrase instead of a key file, you'll need to set the `ATTIC_PASSPHRASE`
|
|
||||||
environment variable. See [attic's repository encryption
|
|
||||||
documentation](https://attic-backup.org/quickstart.html#encrypted-repos) for
|
|
||||||
more info.
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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 hg+https://torsion.org/hg/atticmatic
|
||||||
|
@ -59,7 +47,24 @@ Then copy the following configuration files:
|
||||||
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.
|
Modify those files with your desired configuration, including the path to an
|
||||||
|
attic repository.
|
||||||
|
|
||||||
|
If you don't yet have an attic repository, then the first time you run
|
||||||
|
atticmatic, you'll get an error with information on how to create a repository
|
||||||
|
on a local or remote host.
|
||||||
|
|
||||||
|
And 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.
|
||||||
|
|
||||||
|
It is recommended that you create your attic repository with keyfile
|
||||||
|
encryption, as passphrase-based encryption is less suited for automated
|
||||||
|
backups. If you do plan to run atticmatic 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` environment variable. See [attic's
|
||||||
|
repository encryption
|
||||||
|
documentation](https://attic-backup.org/quickstart.html#encrypted-repos) for
|
||||||
|
more info.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
from __future__ import print_function
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
def create_archive(excludes_filename, verbose, source_directories, repository):
|
def create_archive(excludes_filename, verbose, source_directories, repository):
|
||||||
|
@ -23,7 +26,14 @@ def create_archive(excludes_filename, verbose, source_directories, repository):
|
||||||
('--verbose', '--stats') if verbose else ()
|
('--verbose', '--stats') if verbose else ()
|
||||||
)
|
)
|
||||||
|
|
||||||
subprocess.check_call(command)
|
try:
|
||||||
|
subprocess.check_output(command, stderr=subprocess.STDOUT)
|
||||||
|
except subprocess.CalledProcessError, error:
|
||||||
|
print(error.output.strip(), file=sys.stderr)
|
||||||
|
|
||||||
|
if re.search('Error: Repository .* does not exist', error.output):
|
||||||
|
raise RuntimeError('To create a repository, run: attic init --encryption=keyfile {}'.format(repository))
|
||||||
|
raise error
|
||||||
|
|
||||||
|
|
||||||
def make_prune_flags(retention_config):
|
def make_prune_flags(retention_config):
|
||||||
|
|
|
@ -46,6 +46,6 @@ def main():
|
||||||
create_archive(args.excludes_filename, args.verbose, **location_config)
|
create_archive(args.excludes_filename, args.verbose, **location_config)
|
||||||
prune_archives(args.verbose, repository, retention_config)
|
prune_archives(args.verbose, repository, retention_config)
|
||||||
check_archives(args.verbose, repository)
|
check_archives(args.verbose, repository)
|
||||||
except (ValueError, IOError, CalledProcessError) as error:
|
except (ValueError, IOError, CalledProcessError, RuntimeError) as error:
|
||||||
print(error, file=sys.stderr)
|
print(error, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -1,14 +1,44 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
import sys
|
||||||
|
|
||||||
from flexmock import flexmock
|
from flexmock import flexmock
|
||||||
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
from atticmatic import attic as module
|
from atticmatic import attic as module
|
||||||
|
|
||||||
|
|
||||||
def insert_subprocess_mock(check_call_command, **kwargs):
|
class MockCalledProcessError(Exception):
|
||||||
subprocess = flexmock()
|
def __init__(self, output):
|
||||||
subprocess.should_receive('check_call').with_args(check_call_command, **kwargs).once()
|
self.output = output
|
||||||
|
|
||||||
|
|
||||||
|
def insert_subprocess_check_output_mock(call_command, error_output=None, **kwargs):
|
||||||
|
subprocess = flexmock(CalledProcessError=MockCalledProcessError, STDOUT=flexmock())
|
||||||
|
|
||||||
|
expectation = subprocess.should_receive('check_output').with_args(
|
||||||
|
call_command,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
**kwargs
|
||||||
|
).once()
|
||||||
|
|
||||||
|
if error_output:
|
||||||
|
expectation.and_raise(MockCalledProcessError, output=error_output)
|
||||||
|
flexmock(sys.modules['__builtin__']).should_receive('print')
|
||||||
|
|
||||||
flexmock(module).subprocess = subprocess
|
flexmock(module).subprocess = subprocess
|
||||||
|
return subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def insert_subprocess_check_call_mock(call_command, **kwargs):
|
||||||
|
subprocess = flexmock()
|
||||||
|
|
||||||
|
subprocess.should_receive('check_call').with_args(
|
||||||
|
call_command,
|
||||||
|
**kwargs
|
||||||
|
).once()
|
||||||
|
|
||||||
|
flexmock(module).subprocess = subprocess
|
||||||
|
return subprocess
|
||||||
|
|
||||||
|
|
||||||
def insert_platform_mock():
|
def insert_platform_mock():
|
||||||
|
@ -22,7 +52,7 @@ def insert_datetime_mock():
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_should_call_attic_with_parameters():
|
def test_create_archive_should_call_attic_with_parameters():
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_output_mock(
|
||||||
('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar'),
|
('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar'),
|
||||||
)
|
)
|
||||||
insert_platform_mock()
|
insert_platform_mock()
|
||||||
|
@ -37,7 +67,7 @@ def test_create_archive_should_call_attic_with_parameters():
|
||||||
|
|
||||||
|
|
||||||
def test_create_archive_with_verbose_should_call_attic_with_verbose_parameters():
|
def test_create_archive_with_verbose_should_call_attic_with_verbose_parameters():
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_output_mock(
|
||||||
(
|
(
|
||||||
'attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar',
|
'attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar',
|
||||||
'--verbose', '--stats',
|
'--verbose', '--stats',
|
||||||
|
@ -53,6 +83,39 @@ def test_create_archive_with_verbose_should_call_attic_with_verbose_parameters()
|
||||||
repository='repo',
|
repository='repo',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_create_archive_with_missing_repository_should_raise():
|
||||||
|
insert_subprocess_check_output_mock(
|
||||||
|
('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar'),
|
||||||
|
error_output='Error: Repository repo does not exist',
|
||||||
|
)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
with assert_raises(RuntimeError):
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbose=False,
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_archive_with_other_error_should_raise():
|
||||||
|
subprocess = insert_subprocess_check_output_mock(
|
||||||
|
('attic', 'create', '--exclude-from', 'excludes', 'repo::host-now', 'foo', 'bar'),
|
||||||
|
error_output='Something went wrong',
|
||||||
|
)
|
||||||
|
insert_platform_mock()
|
||||||
|
insert_datetime_mock()
|
||||||
|
|
||||||
|
with assert_raises(subprocess.CalledProcessError):
|
||||||
|
module.create_archive(
|
||||||
|
excludes_filename='excludes',
|
||||||
|
verbose=False,
|
||||||
|
source_directories='foo bar',
|
||||||
|
repository='repo',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
BASE_PRUNE_FLAGS = (
|
BASE_PRUNE_FLAGS = (
|
||||||
('--keep-daily', '1'),
|
('--keep-daily', '1'),
|
||||||
|
@ -80,7 +143,7 @@ def test_prune_archives_should_call_attic_with_parameters():
|
||||||
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
||||||
BASE_PRUNE_FLAGS,
|
BASE_PRUNE_FLAGS,
|
||||||
)
|
)
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_call_mock(
|
||||||
(
|
(
|
||||||
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
||||||
'3',
|
'3',
|
||||||
|
@ -99,7 +162,7 @@ def test_prune_archives_with_verbose_should_call_attic_with_verbose_parameters()
|
||||||
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
flexmock(module).should_receive('make_prune_flags').with_args(retention_config).and_return(
|
||||||
BASE_PRUNE_FLAGS,
|
BASE_PRUNE_FLAGS,
|
||||||
)
|
)
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_call_mock(
|
||||||
(
|
(
|
||||||
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
'attic', 'prune', 'repo', '--keep-daily', '1', '--keep-weekly', '2', '--keep-monthly',
|
||||||
'3', '--verbose',
|
'3', '--verbose',
|
||||||
|
@ -115,7 +178,7 @@ def test_prune_archives_with_verbose_should_call_attic_with_verbose_parameters()
|
||||||
|
|
||||||
def test_check_archives_should_call_attic_with_parameters():
|
def test_check_archives_should_call_attic_with_parameters():
|
||||||
stdout = flexmock()
|
stdout = flexmock()
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_call_mock(
|
||||||
('attic', 'check', 'repo'),
|
('attic', 'check', 'repo'),
|
||||||
stdout=stdout,
|
stdout=stdout,
|
||||||
)
|
)
|
||||||
|
@ -131,7 +194,7 @@ def test_check_archives_should_call_attic_with_parameters():
|
||||||
|
|
||||||
|
|
||||||
def test_check_archives_with_verbose_should_call_attic_with_verbose_parameters():
|
def test_check_archives_with_verbose_should_call_attic_with_verbose_parameters():
|
||||||
insert_subprocess_mock(
|
insert_subprocess_check_call_mock(
|
||||||
('attic', 'check', 'repo', '--verbose'),
|
('attic', 'check', 'repo', '--verbose'),
|
||||||
stdout=None,
|
stdout=None,
|
||||||
)
|
)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='atticmatic',
|
name='atticmatic',
|
||||||
version='0.0.2',
|
version='0.0.4',
|
||||||
description='A wrapper script for Attic backup software that creates and prunes backups',
|
description='A wrapper script for Attic backup software that creates and prunes backups',
|
||||||
author='Dan Helfman',
|
author='Dan Helfman',
|
||||||
author_email='witten@torsion.org',
|
author_email='witten@torsion.org',
|
||||||
|
|
Loading…
Reference in a new issue