Skip to content

Commit

Permalink
Scheduler support multiple repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiencyr committed Jun 3, 2021
1 parent 71f089c commit 4388511
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions src/vorta/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from PyQt5 import QtCore
from apscheduler.schedulers.qt import QtScheduler
from apscheduler.triggers import cron

from vorta.borg.check import BorgCheckThread
from vorta.borg.create import BorgCreateThread
from vorta.borg.list_repo import BorgListRepoThread
from vorta.borg.prune import BorgPruneThread
from vorta.i18n import translate

from vorta.models import BackupProfileModel, EventLogModel
from vorta.models import BackupProfileModel, EventLogModel, BackupProfileMixin
from vorta.notifications import VortaNotifications

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -99,31 +99,37 @@ def next_job_for_profile(self, profile_id):
def create_backup(self, profile_id):
notifier = VortaNotifications.pick()
profile = BackupProfileModel.get(id=profile_id)
query = BackupProfileMixin.get_repos(profile_id)

logger.info('Starting background backup for %s', profile.name)
notifier.deliver(self.tr('Vorta Backup'),
self.tr('Starting background backup for %s.') % profile.name,
level='info')

msg = BorgCreateThread.prepare(profile)
if msg['ok']:
logger.info('Preparation for backup successful.')
thread = BorgCreateThread(msg['cmd'], msg)
thread.start()
thread.wait()
if thread.process.returncode in [0, 1]:
notifier.deliver(self.tr('Vorta Backup'),
self.tr('Backup successful for %s.') % profile.name,
level='info')
logger.info('Backup creation successful.')
self.post_backup_tasks(profile_id)
for repo in query:
profile.repo = repo.repo.id
profile.save

msg = BorgCreateThread.prepare(profile)
if msg['ok']:
logger.info('Preparation for backup successful.')
thread = BorgCreateThread(msg['cmd'], msg)
# connect next thread even if current thread fails
thread.start()
thread.wait()
if thread.process.returncode in [0, 1]:
notifier.deliver(self.tr('Vorta Backup'),
self.tr('Backup successful for %s.') % profile.name,
level='info')
logger.info('Backup creation successful.')
self.post_backup_tasks(profile_id)
else:
notifier.deliver(self.tr('Vorta Backup'), self.tr('Error during backup creation.'), level='error')
logger.error('Error during backup creation.')
else:
notifier.deliver(self.tr('Vorta Backup'), self.tr('Error during backup creation.'), level='error')
logger.error('Error during backup creation.')
else:
logger.error('Conditions for backup not met. Aborting.')
logger.error(msg['message'])
notifier.deliver(self.tr('Vorta Backup'), translate('messages', msg['message']), level='error')
logger.error('Conditions for backup not met. Aborting.')
logger.error(msg['message'])
notifier.deliver(self.tr('Vorta Backup'), translate('messages', msg['message']), level='error')

def post_backup_tasks(self, profile_id):
"""
Expand Down

0 comments on commit 4388511

Please sign in to comment.