Skip to content

Commit

Permalink
Small fixes for ordering and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Feb 6, 2024
1 parent 8fdaabd commit c29bd75
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function startContainer($container) {
global $dockerClient;

if (in_array($container['Name'], self::$skipStartContainers)) {
self::backupLog($container['Name'] . " is being ignored, because it was not started before (or should not be started).");
self::backupLog("Starting " . $container['Name'] . " is being ignored, because it was not started before (or should not be started).");
return;
}

Expand Down Expand Up @@ -581,12 +581,14 @@ public static function updateContainer($name) {
public static function doBackupMethod($method, $containerListOverride = null,) {
global $abSettings, $dockerContainers, $sortedStopContainers, $sortedStartContainers, $abDestination, $dockerUpdateList;

self::backupLog(__METHOD__ . ': $containerListOverride: ' . implode(', ', array_column(($containerListOverride ?? []), 'Name')), self::LOGLEVEL_DEBUG);

switch ($method) {
case 'stopAll':

ABHelper::backupLog("Method: Stop all container before continuing.");
foreach ($containerListOverride ?: $sortedStopContainers as $_container) {
foreach ((self::resolveContainer($_container) ?: [$_container]) as $container) {
foreach ($containerListOverride ? array_reverse($containerListOverride) : $sortedStopContainers as $_container) {
foreach ((self::resolveContainer($_container, true) ?: [$_container]) as $container) {
ABHelper::setCurrentContainerName($container);
ABHelper::stopContainer($container);

Expand All @@ -597,13 +599,15 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
ABHelper::setCurrentContainerName($_container, true);
}

ABHelper::setCurrentContainerName(null);

if (ABHelper::abortRequested()) {
return false;
}

ABHelper::backupLog("Starting backup for containers");
foreach ($containerListOverride ?: $sortedStopContainers as $_container) {
foreach (self::resolveContainer($_container) ?: [$_container] as $container) {
foreach ($containerListOverride ? array_reverse($containerListOverride) : $sortedStopContainers as $_container) {
foreach (self::resolveContainer($_container, true) ?: [$_container] as $container) {
ABHelper::setCurrentContainerName($container);
if (!ABHelper::backupContainer($container, $abDestination)) {
ABHelper::$errorOccured = true;
Expand All @@ -620,6 +624,8 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
ABHelper::setCurrentContainerName($_container, true);
}

ABHelper::setCurrentContainerName(null);

if (ABHelper::abortRequested()) {
return false;
}
Expand All @@ -631,8 +637,8 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
}

ABHelper::backupLog("Set containers to previous state");
foreach ($containerListOverride ? array_reverse($containerListOverride) : $sortedStartContainers as $_container) {
foreach (self::resolveContainer($_container, true) ?: [$_container] as $container) {
foreach ($containerListOverride ?: $sortedStartContainers as $_container) {
foreach (self::resolveContainer($_container) ?: [$_container] as $container) {
ABHelper::setCurrentContainerName($container);
ABHelper::startContainer($container);

Expand All @@ -643,6 +649,8 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
ABHelper::setCurrentContainerName($_container, true);
}

ABHelper::setCurrentContainerName(null);

break;
case 'oneAfterTheOther':
ABHelper::backupLog("Method: Stop/Backup/Start");
Expand Down Expand Up @@ -696,6 +704,12 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
return true;
}

/**
* resolves a container group. Special note goes to the param $reverse: We MUST reverse if the input order is NOT start-order oriented!
* @param $container
* @param $reverse
* @return array|false
*/
public static function resolveContainer($container, $reverse = false) {
global $dockerContainers, $abSettings;
if ($container['isGroup']) {
Expand Down

0 comments on commit c29bd75

Please sign in to comment.