1 # |
1 # |
2 # Borgend Backup instance |
2 # Borgend Backup instance |
3 # |
3 # |
4 |
4 |
|
5 import config |
|
6 from instance import BorgInstance |
|
7 |
5 class Backup: |
8 class Backup: |
6 |
9 |
7 def __init__(self, identifier, config): |
10 def __decode_config(self, cfg): |
|
11 loc0='backup target %d' % self.identifier |
|
12 |
|
13 self.name=config.check_string(cfg, 'name', 'Name', loc0) |
|
14 |
|
15 self.loc='backup target "%s"' % self.name |
|
16 |
|
17 self.repository=config.check_string(cfg, 'repository', |
|
18 'Target repository', self.loc) |
|
19 |
|
20 self.archive_template=config.check_string(cfg, 'archive_template', |
|
21 'Archive template', self.loc) |
|
22 |
|
23 self.backup_interval=config.check_nonneg_int(cfg, 'backup_interval', |
|
24 'Backup interval', self.loc, |
|
25 config.defaults['backup_interval']) |
|
26 |
|
27 self.retry_interval=config.check_nonneg_int(cfg, 'retry_interval', |
|
28 'Retry interval', self.loc, |
|
29 config.defaults['retry_interval']) |
|
30 |
|
31 self.paths=config.check_nonempty_list_of_strings(cfg, 'paths', 'Paths', self.loc) |
|
32 |
|
33 self.borg_parameters=config.check_list_of_dicts(cfg, 'borg_parameters', |
|
34 'Borg parameters', self.loc, |
|
35 default=[]) |
|
36 |
|
37 |
|
38 def __init__(self, identifier, cfg): |
|
39 self.identifier=identifier |
|
40 |
|
41 self.__decode_config(cfg) |
|
42 |
|
43 |
8 self.config=config |
44 self.config=config |
9 self.identifier=identifier |
|
10 self.lastrun=None |
45 self.lastrun=None |
|
46 self.current_instance=None |
|
47 |
|
48 def create(self): |
|
49 if self.current_instance is not None: |
|
50 raise AssertionError('%s running: cannot launch' % self.loc) |
|
51 |
|
52 archive="%s::%s" % (self.repository, self.archive_template) |
|
53 |
|
54 inst=BorgInstance(self.identifier, 'create', self.borg_parameters, |
|
55 archive, self.paths) |
|
56 print(inst.construct_cmdline()) |
11 |
57 |
12 |
58 |
13 |
59 |