make the instance restore process better understandable

Signed-off-by: szaimen <szaimen@e.mail.de>
This commit is contained in:
szaimen 2022-04-24 12:57:23 +02:00
parent 6037b4402b
commit d288bdd023
7 changed files with 80 additions and 57 deletions

View file

@ -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."

View file

@ -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

View file

@ -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(),

View file

@ -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;

View file

@ -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'])) {

View file

@ -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. <br><br>
If you have a dynamic IP-address, you can use e.g. <a href="https://ddclient.net/">DDclient</a> with a compatible domain provider for DNS updates. <br /><br/>
<h2>Restore AIO instance from backup</h2>
You can alternatively restore an AIO instance from backup.<br><br>
<h2>Restore former AIO instance from backup</h2>
You can alternatively restore a former AIO instance from backup.<br><br>
{% endif %}
{% if borg_backup_host_location != '' and borg_restore_password != '' %}
{% if borg_backup_mode in ['test', 'check'] %}
{% if backup_exit_code > 0 %}
<span class="status error"></span> Last {{ borg_backup_mode }} failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
{% 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!<br><br>
{% 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 <a href="https://borgbackup.readthedocs.io/en/stable/faq.html?highlight=repair#:~:text=repairing%20a%20damaged%20repository"><b>this documentation</b></a>
{% endif %}
{% elseif backup_exit_code == 0 %}
<span class="status success"></span> Last {{ borg_backup_mode }} successful! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
{% 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.<br><br>
<form method="POST" action="/api/docker/backup-check" class="xhr">
{% 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 %}
<span class="status error"></span> Last {{ borg_backup_mode }} failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
{% if borg_backup_mode == 'test' %}
Please adjust the path and/or the password in order to make it work!<br><br>
{% 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 <a href="https://borgbackup.readthedocs.io/en/stable/faq.html?highlight=repair#:~:text=repairing%20a%20damaged%20repository"><b>this documentation</b></a>
{% endif %}
{% elseif backup_exit_code == 0 %}
<span class="status success"></span> Last {{ borg_backup_mode }} successful! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
{% 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.<br><br>
<form method="POST" action="/api/docker/backup-check" class="xhr">
<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="Check backup integrity"/><br/>
</form>
{% 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!<br><br>
<form method="POST" action="/api/docker/restore" class="xhr" id="restore_selection">
<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="Check backup integrity"/><br/>
<select id="selected_restore_time" name="selected_restore_time" form="restore_selection">
{% for restore_time in backup_times %}
<option value="{{ restore_time }}">{{ restore_time }} UTC</option>
{% endfor %}
</select>
<input class="button" type="submit" value="Restore selected backup"/>
</form>
{% 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!<br><br>
<form method="POST" action="/api/docker/restore" class="xhr" id="restore_selection">
<input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
<input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
<select id="selected_restore_time" name="selected_restore_time" form="restore_selection">
{% for restore_time in backup_times %}
<option value="{{ restore_time }}">{{ restore_time }} UTC</option>
{% endfor %}
</select>
<input class="button" type="submit" value="Restore selected backup"/>
</form>
{% endif %}
{% elseif borg_backup_mode == 'restore' %}
{% if backup_exit_code > 0 %}
<span class="status error"></span> Last restore failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
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 %}
<span class="status error"></span> Last restore failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup">Logs</a>)<br /><br />
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:<br><br>
<form method="POST" action="/api/configuration" class="xhr">
<input type="text" name="borg_restore_host_location" value="{{borg_backup_host_location}}" placeholder="/mnt/backup"/>
<input type="text" name="borg_restore_password" value="{{borg_restore_password}}" placeholder="enter the borg password"/>
<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" />
</form>
The folder path that you enter may start with <b>/mnt/</b>, <b>/media/</b> or <b>/host_mnt/</b> or may be equal to <b>/var/backups</b>.<br><br>So e.g. <b>/mnt/backup</b> on Linux and macOS or <b>/host_mnt/c/backup/directory</b> 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.)<br><br>
⚠ 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!<br><br>
{% endif %}
{% if borg_backup_host_location != '' and borg_restore_password != '' %}
{% if borg_backup_mode not in ['test', 'check'] or backup_exit_code != 0 %}
<b>Everything set!</b> Click on the button below to test the path and password:<br/><br/>
<form method="POST" action="/api/docker/backup-test" class="xhr">
{% 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:<br><br>
<form method="POST" action="/api/configuration" class="xhr">
<input type="text" name="borg_restore_host_location" value="{{borg_backup_host_location}}" placeholder="/mnt/backup"/>
<input type="text" name="borg_restore_password" value="{{borg_restore_password}}" placeholder="enter the borg password"/>
<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="Test path and password"/><br/>
<input class="button" type="submit" value="Submit" />
</form>
The folder path that you enter may start with <b>/mnt/</b>, <b>/media/</b> or <b>/host_mnt/</b> or may be equal to <b>/var/backups</b>.<br><br>So e.g. <b>/mnt/backup</b> on Linux and macOS or <b>/host_mnt/c/backup/directory</b> 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.)<br><br>
⚠ 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!<br><br>
{% endif %}
{% else %}
<b>Everything set!</b> Click on the button below to test the path and password:<br/><br/>
<form method="POST" action="/api/docker/backup-test" class="xhr">
<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="Test path and password"/><br/>
</form>
{% endif %}
{% endif %}
{% endif %}

View file

@ -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