mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
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:
parent
2e3ec5ac15
commit
b33362cb7a
@ -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]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user