Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daily backup - allow to disable succesful backup notifications #3516

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Containers/mastercontainer/cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Containers/mastercontainer/daily-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 6 additions & 1 deletion php/src/Controller/ConfigurationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down
6 changes: 5 additions & 1 deletion php/src/Cron/BackupNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion php/src/Data/ConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions php/templates/containers.twig
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<input class="button" type="submit" value="Submit backup time" /><br>
<input type="checkbox" id="automatic_updates" name="automatic_updates" checked="checked"><label for="automatic_updates">Automatically update all containers, the mastercontainer and on saturdays your Nextcloud apps</label><br>
<input type="checkbox" id="success_notification" name="success_notification" checked="checked"><label for="success_notification">Send notifications about successful backups (notifications about unsuccessful backups will always be sent)</label><br>
</form>
{% else %}
Daily backups will be created at <b>{{ daily_backup_time }} UTC</b> which includes a notification about the result of the backup.
Expand Down