From 6b91fb7ca2e324f8aa8ae666cacf808935b9882b Mon Sep 17 00:00:00 2001 From: Simon L Date: Wed, 4 Jan 2023 15:38:59 +0100 Subject: [PATCH 1/2] allow to repair the integrity of the backup archive Signed-off-by: Simon L --- Containers/borgbackup/backupscript.sh | 17 +++++++++++++++++ Containers/borgbackup/start.sh | 2 +- php/public/index.php | 1 + php/src/Controller/DockerController.php | 16 ++++++++++++++++ php/templates/containers.twig | 22 ++++++++++++++++++++-- 5 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index 42a32b59..069a9e14 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -364,6 +364,23 @@ if [ "$BORG_MODE" = check ]; then exit 0 fi +# Do the Backup check-repair +if [ "$BORG_MODE" = "check-repair" ]; then + get_start_time + echo "Checking the backup integrity and repairing it..." + + # Perform the check-repair + if ! borg check -v --repair "$BORG_BACKUP_DIRECTORY"; then + echo "Some errors were found while checking and repairing the backup integrity!" + exit 1 + fi + + # Inform user + get_expiration_time + echo "Check finished successfully on $END_DATE_READABLE ($DURATION_READABLE)" + exit 0 +fi + # Do the backup test if [ "$BORG_MODE" = test ]; then if ! [ -d "$BORG_BACKUP_DIRECTORY" ]; then diff --git a/Containers/borgbackup/start.sh b/Containers/borgbackup/start.sh index 00e06ed4..e8d93f58 100644 --- a/Containers/borgbackup/start.sh +++ b/Containers/borgbackup/start.sh @@ -20,7 +20,7 @@ export BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK=yes export BORG_RELOCATED_REPO_ACCESS_IS_OK=yes # Validate BORG_MODE -if [ "$BORG_MODE" != backup ] && [ "$BORG_MODE" != restore ] && [ "$BORG_MODE" != check ] && [ "$BORG_MODE" != test ]; then +if [ "$BORG_MODE" != backup ] && [ "$BORG_MODE" != restore ] && [ "$BORG_MODE" != check ] && [ "$BORG_MODE" != "check-repair" ] && [ "$BORG_MODE" != test ]; then echo "No correct BORG_MODE mode applied. Valid are 'backup', 'check', 'restore' and 'test'." exit 1 fi diff --git a/php/public/index.php b/php/public/index.php index b8f48ce9..be87258d 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -57,6 +57,7 @@ $app->get('/api/docker/getwatchtower', AIO\Controller\DockerController::class . $app->post('/api/docker/start', AIO\Controller\DockerController::class . ':StartContainer'); $app->post('/api/docker/backup', AIO\Controller\DockerController::class . ':StartBackupContainerBackup'); $app->post('/api/docker/backup-check', AIO\Controller\DockerController::class . ':StartBackupContainerCheck'); +$app->post('/api/docker/backup-check-repair', AIO\Controller\DockerController::class . ':StartBackupContainerCheckRepair'); $app->post('/api/docker/backup-test', AIO\Controller\DockerController::class . ':StartBackupContainerTest'); $app->post('/api/docker/restore', AIO\Controller\DockerController::class . ':StartBackupContainerRestore'); $app->post('/api/docker/stop', AIO\Controller\DockerController::class . ':StopContainer'); diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 979edbc8..dd417b27 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -113,6 +113,22 @@ class DockerController return $response->withStatus(201)->withHeader('Location', '/'); } + public function StartBackupContainerCheckRepair(Request $request, Response $response, array $args) : Response { + $config = $this->configurationManager->GetConfig(); + $config['backup-mode'] = 'check-repair'; + $this->configurationManager->WriteConfig($config); + + $id = 'nextcloud-aio-borgbackup'; + $this->PerformRecursiveContainerStart($id); + + // Restore to backup check which is needed to make the UI logic work correctly + $config = $this->configurationManager->GetConfig(); + $config['backup-mode'] = 'check'; + $this->configurationManager->WriteConfig($config); + + return $response->withStatus(201)->withHeader('Location', '/'); + } + public function StartBackupContainerTest(Request $request, Response $response, array $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'test'; diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 90989315..a65ea9f5 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -111,7 +111,16 @@ {% if borg_backup_mode == 'test' %} Please adjust the path and/or the password in order to make it work!

{% elseif borg_backup_mode == 'check' %} - The backup archive seems to be corrupt. Please try to use a different intact backup archive or try to fix it by following this documentation + The backup archive seems to be corrupt. Please try to use a different intact backup archive or try to fix it by following this documentation

+
+ Reveal repair option
+ Below is the option to repair the integrity of your backup. Please note: Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)

+
+ + +
+
+


{% endif %} {% elseif backup_exit_code == 0 %} Last {{ borg_backup_mode }} successful! (Logs)

@@ -329,7 +338,16 @@ {% if backup_exit_code > 0 %} Last {{ borg_backup_mode }} failed! (Logs)

{% if borg_backup_mode == "check" %} - The backup archive seems to be corrupt. You can try to fix it by following this documentation

+ The backup check was not successful which might points towards a corrupt archive (look at the logs). If that should be the case, you can try to fix it by following this documentation

+
+ Reveal repair option
+ Below is the option to repair the integrity of your backup. Please note: Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)

+
+ + +
+
+


{% endif %} {% if has_backup_run_once == false %} You may change the backup path again since the initial backup was not successful. After submitting the new value, you need to click on 'Create Backup' for testing the new value.

From bc7b3c4c548865a33976377a25c11e565a97ee16 Mon Sep 17 00:00:00 2001 From: Simon L Date: Wed, 4 Jan 2023 16:14:59 +0100 Subject: [PATCH 2/2] add onclick warning Signed-off-by: Simon L --- php/templates/containers.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/templates/containers.twig b/php/templates/containers.twig index a65ea9f5..dbc07e12 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -118,7 +118,7 @@
-
+


{% endif %} @@ -345,7 +345,7 @@
-
+


{% endif %}