allow to repair the integrity of the backup archive

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2023-01-04 15:38:59 +01:00
parent 480b3193d4
commit 6b91fb7ca2
5 changed files with 55 additions and 3 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -111,7 +111,16 @@
{% 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#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a>
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#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a><br><br>
<details>
<summary>Reveal repair option</summary><br />
Below is the option to repair the integrity of your backup. <b>Please note:</b> Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)<br><br>
<form method="POST" action="/api/docker/backup-check-repair" 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 and repair backup integrity"/><br/>
</form>
</details><br /><br />
{% 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 />
@ -329,7 +338,16 @@
{% 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 == "check" %}
The backup archive seems to be corrupt. You can try to fix it by following <a href="https://borgbackup.readthedocs.io/en/stable/faq.html#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a><br /><br />
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 <a href="https://borgbackup.readthedocs.io/en/stable/faq.html#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a><br /><br />
<details>
<summary>Reveal repair option</summary><br />
Below is the option to repair the integrity of your backup. <b>Please note:</b> Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)<br><br>
<form method="POST" action="/api/docker/backup-check-repair" 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 and repair backup integrity"/><br/>
</form>
</details><br /><br />
{% 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.<br /><br />