Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Mar 31, 2023
1 parent f25faa8 commit 4f81949
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

require_once __DIR__ . '/ABSettings.php';

/**
* This is a helper class for some useful things
*/
class ABHelper {

const LOGLEVEL_DEBUG = 'debug';
const LOGLEVEL_INFO = 'info';
const LOGLEVEL_WARN = 'warning';
const LOGLEVEL_ERR = 'error';

/**
* @var array Store some temporary data about containers, which should skipped during start routine
*/
private static $skipStartContainers = [];

public static $targetLogLevel = '';
Expand All @@ -36,6 +42,11 @@ public static function isArrayOnline() {
return false;
}

/**
* Takes care of every hook script execution
* @param $script string
* @return bool
*/
public static function handlePrePostScript($script) {
if (empty($script)) {
self::backupLog("Not executing script: Not set!", self::LOGLEVEL_DEBUG);
Expand Down Expand Up @@ -110,6 +121,11 @@ public static function notify($subject, $description, $message = "", $type = "no
shell_exec($command);
}

/**
* Stops a container
* @param $container array
* @return true|void
*/
public static function stopContainer($container) {
global $dockerClient, $abSettings;

Expand Down Expand Up @@ -140,6 +156,11 @@ public static function stopContainer($container) {
}
}

/**
* Starts a container
* @param $container array
* @return void
*/
public static function startContainer($container) {
global $dockerClient;

Expand Down Expand Up @@ -231,14 +252,20 @@ public static function sortContainers($containers, $order, $reverse = false, $re
}


/**
* The heart func: take care of creating a backup!
* @param $container array
* @param $destination string The generated backup folder for this backup run
* @return bool
*/
public static function backupContainer($container, $destination) {
global $abSettings, $dockerClient;

$containerSettings = $abSettings->getContainerSpecificSettings($container['Name']);

self::backupLog("Backup {$container['Name']} - Container Volumeinfo: " . print_r($container['Volumes'], true), self::LOGLEVEL_DEBUG);

$volumes = self::getContainerVolumes($container);
$volumes = self::getContainerVolumes($container);

if ($containerSettings['backupExtVolumes'] == 'no') {
self::backupLog("Should NOT backup ext volumes, sanitizing...", self::LOGLEVEL_DEBUG);
Expand Down Expand Up @@ -344,6 +371,11 @@ public static function backupContainer($container, $destination) {
return true;
}

/**
* Checks, if backup/restore is running
* @param $externalCmd bool Check external commands (tar or something else) which was started by backup/restore?
* @return array|false|string|string[]|null
*/
public static function scriptRunning($externalCmd = false) {
$pid = @file_get_contents(ABSettings::$tempFolder . '/' . ($externalCmd ? ABSettings::$stateExtCmd : ABSettings::$stateFileScriptRunning));
if (!$pid) {
Expand All @@ -367,6 +399,11 @@ public static function abortRequested() {
return file_exists(ABSettings::$tempFolder . '/' . ABSettings::$stateFileAbort);
}

/**
* Helper, to get all host paths of a container
* @param $container
* @return array
*/
public static function getContainerVolumes($container) {

$volumes = [];
Expand All @@ -377,6 +414,11 @@ public static function getContainerVolumes($container) {
return $volumes;
}

/**
* Is a given volume internal or external mapping?
* @param $volume
* @return bool
*/
public static function isVolumeWithinAppdata($volume) {
global $abSettings;

Expand Down

0 comments on commit 4f81949

Please sign in to comment.