mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-21 23:16:59 +00:00
allow to run daily backups without automatic updates
Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
parent
8021c8119f
commit
79e53f0d00
17 changed files with 203 additions and 89 deletions
|
|
@ -138,7 +138,7 @@
|
|||
"COLLABORA_HOST=nextcloud-aio-collabora",
|
||||
"TALK_ENABLED=%TALK_ENABLED%",
|
||||
"ONLYOFFICE_HOST=nextcloud-aio-onlyoffice",
|
||||
"DAILY_BACKUP_RUNNING=%DAILY_BACKUP_RUNNING%",
|
||||
"UPDATE_NEXTCLOUD_APPS=%UPDATE_NEXTCLOUD_APPS%",
|
||||
"TZ=%TIMEZONE%",
|
||||
"TALK_PORT=%TALK_PORT%"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -99,7 +99,8 @@ $app->get('/containers', function ($request, $response, $args) use ($container)
|
|||
'timezone' => $configurationManager->GetTimezone(),
|
||||
'skip_domain_validation' => $configurationManager->shouldDomainValidationBeSkipped(),
|
||||
'talk_port' => $configurationManager->GetTalkPort(),
|
||||
'collabora_dictionaries' => $configurationManager->GetCollaboraDictionaries(),
|
||||
'collabora_dictionaries' => $configurationManager->GetCollaboraDictionaries(),
|
||||
'automatic_updates' => $configurationManager->areAutomaticUpdatesEnabled(),
|
||||
]);
|
||||
})->setName('profile');
|
||||
$app->get('/login', function ($request, $response, $args) use ($container) {
|
||||
|
|
|
|||
|
|
@ -44,8 +44,13 @@ class ConfigurationController
|
|||
}
|
||||
|
||||
if (isset($request->getParsedBody()['daily_backup_time'])) {
|
||||
if (isset($request->getParsedBody()['automatic_updates'])) {
|
||||
$enableAutomaticUpdates = true;
|
||||
} else {
|
||||
$enableAutomaticUpdates = false;
|
||||
}
|
||||
$dailyBackupTime = $request->getParsedBody()['daily_backup_time'] ?? '';
|
||||
$this->configurationManager->SetDailyBackupTime($dailyBackupTime);
|
||||
$this->configurationManager->SetDailyBackupTime($dailyBackupTime, $enableAutomaticUpdates);
|
||||
}
|
||||
|
||||
if (isset($request->getParsedBody()['delete_daily_backup_time'])) {
|
||||
|
|
|
|||
|
|
@ -26,22 +26,21 @@ class DockerController
|
|||
$this->configurationManager = $configurationManager;
|
||||
}
|
||||
|
||||
private function PerformRecursiveContainerStart(string $id) : void {
|
||||
private function PerformRecursiveContainerStart(string $id, bool $pullContainer = true) : void {
|
||||
$container = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||
|
||||
foreach($container->GetDependsOn() as $dependency) {
|
||||
$this->PerformRecursiveContainerStart($dependency);
|
||||
}
|
||||
|
||||
$pullcontainer = true;
|
||||
if ($id === 'nextcloud-aio-database') {
|
||||
if ($this->dockerActionManager->GetDatabasecontainerExitCode() > 0) {
|
||||
$pullcontainer = false;
|
||||
$pullContainer = false;
|
||||
}
|
||||
}
|
||||
$this->dockerActionManager->DeleteContainer($container);
|
||||
$this->dockerActionManager->CreateVolumes($container);
|
||||
if ($pullcontainer) {
|
||||
if ($pullContainer) {
|
||||
$this->dockerActionManager->PullContainer($container);
|
||||
} else {
|
||||
error_log('Not pulling the latest database image because the container was not correctly shut down.');
|
||||
|
|
@ -145,12 +144,12 @@ class DockerController
|
|||
$this->configurationManager->WriteConfig($config);
|
||||
|
||||
// Start container
|
||||
$this->startTopContainer();
|
||||
$this->startTopContainer(true);
|
||||
|
||||
return $response->withStatus(201)->withHeader('Location', '/');
|
||||
}
|
||||
|
||||
public function startTopContainer() : void {
|
||||
public function startTopContainer(bool $pullContainer) : void {
|
||||
$config = $this->configurationManager->GetConfig();
|
||||
// set AIO_TOKEN
|
||||
$config['AIO_TOKEN'] = bin2hex(random_bytes(24));
|
||||
|
|
@ -161,7 +160,7 @@ class DockerController
|
|||
|
||||
$id = self::TOP_CONTAINER;
|
||||
|
||||
$this->PerformRecursiveContainerStart($id);
|
||||
$this->PerformRecursiveContainerStart($id, $pullContainer);
|
||||
}
|
||||
|
||||
public function StartWatchtowerContainer(Request $request, Response $response, $args) : Response {
|
||||
|
|
@ -195,6 +194,11 @@ class DockerController
|
|||
return $response->withStatus(201)->withHeader('Location', '/');
|
||||
}
|
||||
|
||||
public function stopTopContainer() : void {
|
||||
$id = self::TOP_CONTAINER;
|
||||
$this->PerformRecursiveContainerStop($id);
|
||||
}
|
||||
|
||||
public function StartDomaincheckContainer() : void
|
||||
{
|
||||
# Don't start if domain is already set
|
||||
|
|
|
|||
|
|
@ -15,6 +15,3 @@ $dockerController = $container->get(\AIO\Controller\DockerController::class);
|
|||
|
||||
// Stop container and start backup
|
||||
$dockerController->startBackup();
|
||||
|
||||
// Start apache
|
||||
$dockerController->startTopContainer();
|
||||
17
php/src/Cron/StartAndUpdateContainers.php
Normal file
17
php/src/Cron/StartAndUpdateContainers.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);
|
||||
|
||||
// Start apache
|
||||
$dockerController->startTopContainer(true);
|
||||
17
php/src/Cron/StartContainers.php
Normal file
17
php/src/Cron/StartContainers.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);
|
||||
|
||||
// Start apache
|
||||
$dockerController->startTopContainer(false);
|
||||
17
php/src/Cron/StopContainers.php
Normal file
17
php/src/Cron/StopContainers.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);
|
||||
|
||||
// Start apache
|
||||
$dockerController->stopTopContainer();
|
||||
|
|
@ -497,7 +497,7 @@ class ConfigurationManager
|
|||
/**
|
||||
* @throws InvalidSettingConfigurationException
|
||||
*/
|
||||
public function SetDailyBackupTime(string $time) : void {
|
||||
public function SetDailyBackupTime(string $time, bool $enableAutomaticUpdates) : void {
|
||||
if ($time === "") {
|
||||
throw new InvalidSettingConfigurationException("The daily backup time must not be empty!");
|
||||
}
|
||||
|
|
@ -506,6 +506,9 @@ class ConfigurationManager
|
|||
throw new InvalidSettingConfigurationException("You did not enter a correct time! One correct example is '04:00'!");
|
||||
}
|
||||
|
||||
if ($enableAutomaticUpdates === false) {
|
||||
$time .= '\nautomaticUpdatesAreNotEnabled';
|
||||
}
|
||||
file_put_contents(DataConst::GetDailyBackupTimeFile(), $time);
|
||||
}
|
||||
|
||||
|
|
@ -513,7 +516,22 @@ class ConfigurationManager
|
|||
if (!file_exists(DataConst::GetDailyBackupTimeFile())) {
|
||||
return '';
|
||||
}
|
||||
return file_get_contents(DataConst::GetDailyBackupTimeFile());
|
||||
$dailyBackupFile = file_get_contents(DataConst::GetDailyBackupTimeFile());
|
||||
$dailyBackupFileArray = explode("\n", $dailyBackupFile);
|
||||
return $dailyBackupFileArray[0];
|
||||
}
|
||||
|
||||
public function areAutomaticUpdatesEnabled() : bool {
|
||||
if (!file_exists(DataConst::GetDailyBackupTimeFile())) {
|
||||
return false;
|
||||
}
|
||||
$dailyBackupFile = file_get_contents(DataConst::GetDailyBackupTimeFile());
|
||||
$dailyBackupFileArray = explode("\n", $dailyBackupFile);
|
||||
if (isset($dailyBackupFileArray[1]) && $dailyBackupFileArray[1] === 'automaticUpdatesAreNotEnabled') {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public function DeleteDailyBackupTime() : void {
|
||||
|
|
|
|||
|
|
@ -280,8 +280,8 @@ class DockerActionManager
|
|||
} else {
|
||||
$replacements[1] = '';
|
||||
}
|
||||
} elseif ($out[1] === 'DAILY_BACKUP_RUNNING') {
|
||||
if ($this->configurationManager->isDailyBackupRunning()) {
|
||||
} elseif ($out[1] === 'UPDATE_NEXTCLOUD_APPS') {
|
||||
if ($this->configurationManager->isDailyBackupRunning() && $this->configurationManager->areAutomaticUpdatesEnabled()) {
|
||||
$replacements[1] = 'yes';
|
||||
} else {
|
||||
$replacements[1] = '';
|
||||
|
|
|
|||
|
|
@ -51,13 +51,15 @@
|
|||
|
||||
{% if is_daily_backup_running == true %}
|
||||
<span class="status running"></span> Daily backup currently running. (<a href="/api/docker/logs?id=nextcloud-aio-mastercontainer">Logs</a>)<br /><br />
|
||||
It will update your containers, the mastercontainer and on saturdays your Nextcloud apps if the backup is successful.<br /><br />
|
||||
{% if is_mastercontainer_update_available == true %}
|
||||
Since the mastercontainer gets updated, it will restart the container which will make it unavailable for a moment. (<a href="/api/docker/logs?id=nextcloud-aio-watchtower">Logs</a>)<br /><br />
|
||||
{% if automatic_updates == true %}
|
||||
It will update your containers, the mastercontainer and on saturdays your Nextcloud apps if the backup is successful.<br /><br />
|
||||
{% if is_mastercontainer_update_available == true %}
|
||||
Since the mastercontainer gets updated, it will restart the container which will make it unavailable for a moment. (<a href="/api/docker/logs?id=nextcloud-aio-watchtower">Logs</a>)<br /><br />
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if has_update_available == false %}
|
||||
The whole process should not take more than a few minutes.<br /><br />
|
||||
{% else %}
|
||||
{% elseif automatic_updates == true %}
|
||||
The whole process can take a while because your containers get updated.<br /><br />
|
||||
{% endif %}
|
||||
<a href="" class="button reload">Reload ↻</a><br/>
|
||||
|
|
@ -380,11 +382,15 @@
|
|||
<input type="text" name="daily_backup_time" value="04:00" placeholder="04:00"/>
|
||||
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
|
||||
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
|
||||
<input class="button" type="submit" value="Submit" />
|
||||
<input class="button" type="submit" value="Submit" /><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>
|
||||
</form>
|
||||
This option will also automatically update your containers, the mastercontainer and on saturdays your Nextcloud apps and will send a notification about the result of the backup.<br><br/>
|
||||
{% else %}
|
||||
Daily backups will be created at <b>{{ daily_backup_time }} UTC</b> which includes a notification about the result of the backup and automatic updates of your containers, the mastercontainer and on saturdays your Nextcloud apps. You can disable this option again by clicking on the button below.<br><br/>
|
||||
Daily backups will be created at <b>{{ daily_backup_time }} UTC</b> which includes a notification about the result of the backup.
|
||||
{% if automatic_updates == true %}
|
||||
Also your containers, the mastercontainer and on saturdays your Nextcloud apps will be automatically updated.
|
||||
{% endif %}
|
||||
You can disable this option again by clicking on the button below.<br><br/>
|
||||
<form method="POST" action="/api/configuration" class="xhr">
|
||||
<input type="hidden" name="delete_daily_backup_time" value="yes"/>
|
||||
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue