mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-20 06:26:57 +00:00
Merge pull request #1094 from nextcloud/enh/1077/backup-check
rework the daily backup script and allow to start the backup check from it
This commit is contained in:
commit
2ab42b06ed
4 changed files with 47 additions and 6 deletions
|
|
@ -1,10 +1,16 @@
|
||||||
#!/bin/bash
|
#!/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
|
# 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
|
# 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/"*
|
rm -f "/mnt/docker-aio-config/session/"*
|
||||||
fi
|
fi
|
||||||
sudo -u www-data touch "/mnt/docker-aio-config/data/daily_backup_running"
|
sudo -u www-data touch "/mnt/docker-aio-config/data/daily_backup_running"
|
||||||
|
|
@ -26,6 +32,8 @@ done
|
||||||
|
|
||||||
# Update the mastercontainer
|
# Update the mastercontainer
|
||||||
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
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
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/UpdateMastercontainer.php
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -40,20 +48,31 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Stop containers if required
|
# 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
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StopContainers.php
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Execute the backup itself and some related tasks (also stops the containers)
|
# Execute the backup itself and some related tasks (also stops the containers)
|
||||||
if [ "$DAILY_BACKUP" = 1 ]; then
|
if [ "$DAILY_BACKUP" = 1 ]; then
|
||||||
|
echo "Creating daily backup..."
|
||||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/CreateBackup.php
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/CreateBackup.php
|
||||||
fi
|
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
|
# Start and/or update containers
|
||||||
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
||||||
|
echo "Starting and updating containers..."
|
||||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartAndUpdateContainers.php
|
||||||
else
|
else
|
||||||
if [ "$START_CONTAINERS" = 1 ]; then
|
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
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/StartContainers.php
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
@ -75,7 +94,8 @@ if [ "$DAILY_BACKUP" = 1 ]; then
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
echo "Sending backup notification..."
|
||||||
sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Daily backup has finished"
|
echo "Daily backup script has finished"
|
||||||
|
|
|
||||||
|
|
@ -85,14 +85,17 @@ class DockerController
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StartBackupContainerCheck(Request $request, Response $response, $args) : Response {
|
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 = $this->configurationManager->GetConfig();
|
||||||
$config['backup-mode'] = 'check';
|
$config['backup-mode'] = 'check';
|
||||||
$this->configurationManager->WriteConfig($config);
|
$this->configurationManager->WriteConfig($config);
|
||||||
|
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$this->PerformRecursiveContainerStart($id);
|
$this->PerformRecursiveContainerStart($id);
|
||||||
|
|
||||||
return $response->withStatus(201)->withHeader('Location', '/');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function StartBackupContainerRestore(Request $request, Response $response, $args) : Response {
|
public function StartBackupContainerRestore(Request $request, Response $response, $args) : Response {
|
||||||
|
|
|
||||||
17
php/src/Cron/CheckBackup.php
Normal file
17
php/src/Cron/CheckBackup.php
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
// increase memory limit to 2GB
|
||||||
|
ini_set('memory_limit', '2048M');
|
||||||
|
|
||||||
|
use DI\Container;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
$container = \AIO\DependencyInjection::GetContainer();
|
||||||
|
|
||||||
|
/** @var \AIO\Controller\DockerController $dockerController */
|
||||||
|
$dockerController = $container->get(\AIO\Controller\DockerController::class);
|
||||||
|
|
||||||
|
// Stop container and start backup check
|
||||||
|
$dockerController->checkBackup();
|
||||||
|
|
@ -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.
|
- `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.
|
- `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.
|
- `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.
|
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.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue