From 258f6683dedd81dcbc447dac7ea7cecd5b4e88db Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 9 Oct 2023 17:18:40 +0200 Subject: [PATCH] daily backup - allow to disable succesful backup notifications Signed-off-by: Simon L --- Containers/mastercontainer/cron.sh | 5 +++++ Containers/mastercontainer/daily-backup.sh | 2 +- php/src/Controller/ConfigurationController.php | 7 ++++++- php/src/Cron/BackupNotification.php | 6 +++++- php/src/Data/ConfigurationManager.php | 5 ++++- php/templates/containers.twig | 1 + 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Containers/mastercontainer/cron.sh b/Containers/mastercontainer/cron.sh index 60fd4f2c0bc..fc8c4081922 100644 --- a/Containers/mastercontainer/cron.sh +++ b/Containers/mastercontainer/cron.sh @@ -12,6 +12,11 @@ while true; do export AUTOMATIC_UPDATES=0 export START_CONTAINERS=1 fi + if [ "$(sed -n '3p' "/mnt/docker-aio-config/data/daily_backup_time")" != 'successNotificationsAreNotEnabled' ]; then + export SEND_SUCCESS_NOTIFICATIONS=1 + else + export SEND_SUCCESS_NOTIFICATIONS=0 + fi set +x if [ -f "/mnt/docker-aio-config/data/daily_backup_running" ]; then export LOCK_FILE_PRESENT=1 diff --git a/Containers/mastercontainer/daily-backup.sh b/Containers/mastercontainer/daily-backup.sh index f87b3966215..62911b9c628 100644 --- a/Containers/mastercontainer/daily-backup.sh +++ b/Containers/mastercontainer/daily-backup.sh @@ -105,7 +105,7 @@ if [ "$DAILY_BACKUP" = 1 ] && ([ "$AUTOMATIC_UPDATES" = 1 ] || [ "$START_CONTAIN done fi echo "Sending backup notification..." - sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php + sudo -E -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php fi echo "Daily backup script has finished" diff --git a/php/src/Controller/ConfigurationController.php b/php/src/Controller/ConfigurationController.php index b7271398fa0..e786697ae88 100644 --- a/php/src/Controller/ConfigurationController.php +++ b/php/src/Controller/ConfigurationController.php @@ -49,8 +49,13 @@ public function SetConfig(Request $request, Response $response, array $args) : R } else { $enableAutomaticUpdates = false; } + if (isset($request->getParsedBody()['success_notification'])) { + $successNotification = true; + } else { + $successNotification = false; + } $dailyBackupTime = $request->getParsedBody()['daily_backup_time'] ?? ''; - $this->configurationManager->SetDailyBackupTime($dailyBackupTime, $enableAutomaticUpdates); + $this->configurationManager->SetDailyBackupTime($dailyBackupTime, $enableAutomaticUpdates, $successNotification); } if (isset($request->getParsedBody()['delete_daily_backup_time'])) { diff --git a/php/src/Cron/BackupNotification.php b/php/src/Cron/BackupNotification.php index a570031b408..17da93b2ab8 100644 --- a/php/src/Cron/BackupNotification.php +++ b/php/src/Cron/BackupNotification.php @@ -21,7 +21,11 @@ $backupExitCode = $dockerActionManger->GetBackupcontainerExitCode(); if ($backupExitCode === 0) { - $dockerActionManger->sendNotification($nextcloudContainer, 'Daily backup successful!', 'You can get further info by looking at the backup logs in the AIO interface.'); + if (getenv('SEND_SUCCESS_NOTIFICATIONS') === "0") { + error_log("Daily backup successful! Only logging successful backup and not sending backup notification since that has been disabled! You can get further info by looking at the backup logs in the AIO interface."); + } else { + $dockerActionManger->sendNotification($nextcloudContainer, 'Daily backup successful!', 'You can get further info by looking at the backup logs in the AIO interface.'); + } } if ($backupExitCode > 0) { diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 5bb295b5f26..7411cafc12e 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -676,7 +676,7 @@ private function GetCollaboraSeccompDisabledState() : string { /** * @throws InvalidSettingConfigurationException */ - public function SetDailyBackupTime(string $time, bool $enableAutomaticUpdates) : void { + public function SetDailyBackupTime(string $time, bool $enableAutomaticUpdates, bool $successNotification) : void { if ($time === "") { throw new InvalidSettingConfigurationException("The daily backup time must not be empty!"); } @@ -688,6 +688,9 @@ public function SetDailyBackupTime(string $time, bool $enableAutomaticUpdates) : if ($enableAutomaticUpdates === false) { $time .= PHP_EOL . 'automaticUpdatesAreNotEnabled'; } + if ($successNotification === false) { + $time .= PHP_EOL . 'successNotificationsAreNotEnabled'; + } file_put_contents(DataConst::GetDailyBackupTimeFile(), $time); } diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 40e2e9eace7..b63953f6e67 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -481,6 +481,7 @@

+
{% else %} Daily backups will be created at {{ daily_backup_time }} UTC which includes a notification about the result of the backup.