Merge pull request #5 from ypid/support-file-globs

Added support for file globs in source_directories.
This commit is contained in:
Dan Helfman 2016-02-13 16:32:05 -08:00
commit 45a2b9cded
5 changed files with 25 additions and 4 deletions

1
NEWS
View file

@ -3,6 +3,7 @@
* Fixed handling of repeated spaces in source_directories which resulted in backup up everything.
* Added support for --one-file-system for Borg.
* Support borg create --umask.
* Added support for file globs in source_directories.
0.1.7

View file

@ -15,7 +15,8 @@ Here's an example config file:
```INI
[location]
# Space-separated list of source directories to backup.
source_directories: /home /etc
# Globs are expanded.
source_directories: /home /etc /var/log/syslog*
# Path to local or remote backup repository.
repository: user@backupserver:sourcehostname.attic

View file

@ -3,6 +3,8 @@ import os
import re
import platform
import subprocess
from glob import glob
from itertools import chain
from atticmatic.config import Section_format, option
from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
@ -58,14 +60,15 @@ def initialize(storage_config, command):
def create_archive(
excludes_filename, verbosity, storage_config, source_directories, repository, command,
one_file_system=None,
one_file_system=None
):
'''
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(re.split('\s+', source_directories))
sources = re.split('\s+', source_directories)
sources = tuple(chain.from_iterable([glob(x) if glob(x) else [x] for x in sources]))
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
compression = storage_config.get('compression', None)
compression_flags = ('--compression', compression) if compression else ()

View file

@ -177,6 +177,21 @@ def test_create_archive_with_umask_should_call_attic_with_umask_parameters():
)
def test_create_archive_with_globs():
insert_subprocess_mock(('attic', 'create', 'repo::host-now', 'setup.py', 'setup.cfg'))
insert_platform_mock()
insert_datetime_mock()
module.create_archive(
excludes_filename=None,
verbosity=None,
storage_config={},
source_directories='setup*',
repository='repo',
command='attic',
)
BASE_PRUNE_FLAGS = (
('--keep-daily', '1'),
('--keep-weekly', '2'),

View file

@ -1,6 +1,7 @@
[location]
# Space-separated list of source directories to backup.
source_directories: /home /etc
# Globs are expanded.
source_directories: /home /etc /var/log/syslog*
# For Borg only, you can specify to stay in same file system (do not cross
# mount points).