diff --git a/Containers/mastercontainer/daily-backup.sh b/Containers/mastercontainer/daily-backup.sh index 09eefec1..8f6ecb6a 100644 --- a/Containers/mastercontainer/daily-backup.sh +++ b/Containers/mastercontainer/daily-backup.sh @@ -1,10 +1,16 @@ #!/bin/bash -echo "Daily backup has started" +echo "Daily backup script has started" + +# Daily backup and backup check cannot be run at the same time +if [ "$DAILY_BACKUP" = 1 ] && [ "$CHECK_BACKUP" = 1 ]; then + echo "Daily backup and backup check cannot be run at the same time. Exiting..." + exit 1 +fi # Delete all active sessions and create a lock file # But don't kick out the user if the mastercontainer was just updated since we block the interface either way with the lock file -if [ "$LOCK_FILE_PRESENT" = 0 ]; then +if [ "$LOCK_FILE_PRESENT" = 0 ] || ! [ -f "/mnt/docker-aio-config/data/daily_backup_running" ]; then rm -f "/mnt/docker-aio-config/session/"* fi sudo -u www-data touch "/mnt/docker-aio-config/data/daily_backup_running" @@ -26,6 +32,8 @@ done # Update the mastercontainer if [ "$AUTOMATIC_UPDATES" = 1 ]; then + echo "Starting mastercontainer update..." + echo "(The script might get exited due to that. In order to update all the other containers correctly, you need to run this script with the same settings a second time.)" sudo -u www-data php /var/www/docker-aio/php/src/Cron/UpdateMastercontainer.php fi @@ -40,20 +48,31 @@ else fi # Stop containers if required -if [ "$DAILY_BACKUP" != 1 ] || [ "$STOP_CONTAINERS" = 1 ]; then +# shellcheck disable=SC2235 +if [ "$CHECK_BACKUP" != 1 ] && ([ "$DAILY_BACKUP" != 1 ] || [ "$STOP_CONTAINERS" = 1 ]); then + echo "Stopping containers..." sudo -u www-data php /var/www/docker-aio/php/src/Cron/StopContainers.php fi # Execute the backup itself and some related tasks (also stops the containers) if [ "$DAILY_BACKUP" = 1 ]; then + echo "Creating daily backup..." sudo -u www-data php /var/www/docker-aio/php/src/Cron/CreateBackup.php fi +# Execute backup check +if [ "$CHECK_BACKUP" = 1 ]; then + echo "Starting backup check..." + sudo -u www-data php /var/www/docker-aio/php/src/Cron/CheckBackup.php +fi + # Start and/or update containers if [ "$AUTOMATIC_UPDATES" = 1 ]; then + echo "Starting and updating containers..." sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php else if [ "$START_CONTAINERS" = 1 ]; then + echo "Starting containers without updating them..." sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartContainers.php fi fi @@ -75,7 +94,8 @@ if [ "$DAILY_BACKUP" = 1 ]; then fi done fi + echo "Sending backup notification..." sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php fi -echo "Daily backup has finished" +echo "Daily backup script has finished" diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 74891d5f..c1f44312 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -85,14 +85,17 @@ class DockerController } public function StartBackupContainerCheck(Request $request, Response $response, $args) : Response { + $this->checkBackup(); + return $response->withStatus(201)->withHeader('Location', '/'); + } + + public function checkBackup() : void { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'check'; $this->configurationManager->WriteConfig($config); $id = 'nextcloud-aio-borgbackup'; $this->PerformRecursiveContainerStart($id); - - return $response->withStatus(201)->withHeader('Location', '/'); } public function StartBackupContainerRestore(Request $request, Response $response, $args) : Response { diff --git a/php/src/Cron/CheckBackup.php b/php/src/Cron/CheckBackup.php new file mode 100644 index 00000000..6d9b027c --- /dev/null +++ b/php/src/Cron/CheckBackup.php @@ -0,0 +1,17 @@ +get(\AIO\Controller\DockerController::class); + +// Stop container and start backup check +$dockerController->checkBackup(); diff --git a/readme.md b/readme.md index f4a12ba4..d564caef 100644 --- a/readme.md +++ b/readme.md @@ -381,6 +381,7 @@ You can do so by running the `/daily-backup.sh` script that is stored in the mas - `DAILY_BACKUP` if set to `1`, it will automatically stop the containers and create a backup. If you want to start them again afterwards, you may have a look at the `START_CONTAINERS` option. Please be aware that this option is non-blocking which means that the backup is not done when the process is finished since it only start the borgbackup container with the correct configuration. - `START_CONTAINERS` if set to `1`, it will automatically start the containers without updating them. - `STOP_CONTAINERS` if set to `1`, it will automatically stop the containers. +- `CHECK_BACKUP` if set to `1`, it will start the backup check. This is not allowed to be enabled at the same time like `DAILY_BACKUP`. One example for this would be `sudo docker exec -it -e DAILY_BACKUP=1 nextcloud-aio-mastercontainer /daily-backup.sh`, which you can run via a cronjob or put it in a script.