From e26c1908c5ac8c49d324c7084dae7b6f9efe9a36 Mon Sep 17 00:00:00 2001 From: SergeantPanda Date: Wed, 4 Feb 2026 16:56:11 -0600 Subject: [PATCH] Bug Fix: Automatic backups not enabled by default on new installations: Added backups app to `INSTALLED_APPS` and implemented automatic scheduler initialization in `BackupsConfig.ready()`. The backup scheduler now properly syncs the periodic task on startup, ensuring automatic daily backups are enabled and scheduled immediately on fresh database creation without requiring manual user intervention. --- CHANGELOG.md | 1 + apps/backups/apps.py | 30 ++++++++++++++++++++++++++++++ dispatcharr/settings.py | 1 + 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb77e53d..f711d67c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Automatic backups not enabled by default on new installations: Added backups app to `INSTALLED_APPS` and implemented automatic scheduler initialization in `BackupsConfig.ready()`. The backup scheduler now properly syncs the periodic task on startup, ensuring automatic daily backups are enabled and scheduled immediately on fresh database creation without requiring manual user intervention. - Fixed modular Docker Compose deployment and entrypoint/init scripts to properly support `DISPATCHARR_ENV=modular`, use external PostgreSQL/Redis services, and handle port, version, and encoding validation (Closes #324, Fixes #61, #445, #731) - Thanks [@CodeBormen](https://github.com/CodeBormen) - Stream rehash/merge logic now guarantees unique stream_hash and always preserves the stream with the best channel ordering and relationships. This prevents duplicate key errors and ensures the correct stream is retained when merging. (Fixes #892) - Admin URL Conflict with XC Streams: Updated nginx configuration to only redirect exact `/admin` and `/admin/` paths to login in production, preventing interference with stream URLs that use "admin" as a username (e.g., `/admin/password/stream_id` now properly routes to stream handling instead of being redirected). diff --git a/apps/backups/apps.py b/apps/backups/apps.py index ee644149..d4bbb973 100644 --- a/apps/backups/apps.py +++ b/apps/backups/apps.py @@ -1,7 +1,37 @@ +import logging +import sys + from django.apps import AppConfig +logger = logging.getLogger(__name__) + class BackupsConfig(AppConfig): default_auto_field = "django.db.models.BigAutoField" name = "apps.backups" verbose_name = "Backups" + + def ready(self): + """Initialize backup scheduler on app startup.""" + # Only run in the main process (not in workers, beat, or management commands) + if 'runserver' in sys.argv or 'uwsgi' in sys.argv[0] if sys.argv else False: + self._sync_backup_scheduler() + + def _sync_backup_scheduler(self): + """Sync backup scheduler task to database.""" + # Import here to avoid circular imports + from core.models import CoreSettings + from .scheduler import _sync_periodic_task, DEFAULTS + try: + # Ensure settings exist with defaults if this is a new install + CoreSettings.objects.get_or_create( + key="backup_settings", + defaults={"name": "Backup Settings", "value": DEFAULTS.copy()} + ) + + # Always sync the periodic task (handles new installs, updates, or missing tasks) + logger.debug("Syncing backup scheduler") + _sync_periodic_task() + except Exception as e: + # Log but don't fail startup if there's an issue + logger.warning(f"Failed to initialize backup scheduler: {e}") diff --git a/dispatcharr/settings.py b/dispatcharr/settings.py index 7af6e939..cfc499da 100644 --- a/dispatcharr/settings.py +++ b/dispatcharr/settings.py @@ -21,6 +21,7 @@ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") INSTALLED_APPS = [ "apps.api", "apps.accounts", + "apps.backups.apps.BackupsConfig", "apps.channels.apps.ChannelsConfig", "apps.dashboard", "apps.epg",