5 import config |
5 import config |
6 import logging |
6 import logging |
7 import time |
7 import time |
8 import keyring |
8 import keyring |
9 import borgend |
9 import borgend |
|
10 import repository |
10 from instance import BorgInstance |
11 from instance import BorgInstance |
11 from threading import Thread, Lock, Condition |
12 from threading import Thread, Lock, Condition |
12 from scheduler import TerminableThread |
13 from scheduler import TerminableThread |
13 |
14 |
14 logger=borgend.logger.getChild(__name__) |
15 logger=borgend.logger.getChild(__name__) |
53 |
54 |
54 self._name=config.check_string(cfg, 'name', 'Name', loc0) |
55 self._name=config.check_string(cfg, 'name', 'Name', loc0) |
55 |
56 |
56 self.loc='backup target "%s"' % self._name |
57 self.loc='backup target "%s"' % self._name |
57 |
58 |
58 self.repository=config.check_string(cfg, 'repository', |
59 reponame=config.check_string(cfg, 'repository', |
59 'Target repository', self.loc) |
60 'Target repository', self.loc) |
|
61 |
|
62 self.repository=repository.get_controller(reponame) |
60 |
63 |
61 self.archive_prefix=config.check_string(cfg, 'archive_prefix', |
64 self.archive_prefix=config.check_string(cfg, 'archive_prefix', |
62 'Archive prefix', self.loc) |
65 'Archive prefix', self.loc) |
63 |
66 |
64 self.archive_template=config.check_string(cfg, 'archive_template', |
67 self.archive_template=config.check_string(cfg, 'archive_template', |
294 else: |
297 else: |
295 try: |
298 try: |
296 logger.debug("Launching '%s' on '%s'" % (op['operation'], self._name)) |
299 logger.debug("Launching '%s' on '%s'" % (op['operation'], self._name)) |
297 |
300 |
298 if op['operation']=='create': |
301 if op['operation']=='create': |
299 archive="%s::%s%s" % (self.repository, |
302 archive="%s::%s%s" % (self.repository.repository_name, |
300 self.archive_prefix, |
303 self.archive_prefix, |
301 self.archive_template) |
304 self.archive_template) |
302 |
305 |
303 self.__do_launch(op, archive, |
306 self.__do_launch(op, archive, |
304 self.common_parameters+self.create_parameters, |
307 self.common_parameters+self.create_parameters, |
305 self.paths) |
308 self.paths) |
306 elif op['operation']=='prune': |
309 elif op['operation']=='prune': |
307 self.__do_launch(op, self.repository, |
310 self.__do_launch(op, self.repository.repository_name, |
308 ([{'prefix': self.archive_prefix}] + |
311 ([{'prefix': self.archive_prefix}] + |
309 self.common_parameters + |
312 self.common_parameters + |
310 self.prune_parameters)) |
313 self.prune_parameters)) |
311 else: |
314 else: |
312 raise NotImplementedError("Invalid operation '%s'" % op['operation']) |
315 raise NotImplementedError("Invalid operation '%s'" % op['operation']) |
386 self.scheduler.wait_until(now+delay, self._cond, self._name) |
389 self.scheduler.wait_until(now+delay, self._cond, self._name) |
387 |
390 |
388 if self.scheduled_operation: |
391 if self.scheduled_operation: |
389 op=self.scheduled_operation |
392 op=self.scheduled_operation |
390 self.scheduled_operation=None |
393 self.scheduled_operation=None |
391 self.__launch(op) |
394 self.repository.queue_action(self._cond, name=self._name, |
392 |
395 action=lambda: self.__launch(op)) |
393 # Kill a running borg to cause log and result threads to terminate |
396 # Kill a running borg to cause log and result threads to terminate |
394 if self.borg_instance: |
397 if self.borg_instance: |
395 logger.debug("Terminating a borg instance") |
398 logger.debug("Terminating a borg instance") |
396 self.borg_instance.terminate() |
399 self.borg_instance.terminate() |
397 |
400 |