From 8113728d3df789c5cad7da0819b822e51caf738a Mon Sep 17 00:00:00 2001 From: Ludy Date: Thu, 4 Sep 2025 16:02:31 +0200 Subject: [PATCH] feat(database): make backup schedule configurable via system keys (#4251) --- DATABASE.md | 2 +- .../software/common/model/ApplicationProperties.java | 6 ++++++ app/core/src/main/resources/settings.yml.template | 2 ++ .../proprietary/security/database/ScheduledTasks.java | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/DATABASE.md b/DATABASE.md index c37c598bb..5c245af27 100644 --- a/DATABASE.md +++ b/DATABASE.md @@ -5,7 +5,7 @@ The newly introduced feature enhances the application with robust database backup and import capabilities. This feature is designed to ensure data integrity and provide a straightforward way to manage database backups. Here's how it works: 1. Automatic Backup Creation - - The system automatically creates a database backup every day at midnight. This ensures that there is always a recent backup available, minimizing the risk of data loss. + - The system automatically creates a database backup on a configurable schedule (default: daily at midnight via `system.databaseBackup.cron`). This ensures that there is always a recent backup available, minimizing the risk of data loss. 2. Manual Backup Export - Admin actions that modify the user database trigger a manual export of the database. This keeps the backup up-to-date with the latest changes and provides an extra layer of data security. 3. Importing Database Backups diff --git a/app/common/src/main/java/stirling/software/common/model/ApplicationProperties.java b/app/common/src/main/java/stirling/software/common/model/ApplicationProperties.java index ece91b269..83548bb59 100644 --- a/app/common/src/main/java/stirling/software/common/model/ApplicationProperties.java +++ b/app/common/src/main/java/stirling/software/common/model/ApplicationProperties.java @@ -329,12 +329,18 @@ public class ApplicationProperties { private CustomPaths customPaths = new CustomPaths(); private String fileUploadLimit; private TempFileManagement tempFileManagement = new TempFileManagement(); + private DatabaseBackup databaseBackup = new DatabaseBackup(); public boolean isAnalyticsEnabled() { return this.getEnableAnalytics() != null && this.getEnableAnalytics(); } } + @Data + public static class DatabaseBackup { + private String cron = "0 0 0 * * ?"; // daily at midnight + } + @Data public static class CustomPaths { private Pipeline pipeline = new Pipeline(); diff --git a/app/core/src/main/resources/settings.yml.template b/app/core/src/main/resources/settings.yml.template index bbbac5fcd..a2b290ae4 100644 --- a/app/core/src/main/resources/settings.yml.template +++ b/app/core/src/main/resources/settings.yml.template @@ -151,6 +151,8 @@ system: cleanupIntervalMinutes: 30 # How often to run cleanup (in minutes) startupCleanup: true # Clean up old temp files on startup cleanupSystemTemp: false # Whether to clean broader system temp directory + databaseBackup: + cron: '0 0 0 * * ?' # Cron expression for automatic database backups "0 0 0 * * ?" daily at midnight ui: appName: '' # application's visible name diff --git a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/ScheduledTasks.java b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/ScheduledTasks.java index 6821414aa..68c34c31a 100644 --- a/app/proprietary/src/main/java/stirling/software/proprietary/security/database/ScheduledTasks.java +++ b/app/proprietary/src/main/java/stirling/software/proprietary/security/database/ScheduledTasks.java @@ -18,7 +18,7 @@ public class ScheduledTasks { private final DatabaseServiceInterface databaseService; - @Scheduled(cron = "0 0 0 * * ?") + @Scheduled(cron = "#{applicationProperties.system.databaseBackup.cron}") public void performBackup() throws SQLException, UnsupportedProviderException { databaseService.exportDatabase(); }