Browse Source

build arguments

Nathaniel van Diepen 4 years ago
parent
commit
40de3edc54
1 changed files with 44 additions and 3 deletions
  1. 44 3
      backup.py

+ 44 - 3
backup.py

@@ -115,12 +115,53 @@ class Job(object):
 
     @property
     def args(self):
-        return Backup.args + []
+        if Backup.engine == "rdiff-backup":
+            args = ['rdiff-backup']
+            for item in self.config['filters']:
+                if 'include' in item:
+                    args += ['--include', item['include']]
+
+                elif 'exclude' in item:
+                    args += ['--exclude', item['exclude']]
+
+                else:
+                    raise BackupException(
+                        '{0} has an invalid filter {1}'.format(self, item))
+
+            return args + [self.fromPath, self.toPath]
+
+        raise StateException('Invalid backup engine {}'.format(Backup.engine))
 
     @property
     def logfile(self):
         return self._backup.logfile
 
+    @property
+    def fromPath(self):
+        if not hasattr(self, '_fromPath'):
+            fromPath = self.config['from']
+            if 'roots' in self._backup.config:
+                roots = self._backup.config['roots']
+                if 'from' in roots:
+                    fromPath = os.path.join(roots['from'], fromPath)
+
+            self._fromPath = fromPath
+
+        return self._fromPath
+
+    @property
+    def toPath(self):
+        if not hasattr(self, '_toPath'):
+            toPath = self.config['to']
+            if 'roots' in self._backup.config:
+                roots = self._backup.config['roots']
+                if 'to' in roots:
+                    toPath = os.path.join(roots['to'], toPath)
+
+            self._toPath = toPath
+
+        return self._toPath
+
     @property
     def process(self):
         return self._process
@@ -139,7 +180,7 @@ class Job(object):
 class Backup(object):
     instances = {}
     _queue = []
-    args = ['rdiff-backup']
+    engine = 'rdiff-backup'
     logdir = '/var/log/backup.d'
     BLOCKED = 0
     READY = 1
@@ -367,7 +408,7 @@ def main(args):
         if engine not in ("rdiff-backup"):
             raise BackupException('Unknown backup engine: {}'.format(engine))
 
-        Backup.args = [engine]
+        Backup.engine = engine
 
     if 'logdir' in config():
         logdir = config()['logdir']