From 40b2e014fb8d5031cf42cc23e7fcf6c646bcf7d3 Mon Sep 17 00:00:00 2001 From: szaimen Date: Thu, 25 Aug 2022 19:03:29 +0200 Subject: [PATCH] Fix additional backup dirs Signed-off-by: szaimen --- Containers/borgbackup/backupscript.sh | 2 +- php/src/Data/ConfigurationManager.php | 2 +- php/src/Docker/DockerActionManager.php | 5 ++--- php/templates/containers.twig | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index 26c9b42c..26a9ddd9 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -184,7 +184,7 @@ if [ "$BORG_MODE" = backup ]; then do EXCLUDE_DIRS+=(--exclude "/host_mounts/$directory/") done - if ! borg create "${BORG_OPTS[@]}" "${EXCLUDED_DIRECTORIES[@]}" "$BORG_BACKUP_DIRECTORY::$CURRENT_DATE-additional-host-mounts" "/host_mounts/"; then + if ! borg create "${BORG_OPTS[@]}" "${EXCLUDE_DIRS[@]}" "$BORG_BACKUP_DIRECTORY::$CURRENT_DATE-additional-host-mounts" "/host_mounts/"; then echo "Deleting the failed backup archive..." borg delete --stats --progress "$BORG_BACKUP_DIRECTORY::$CURRENT_DATE-additional-host-mounts" echo "Backup of additional host-mounts failed!" diff --git a/php/src/Data/ConfigurationManager.php b/php/src/Data/ConfigurationManager.php index 826fa3ea..2ebcf53e 100644 --- a/php/src/Data/ConfigurationManager.php +++ b/php/src/Data/ConfigurationManager.php @@ -594,7 +594,7 @@ class ConfigurationManager // Trim all unwanted chars on both sites $entry = trim($entry); if ($entry !== "") { - if (!preg_match("#^/[0-1a-zA-Z/-_]$#", $entry) && !preg_match("#^[0-1a-zA-Z_-]$#", $entry)) { + if (!preg_match("#^/[0-1a-zA-Z/-_]+$#", $entry) && !preg_match("#^[0-1a-zA-Z_-]+$#", $entry)) { throw new InvalidSettingConfigurationException("You entered unallowed characters! Problematic is " . $entry); } $validDirectories .= rtrim($entry, '/') . PHP_EOL; diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 85c9cd21..43f84deb 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -368,11 +368,10 @@ class DockerActionManager foreach ($this->configurationManager->GetAdditionalBackupDirectoriesArray() as $additionalBackupDirectories) { if ($additionalBackupDirectories !== '') { if (!str_starts_with($additionalBackupDirectories, '/')) { - $target = '/docker_volumes/'; + $mounts[] = ["Type" => "volume", "Source" => $additionalBackupDirectories, "Target" => "/docker_volumes/" . $additionalBackupDirectories, "ReadOnly" => true]; } else { - $target = '/host_mounts'; + $mounts[] = ["Type" => "bind", "Source" => $additionalBackupDirectories, "Target" => "/host_mounts" . $additionalBackupDirectories, "ReadOnly" => true, "BindOptions" => ["NonRecursive" => true]]; } - $mounts[] = ["Type" => "bind", "Source" => $additionalBackupDirectories, "Target" => $target . $additionalBackupDirectories, "ReadOnly" => true, "BindOptions" => ["NonRecursive" => true]]; } } if(count($mounts) > 0) { diff --git a/php/templates/containers.twig b/php/templates/containers.twig index e9575372..cde78a36 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -407,7 +407,7 @@ {% endif %} -

Back up additional directories and volumes of your host

+

Back up additional directories and docker volumes of your host

Below, you can enter directories and docker volumes of your host that will backed up additionally into the same borg backup archive.

@@ -415,7 +415,7 @@
- Each line and entry needs to start with a slash or letter/digit. Allowed are only a-z, A-Z, 0-9, _, -, and /. If the entry begins with a letter/digit are slashes not supported. Two valid entries are /directory/on/the/host and my_custom_docker_volume

+ Each line and entry needs to start with a slash or letter/digit. Allowed are only a-z, A-Z, 0-9, _, -, and /. If the entry begins with a letter/digit are slashes not supported. Two valid entries are /directory/on/the/host and my_custom_docker_volume. You need to make sure yourself that all given directories exist. Otherwise the backup container will fail starting!

Make sure to specify all storages that you want to back up separately since storages will not be mounted recursively. E.g. providing / as additional backup directory will only back up files and folders that are stored on the root partition and not on the EFI partition or any other. Excluded by the backup will be caches and a few other directories. You should make sure to stop all services before the backup can run correctly if you want to back up the root partition. For automating this see this documentation

Please note that the chosen directories/volumes will not be restored when you restore your instance, so this would need to be done manually.

{% if additional_backup_directories != "" %}