From d288bdd023ee03d340927f08455a828c1afab9d3 Mon Sep 17 00:00:00 2001 From: szaimen Date: Sun, 24 Apr 2022 12:57:23 +0200 Subject: [PATCH] make the instance restore process better understandable Signed-off-by: szaimen --- Containers/borgbackup/backupscript.sh | 6 +- Containers/borgbackup/start.sh | 9 ++- php/public/index.php | 1 + php/src/Controller/DockerController.php | 1 + php/src/Data/ConfigurationManager.php | 13 +++ php/templates/containers.twig | 101 ++++++++++++------------ tests/QA/010-restore-instance.md | 6 +- 7 files changed, 80 insertions(+), 57 deletions(-) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index 491fb6a8..4a73b632 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -256,11 +256,15 @@ fi if [ "$BORG_MODE" = test ]; then if ! [ -d "$BORG_BACKUP_DIRECTORY" ]; then echo "No 'borg' directory in the given backup directory found!" + echo "Only the files/folders below have been found in the given directory." + ls -a "$MOUNT_DIR" echo "Please adjust the directory so that the borg archive is positioned in a folder named 'borg' inside the given directory!" exit 1 elif ! [ -f "$BORG_BACKUP_DIRECTORY/config" ]; then echo "A 'borg' directory was found but could not find the borg archive." - echo "It must be positioned directly in the 'borg' subfolder." + echo "Only the files/folders below have been found in the borg directory." + ls -a "$BORG_BACKUP_DIRECTORY" + echo "The archive and most importantly the config file must be positioned directly in the 'borg' subfolder." exit 1 elif ! borg list "$BORG_BACKUP_DIRECTORY"; then echo "The entered path seems to be valid but could not open the backup archive." diff --git a/Containers/borgbackup/start.sh b/Containers/borgbackup/start.sh index b189a101..00e06ed4 100644 --- a/Containers/borgbackup/start.sh +++ b/Containers/borgbackup/start.sh @@ -1,7 +1,8 @@ #!/bin/bash # Variables -export BORG_BACKUP_DIRECTORY="/mnt/borgbackup/borg" +export MOUNT_DIR="/mnt/borgbackup" +export BORG_BACKUP_DIRECTORY="$MOUNT_DIR/borg" # Validate BORG_PASSWORD if [ -z "$BORG_PASSWORD" ] && [ -z "$BACKUP_RESTORE_PASSWORD" ]; then @@ -35,7 +36,11 @@ fi rm -f "/nextcloud_aio_volumes/nextcloud_aio_database_dump/backup-is-running" # Get a list of all available borg archives -borg list "$BORG_BACKUP_DIRECTORY" | grep "nextcloud-aio" | awk -F " " '{print $1","$3,$4}' > "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" +if borg list "$BORG_BACKUP_DIRECTORY" &>/dev/null; then + borg list "$BORG_BACKUP_DIRECTORY" | grep "nextcloud-aio" | awk -F " " '{print $1","$3,$4}' > "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" +else + echo "" > "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" +fi chmod +r "/nextcloud_aio_volumes/nextcloud_aio_mastercontainer/data/backup_archives.list" if [ -n "$FAILED" ]; then diff --git a/php/public/index.php b/php/public/index.php index eddd71ca..eeea480d 100644 --- a/php/public/index.php +++ b/php/public/index.php @@ -81,6 +81,7 @@ $app->get('/containers', function ($request, $response, $args) use ($container) 'has_backup_run_once' => $configurationManager->hasBackupRunOnce(), 'is_backup_container_running' => $dockerActionManger->isBackupContainerRunning(), 'backup_exit_code' => $dockerActionManger->GetBackupcontainerExitCode(), + 'is_instance_restore_attempt' => $configurationManager->isInstanceRestoreAttempt(), 'borg_backup_mode' => $configurationManager->GetBorgBackupMode(), 'was_start_button_clicked' => $configurationManager->wasStartButtonClicked(), 'has_update_available' => $dockerActionManger->isAnyUpdateAvailable(), diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 5257be19..8edb88ea 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -115,6 +115,7 @@ class DockerController public function StartBackupContainerTest(Request $request, Response $response, $args) : Response { $config = $this->configurationManager->GetConfig(); $config['backup-mode'] = 'test'; + $config['instance_restore_attempt'] = 0; $this->configurationManager->WriteConfig($config); $id = self::TOP_CONTAINER; diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index afe30b5a..13d9e0a5 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -334,6 +334,7 @@ class ConfigurationManager $config = $this->GetConfig(); $config['borg_backup_host_location'] = $location; $config['borg_restore_password'] = $password; + $config['instance_restore_attempt'] = 1; $this->WriteConfig($config); } @@ -422,6 +423,18 @@ class ConfigurationManager return $config['borg_restore_password']; } + public function isInstanceRestoreAttempt() : bool { + $config = $this->GetConfig(); + if(!isset($config['instance_restore_attempt'])) { + $config['instance_restore_attempt'] = ''; + } + + if ($config['instance_restore_attempt'] === 1) { + return true; + } + return false; + } + public function GetBorgBackupMode() : string { $config = $this->GetConfig(); if(!isset($config['backup-mode'])) { diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 28542f98..f5c1bf58 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -88,70 +88,69 @@ Make sure that this server is reachable on Port 443 and you've correctly set up the DNS config for the domain that you enter.

If you have a dynamic IP-address, you can use e.g. DDclient with a compatible domain provider for DNS updates.

-

Restore AIO instance from backup

- You can alternatively restore an AIO instance from backup.

+

Restore former AIO instance from backup

+ You can alternatively restore a former AIO instance from backup.

{% endif %} - {% if borg_backup_host_location != '' and borg_restore_password != '' %} - {% if borg_backup_mode in ['test', 'check'] %} - {% if backup_exit_code > 0 %} - Last {{ borg_backup_mode }} failed! (Logs)

- {% if borg_backup_mode == 'test' %} - Please adjust the path and/or password in order to make it work! After changing and submitting the values, click on 'Test path and password' button at the bottom of this page to verify and test the new settings!

- {% 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 - {% endif %} - {% elseif backup_exit_code == 0 %} - Last {{ borg_backup_mode }} successful! (Logs)

- {% if borg_backup_mode == 'test' %} - Feel free to check the integrity of the backup archive below before starting the restore process in order to make double-sure that the restore will work. This can take a long time though depending on the size of the backup archive and is thus not required.

-
+ {% if is_instance_restore_attempt == false %} + {% if borg_backup_host_location != '' and borg_restore_password != '' %} + {% if borg_backup_mode in ['test', 'check'] %} + {% if backup_exit_code > 0 %} + Last {{ borg_backup_mode }} failed! (Logs)

+ {% 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 + {% endif %} + {% elseif backup_exit_code == 0 %} + Last {{ borg_backup_mode }} successful! (Logs)

+ {% if borg_backup_mode == 'test' %} + Feel free to check the integrity of the backup archive below before starting the restore process in order to make double-sure that the restore will work. This can take a long time though depending on the size of the backup archive and is thus not required.

+ + + +
+
+ {% endif %} + Choose the backup that you want to restore and click on the button below to restore the selected backup. This will restore the whole AIO instance from backup. Please not that the current AIO password will be kept and the AIO password not restored from backup!

+
-
+ +
{% endif %} - Choose the backup that you want to restore and click on the button below to restore the selected backup. This will restore the whole AIO instance from backup. Please not that the current AIO password will be kept and the AIO password not restored from backup!

-
- - - - -
- {% endif %} - {% elseif borg_backup_mode == 'restore' %} - {% if backup_exit_code > 0 %} - Last restore failed! (Logs)

- Somehow the restore failed which is unexpected! Please adjust the path and password, test it and try to restore again! + {% elseif borg_backup_mode == 'restore' %} + {% if backup_exit_code > 0 %} + Last restore failed! (Logs)

+ Somehow the restore failed which is unexpected! Please adjust the path and password, test it and try to restore again! + {% endif %} {% endif %} {% endif %} - {% endif %} - {% if borg_backup_host_location == '' or borg_restore_password == '' or borg_backup_mode not in ['test', 'check', ''] or backup_exit_code > 0 %} - Please enter the location of the backup archive on your host and the password of the backup archive below:

-
- - - - - -
- The folder path that you enter may start with /mnt/, /media/ or /host_mnt/ or may be equal to /var/backups.

So e.g. /mnt/backup on Linux and macOS or /host_mnt/c/backup/directory on Windows. (This Windows example would be equivalent to 'C:\backup\directory' on the Windows host. So you need to translate the path that you want to use into the correct format.)

- ⚠ Note that the backup archive must be located in a subfolder of the folder that you enter here and the subfolder which contains the archive must be named 'borg'. Otherwise will the backup container not find the backup archive!

- {% endif %} - {% if borg_backup_host_location != '' and borg_restore_password != '' %} - {% if borg_backup_mode not in ['test', 'check'] or backup_exit_code != 0 %} - Everything set! Click on the button below to test the path and password:

-
+ {% if borg_backup_host_location == '' or borg_restore_password == '' or borg_backup_mode not in ['test', 'check', ''] or backup_exit_code > 0 %} + Please enter the location of the backup archive on your host and the password of the backup archive below:

+ + + -
+
+ The folder path that you enter may start with /mnt/, /media/ or /host_mnt/ or may be equal to /var/backups.

So e.g. /mnt/backup on Linux and macOS or /host_mnt/c/backup/directory on Windows. (This Windows example would be equivalent to 'C:\backup\directory' on the Windows host. So you need to translate the path that you want to use into the correct format.)

+ ⚠ Note that the backup archive must be located in a subfolder of the folder that you enter here and the subfolder which contains the archive must be named 'borg'. Otherwise will the backup container not find the backup archive!

{% endif %} + {% else %} + Everything set! Click on the button below to test the path and password:

+
+ + +
+
{% endif %} {% endif %} {% endif %} diff --git a/tests/QA/010-restore-instance.md b/tests/QA/010-restore-instance.md index b39e7aba..ff98793a 100644 --- a/tests/QA/010-restore-instance.md +++ b/tests/QA/010-restore-instance.md @@ -4,9 +4,9 @@ For the below to work, you need a backup archive of an AIO instance and the loca - [ ] The section that allows to restore the whole AIO instance from backup should show two input fields: one that allows to enter a location where the backup archive is located and one that allows to enter password of the archive. It should also show a short explanation regarding the path requirements - [ ] Entering an incorrect path and/or password should let you continue and test your settings in the next step - - [ ] Clicking on the test button should after a reload bring you back to the initial screen where it should say that the test was unsuccessful. - - [ ] You should now see the input box again where you can change the path and password, confirm it and test the changes with a button on the bottom of the screen. -- [ ] Entering the correct path to the backup archive and the correct password here (in the first try) should: + - [ ] Clicking on the test button should after a reload bring you back to the initial screen where it should say that the test was unsuccessful. Also you should be able to have a look at the backup container logs for investigation what exactly failed. + - [ ] You should also now see the input boxes again where you can change the path and password, confirm it and bring you again to the screen where you can test your settings. +- [ ] Entering the correct path to the backup archive and the correct password here should: - [ ] Should reload and should hide all options except the option to test the path and password - [ ] After the test you should see the options to check the integrity of the backup and a list of backup archives that you can choose from to restore your instance - [ ] Clicking on either option should show a window prompt that lets you cancel the operation