def prune_action(self): params = BorgPruneThread.prepare(self.profile()) if params['ok']: thread = BorgPruneThread(params['cmd'], params, parent=self.app) thread.updated.connect(self._set_status) thread.result.connect(self.prune_result) self._toggle_all_buttons(False) thread.start()
def test_borg_prune(qapp, qtbot, mocker, borg_json_output): stdout, stderr = borg_json_output('prune') popen_result = mocker.MagicMock(stdout=stdout, stderr=stderr, returncode=0) mocker.patch.object(vorta.borg.borg_thread, 'Popen', return_value=popen_result) params = BorgPruneThread.prepare(vorta.models.BackupProfileModel.select().first()) thread = BorgPruneThread(params['cmd'], params, qapp) with qtbot.waitSignal(thread.result, timeout=10000) as blocker: blocker.connect(thread.updated) thread.run() assert blocker.args[0]['returncode'] == 0
def post_backup_tasks(self, profile_id): """ Pruning and checking after successful backup. """ profile = BackupProfileModel.get(id=profile_id) logger.info('Doing post-backup jobs for %s', profile.name) if profile.prune_on: msg = BorgPruneThread.prepare(profile) if msg['ok']: prune_thread = BorgPruneThread(msg['cmd'], msg) prune_thread.start() prune_thread.wait() # Refresh snapshots msg = BorgListThread.prepare(profile) if msg['ok']: list_thread = BorgListThread(msg['cmd'], msg) list_thread.start() list_thread.wait() validation_cutoff = date.today() - timedelta(days=7 * profile.validation_weeks) recent_validations = EventLogModel.select().where( (EventLogModel.subcommand == 'check') & (EventLogModel.start_time > validation_cutoff) & (EventLogModel.repo_url == profile.repo.url)).count() if profile.validation_on and recent_validations == 0: msg = BorgCheckThread.prepare(profile) if msg['ok']: check_thread = BorgCheckThread(msg['cmd'], msg) check_thread.start() check_thread.wait() logger.info('Finished background task for profile %s', profile.name)