backup.py

changeset 2
e343594c0014
parent 1
4cdc9c1f6b28
child 3
4cad934aa9ce
--- a/backup.py	Thu Jan 18 23:01:16 2018 +0000
+++ b/backup.py	Fri Jan 19 10:41:01 2018 +0000
@@ -2,12 +2,58 @@
 # Borgend Backup instance
 #
 
+import config
+from instance import BorgInstance
+
 class Backup:
 
-    def __init__(self, identifier, config):
+    def __decode_config(self, cfg):
+        loc0='backup target %d' % self.identifier
+
+        self.name=config.check_string(cfg, 'name', 'Name', loc0)
+
+        self.loc='backup target "%s"' % self.name
+
+        self.repository=config.check_string(cfg, 'repository',
+                                            'Target repository', self.loc)
+
+        self.archive_template=config.check_string(cfg, 'archive_template',
+                                                  'Archive template', self.loc)
+
+        self.backup_interval=config.check_nonneg_int(cfg, 'backup_interval',
+                                                     'Backup interval', self.loc,
+                                                     config.defaults['backup_interval'])
+
+        self.retry_interval=config.check_nonneg_int(cfg, 'retry_interval',
+                                                    'Retry interval', self.loc,
+                                                    config.defaults['retry_interval'])
+
+        self.paths=config.check_nonempty_list_of_strings(cfg, 'paths', 'Paths', self.loc)
+
+        self.borg_parameters=config.check_list_of_dicts(cfg, 'borg_parameters',
+                                                        'Borg parameters', self.loc,
+                                                        default=[])
+
+
+    def __init__(self, identifier, cfg):
+        self.identifier=identifier
+
+        self.__decode_config(cfg)
+
+
         self.config=config
-        self.identifier=identifier
         self.lastrun=None
+        self.current_instance=None
+
+    def create(self):
+        if self.current_instance is not None:
+            raise AssertionError('%s running: cannot launch' % self.loc)
+
+        archive="%s::%s" % (self.repository, self.archive_template)
+
+        inst=BorgInstance(self.identifier, 'create', self.borg_parameters, 
+                          archive, self.paths)
+        print(inst.construct_cmdline())
 
 
 

mercurial