backups: Trigger schedules every hour

- This will lead to backups only once a day or so.

- In case of errors, backups are tried every hour.

- Cleanups are also triggered but cleanups happen only after a successful
backup.

Tests performed:

- In development mode, a new backup is taken after 3 minutes of enabling a
repository's schedule.

- Error in one repository does not effect the backup of other repositories.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-01-05 16:31:03 -08:00 committed by James Valleroy
parent 2e3ec5ac15
commit b33362cb7a
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -4,6 +4,7 @@ FreedomBox app to manage backup archives.
"""
import json
import logging
import os
import pathlib
import re
@ -14,10 +15,12 @@ from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth import app as app_module
from plinth import cfg, menu
from plinth import cfg, glib, menu
from . import api
logger = logging.getLogger(__name__)
version = 2
is_essential = True
@ -56,6 +59,11 @@ class BackupsApp(app_module.App):
'backups:index', parent_url_name='system')
self.add(menu_item)
# Check every hour (every 3 minutes in debug mode) to perform scheduled
# backups.
interval = 180 if cfg.develop else 3600
glib.schedule(interval, backup_by_schedule)
def setup(helper, old_version=None):
"""Install and configure the module."""
@ -98,6 +106,17 @@ def _backup_handler(packet, encryption_passphrase=None):
actions.superuser_run('backups', arguments, input=input_data.encode())
def backup_by_schedule(data):
"""Check if backups need to be taken and run the operation."""
from . import repository as repository_module
for repository in repository_module.get_repositories():
try:
repository.schedule.run_schedule()
except Exception as exception:
logger.exception('Error running scheduled backup: %s', exception)
# XXX: Create a notification
def get_exported_archive_apps(path):
"""Get list of apps included in exported archive file."""
arguments = ['get-exported-archive-apps', '--path', path]