diff options
author | Lars Wirzenius <liw@liw.fi> | 2014-01-20 09:57:44 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2014-01-20 09:57:44 +0000 |
commit | 263aaaa136b96e3892cd0419ff1bb9b18d694e68 (patch) | |
tree | 2705252dae797331f261cd67d54e43a77342c082 | |
parent | 07152b21f072a790b0370c5c5a1745fef6a21070 (diff) | |
download | obnam-263aaaa136b96e3892cd0419ff1bb9b18d694e68.tar.gz |
Add --exclude-from option
Patch-by: Enrico Tröger
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | obnamlib/plugins/backup_plugin.py | 26 | ||||
-rw-r--r-- | test-gpghome/random_seed | bin | 600 -> 600 bytes |
3 files changed, 27 insertions, 3 deletions
@@ -22,6 +22,10 @@ Version 1.7, released UNRELEASED flags in permissions, even if the restore is not being run by `root` or the owner of the files (as recorded in the backup). +* New option `--exclude-from` allows exclusion patterns to be given in + a separate file (one per line), instead of in a configuration file + or on the command line. Patch by Enrico Tröger. + Bug fixes: * Obnam now creates a `trustdb.gpg` in the temporary GNUPGHOME it uses diff --git a/obnamlib/plugins/backup_plugin.py b/obnamlib/plugins/backup_plugin.py index 475f16dd..7fde4341 100644 --- a/obnamlib/plugins/backup_plugin.py +++ b/obnamlib/plugins/backup_plugin.py @@ -181,6 +181,10 @@ class BackupPlugin(obnamlib.ObnamPlugin): 'exclude from backup (can be used multiple ' 'times)', group=backup_group) + self.app.settings.string_list(['exclude-from'], + 'read exclude patterns from FILE', + metavar='FILE', + group=backup_group) self.app.settings.boolean(['exclude-caches'], 'exclude directories (and their subdirs) ' 'that contain a CACHEDIR.TAG file', @@ -389,15 +393,21 @@ class BackupPlugin(obnamlib.ObnamPlugin): self.repo = self.app.get_repository_object(repofs=self.repo.get_fs()) def compile_exclusion_patterns(self): + # read exclude list files from --exclude-from + exclude_patterns = self.read_exclusion_patterns_from_files( + self.app.settings['exclude-from']) + # add patterns passed via --exclude + exclude_patterns.extend(self.app.settings['exclude']) + log = self.app.settings['log'] if log: log = self.app.settings['log'] - self.app.settings['exclude'].append(log) - for pattern in self.app.settings['exclude']: + exclude_patterns.append(log) + for pattern in exclude_patterns: logging.debug('Exclude pattern: %s' % pattern) self.exclude_pats = [] - for x in self.app.settings['exclude']: + for x in exclude_patterns: if x != '': try: self.exclude_pats.append(re.compile(x)) @@ -407,6 +417,16 @@ class BackupPlugin(obnamlib.ObnamPlugin): logging.error(msg) self.progress.error(msg) + def read_exclusion_patterns_from_files(self, filenames): + patterns = [] + for filename in filenames: + with open(filename) as f: + for line in f: + line = line.strip() + if line and not line.startswith('#'): + patterns.append(line) + return patterns + def backup_roots(self, roots): self.progress.what('connecting to to repository') self.fs = self.app.fsf.new(roots[0]) diff --git a/test-gpghome/random_seed b/test-gpghome/random_seed Binary files differindex 57826173..efbc75b6 100644 --- a/test-gpghome/random_seed +++ b/test-gpghome/random_seed |