Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Feb 26, 2024
2 parents 68d876b + 9a2930c commit 85612a3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
19 changes: 13 additions & 6 deletions src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,8 @@ public static function backupContainer($container, $destination) {

$tarExcludes = [];
if (!empty($containerSettings['exclude'])) {
self::backupLog("Container got excludes! " . PHP_EOL . print_r($containerSettings['exclude'], true), self::LOGLEVEL_DEBUG);
$excludes = explode("\r\n", $containerSettings['exclude']);
if (!empty($excludes)) {
foreach ($excludes as $exclude) {
self::backupLog("Container got excludes! " . implode(", ", $containerSettings['exclude']), self::LOGLEVEL_DEBUG);
foreach ($containerSettings['exclude'] as $exclude) {
$exclude = rtrim($exclude, "/");
if (!empty($exclude)) {
if (($volumeKey = array_search($exclude, $volumes)) !== false) {
Expand All @@ -375,7 +373,6 @@ public static function backupContainer($container, $destination) {
$tarExcludes[] = '--exclude ' . escapeshellarg($exclude);
}
}
}
}

if (!empty($abSettings->globalExclusions)) {
Expand Down Expand Up @@ -502,7 +499,7 @@ public static function abortRequested() {
* @param $container
* @return array
*/
public static function getContainerVolumes($container) {
public static function getContainerVolumes($container, $skipExclusionCheck = false) {
global $abSettings;

$volumes = [];
Expand All @@ -512,6 +509,16 @@ public static function getContainerVolumes($container) {
self::backupLog("This volume is empty (rootfs mapped??)! Ignoring.", self::LOGLEVEL_DEBUG);
continue;
}

if (!$skipExclusionCheck) {
$containerSettings = $abSettings->getContainerSpecificSettings($container['Name']);

if (in_array($hostPath, $containerSettings['exclude'])) {
self::backupLog("Ignoring '$hostPath' because its listed in containers exclusions list!", self::LOGLEVEL_DEBUG);
continue;
}
}

if (!file_exists($hostPath)) {
self::backupLog("'$hostPath' does NOT exist! Please check your mappings! Skipping it for now.", self::LOGLEVEL_ERR);
continue;
Expand Down
21 changes: 19 additions & 2 deletions src/include/ABSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ABSettings {

// The following are hidden, container special default settings
'skip' => 'no',
'exclude' => '',
'exclude' => [],
'dontStop' => 'no',
'backupExtVolumes' => 'no'
];
Expand Down Expand Up @@ -111,6 +111,23 @@ public function __construct() {
case 'settingsVersion':
$this::$settingsVersion = $value;
break;
case 'containerSettings':
/**
* Container specific patches
*/
foreach ($value as $containerName => $containerSettings) {
$paths = explode("\r\n", $containerSettings['exclude']);
$newPaths = [];
foreach ($paths as $pathKey => $path) {
if (empty(trim($path))) {
continue; // Skip empty lines
}
$newPaths[] = rtrim($path, '/');
}
$value[$containerName]['exclude'] = $newPaths;
}
$this->$key = $value;
break;
default:
$this->$key = $value;
break;
Expand Down Expand Up @@ -217,7 +234,7 @@ public function getContainerSpecificSettings($name, $setEmptyToDefault = true) {
* Container is unknown, init its values with empty strings = 'use default'
*/
foreach ($this->defaults as $setting => $value) {
$this->containerSettings[$name][$setting] = '';
$this->containerSettings[$name][$setting] = is_array($value) ? [] : '';
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/pages/content/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@
}

<?php if(isset($selectBorder)): ?>
blockquote select, blockquote textarea {
blockquote select, blockquote textarea, blockquote input[type="text"] {
border-bottom: <?= $selectBorder ?>;
color: <?= $bgcolor ?>;
}

<?php endif; ?>
Expand Down Expand Up @@ -574,19 +575,21 @@ class="fa fa-clock-o title"></i>Notifications and scheduling</span>
}

$image = empty($container['Icon']) ? '/plugins/dynamix.docker.manager/images/question.png' : $container['Icon'];
$volumes = ABHelper::getContainerVolumes($container);
$volumes = ABHelper::getContainerVolumes($container, true);
$containerSetting = $abSettings->getContainerSpecificSettings($container['Name'], false);
$realContainerSetting = print_r($abSettings->getContainerSpecificSettings($container['Name']), true);

if (empty($volumes)) {
$volumes = "<b>No volumes - container will NOT being backed up!</b>";
} else {
foreach ($volumes as $index => $volume) {
$volumes[$index] = '<span class="fa ' . (!ABHelper::isVolumeWithinAppdata($volume) ? 'fa-external-link' : 'fa-folder') . '"></span> <code style="cursor:pointer;" data-container="' . $container['Name'] . '" onclick="addVolumeToExclude(this);">' . $volume . '</code><span style="display: none;" class="multiVolumeWarn"> - <a target="_blank" href="https://forums.unraid.net/topic/137710-plugin-appdatabackup/?do=findComment&comment=1250363">used in multiple containers!</a></span>';
$excluded = in_array($volume, $containerSetting['exclude']) ? ' - <abbr style="color: red; font-weight: bold;" title="Will not being backed up! See exclusions list below!">EXCLUDED!</abbr> ' : '';
$volumes[$index] = '<span class="fa ' . (!ABHelper::isVolumeWithinAppdata($volume) ? 'fa-external-link' : 'fa-folder') . '"></span> <code style="cursor:pointer;" data-container="' . $container['Name'] . '" onclick="addVolumeToExclude(this);">' . $volume . '</code>' . $excluded . '<span style="display: none;" class="multiVolumeWarn"> - <a target="_blank" href="https://forums.unraid.net/topic/137710-plugin-appdatabackup/?do=findComment&comment=1250363">used in multiple containers!</a></span>';
}
$volumes = implode('<br />', $volumes);
}

$containerSetting = $abSettings->getContainerSpecificSettings($container['Name'], false);
$realContainerSetting = print_r($abSettings->getContainerSpecificSettings($container['Name']), true);
$containerExcludes = implode("\r\n", $containerSetting['exclude']);

echo <<<HTML
<div style="display: none" id="actualContainerSettings_{$container['Name']}">$realContainerSetting</div>
Expand Down Expand Up @@ -625,12 +628,12 @@ class="fa fa-clock-o title"></i>Notifications and scheduling</span>
</dd>
<dt>Excluded folders/files<br /><small>One path/pattern per line. See belows "Global exclusions" for more examples.</small></dt>
<dd><div style="display: table; width: 300px;"><textarea id="{$container['Name']}_exclude" name="containerSettings[{$container['Name']}][exclude]" onfocus="$(this).next('.ft').slideDown('fast');" style="resize: vertical; width: 400px;">{$containerSetting['exclude']}</textarea><div class="ft" style="display: none;"><div class="fileTreeDiv"></div><button onclick="addSelectionToList(this); return false;">Add to list</button></div></div></dd>
<dd><div style="display: table; width: 300px;"><textarea id="{$container['Name']}_exclude" name="containerSettings[{$container['Name']}][exclude]" onfocus="$(this).next('.ft').slideDown('fast');" style="resize: vertical; width: 400px;">$containerExcludes</textarea><div class="ft" style="display: none;"><div class="fileTreeDiv"></div><button onclick="addSelectionToList(this); return false;">Add to list</button></div></div></dd>
<div onclick="$(this).next().show();"><a style="cursor:pointer;">Show advanced options</a></div>
<div onclick="$(this).next().toggle();"><a style="cursor:pointer;">Show advanced options</a></div>
<div style="display: none;">
<dt>Skip backup? <small>Only stop/start</small></dt>
Expand Down Expand Up @@ -948,7 +951,8 @@ function addVolumeToExclude(element) {
$path = $(element).text();
$excludeTextarea = $('#' + $(element).data('container') + '_exclude');

if ($excludeTextarea.val().indexOf($path) !== -1) { // If existing inside textarea
if ($excludeTextarea.val().split(/\r?\n|\r|\n/g).includes($path)) { // If existing inside textarea
console.debug("Not adding this volume to exclusion: already listed!")
return;
}

Expand Down Expand Up @@ -1009,17 +1013,18 @@ function checkVolumesForDuplicates() {
$("code[data-container]").each(function () {
let container = $(this).data('container');
let mapping = $(this).text();
if ($('#' + container + '_exclude').val().indexOf(mapping) !== -1) {
console.debug(container, mapping, 'is excluded so ignored');
} else if (volumeMatrix.includes(mapping)) {

if (volumeMatrix.includes(mapping)) {
affectedMappings.push(mapping);
} else {
volumeMatrix.push($(this).text());
}
});

console.debug("Volume dup check (affected/matrix): ", affectedMappings, volumeMatrix);

affectedMappings.forEach(function (element) {
let codeElems = $('code:contains(' + element + ')');
let codeElems = $('code[data-container]:contains(' + element + ')');
codeElems.each(function () {
$('#containerMultiMappingIssue_' + $(this).data('container')).show();
$(this).next('.multiVolumeWarn').show();
Expand Down

0 comments on commit 85612a3

Please sign in to comment.