Added support for file globs in source_directories.

source_directories_glob can be used to enable glob support (defaults to
disabled).
This commit is contained in:
Robin Schneider 2016-01-25 23:52:16 +01:00
parent dd2be365b1
commit e4cf193cd7
4 changed files with 24 additions and 1 deletions

View file

@ -16,6 +16,7 @@ Here's an example config file:
[location] [location]
# Space-separated list of source directories to backup. # Space-separated list of source directories to backup.
source_directories: /home /etc source_directories: /home /etc
# source_directories_glob: 1
# Path to local or remote backup repository. # Path to local or remote backup repository.
repository: user@backupserver:sourcehostname.attic repository: user@backupserver:sourcehostname.attic

View file

@ -3,6 +3,8 @@ import os
import re import re
import platform import platform
import subprocess import subprocess
from glob import glob
from itertools import chain
from atticmatic.config import Section_format, option from atticmatic.config import Section_format, option
from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS from atticmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS
@ -19,6 +21,7 @@ CONFIG_FORMAT = (
'location', 'location',
( (
option('source_directories'), option('source_directories'),
option('source_directories_glob', int, required=False),
option('repository'), option('repository'),
), ),
), ),
@ -58,7 +61,7 @@ def initialize(storage_config, command):
def create_archive( def create_archive(
excludes_filename, verbosity, storage_config, source_directories, repository, command, excludes_filename, verbosity, storage_config, source_directories, repository, command,
one_file_system=None, one_file_system=None, source_directories_glob=None
): ):
''' '''
Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated Given an excludes filename (or None), a vebosity flag, a storage config dict, a space-separated
@ -66,6 +69,8 @@ def create_archive(
attic archive. attic archive.
''' '''
sources = tuple(re.split('\s+', source_directories)) sources = tuple(re.split('\s+', source_directories))
if source_directories_glob:
sources = tuple(chain.from_iterable([glob(x) for x in sources]))
exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else () exclude_flags = ('--exclude-from', excludes_filename) if excludes_filename else ()
compression = storage_config.get('compression', None) compression = storage_config.get('compression', None)
compression_flags = ('--compression', compression) if compression else () compression_flags = ('--compression', compression) if compression else ()

View file

@ -177,6 +177,22 @@ 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',
source_directories_glob=1,
)
BASE_PRUNE_FLAGS = ( BASE_PRUNE_FLAGS = (
('--keep-daily', '1'), ('--keep-daily', '1'),
('--keep-weekly', '2'), ('--keep-weekly', '2'),

View file

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