Skip to content

Commit

Permalink
Init exec ref vars
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Mar 31, 2023
1 parent b3cfcff commit a3dfca1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public static function handlePrePostScript($script) {
self::backupLog($script . ' is not executable! Skipping!', self::LOGLEVEL_ERR);
return false;
}

$output = $resultcode = null;
self::backupLog("Executing script $script...");
exec(escapeshellarg($script), $output, $resultcode);
self::backupLog($script . " CODE: " . $resultcode . " - " . print_r($output, true), self::LOGLEVEL_DEBUG);
Expand Down Expand Up @@ -326,6 +328,7 @@ public static function backupContainer($container, $destination) {
self::backupLog("Generated tar command: " . $finalTarOptions, self::LOGLEVEL_DEBUG);
self::backupLog("Backing up " . $container['Name'] . '...');

$output = $resultcode = null;
exec("tar " . $finalTarOptions . " 2>&1 " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
self::backupLog("Tar out: " . implode('; ', $output), self::LOGLEVEL_DEBUG);

Expand All @@ -343,6 +346,8 @@ public static function backupContainer($container, $destination) {
if ($containerSettings['verifyBackup'] == 'yes') {
self::backupLog("Verifying backup...");
self::backupLog("Final verify command: " . $finalTarVerifyOptions, self::LOGLEVEL_DEBUG);

$output = $resultcode = null;
exec("tar " . $finalTarVerifyOptions . " 2>&1 " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
self::backupLog("Tar out: " . implode('; ', $output), self::LOGLEVEL_DEBUG);

Expand All @@ -352,7 +357,7 @@ public static function backupContainer($container, $destination) {
* Special debug: The creation was ok but verification failed: Something is accessing docker files! List docker info for this container
*/
foreach ($volumes as $volume) {
$output = null; // Reset exec lines
$output = null;
exec("lsof -nl +D " . escapeshellarg($volume), $output);
self::backupLog("lsof($volume)" . PHP_EOL . print_r($output, true), self::LOGLEVEL_DEBUG);
}
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
if (!file_exists($script)) {
ABHelper::backupLog("The flash backup script is not available!", ABHelper::LOGLEVEL_ERR);
} else {
$output = null;
exec($script . " " . ABSettings::$externalCmdPidCapture, $output);
ABHelper::backupLog("flash backup returned: " . implode(", ", $output), ABHelper::LOGLEVEL_DEBUG);
if (empty($output[0])) {
Expand Down Expand Up @@ -241,6 +242,7 @@
} else {
ABHelper::backupLog("VM meta backup enabled! Backing up...");

$output = $resultcode = null;
exec("tar -czf " . escapeshellarg($abDestination . '/vm_meta.tgz') . " " . ABSettings::$qemuFolder . '/ ' . ABSettings::$externalCmdPidCapture, $output, $resultcode);
ABHelper::backupLog("tar return: $resultcode and output: " . print_r($output), ABHelper::LOGLEVEL_DEBUG);
if ($resultcode != 0) {
Expand Down Expand Up @@ -326,6 +328,7 @@
ABHelper::backupLog("Generated tar command: " . $finalTarOptions, ABHelper::LOGLEVEL_DEBUG);
ABHelper::backupLog("Backing up extra files...");

$output = $resultcode = null;
exec("tar " . $finalTarOptions . " 2>&1 " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
ABHelper::backupLog("Tar out: " . implode('; ', $output), ABHelper::LOGLEVEL_DEBUG);

Expand Down
3 changes: 3 additions & 0 deletions src/scripts/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
$finalTarCommand = 'tar ' . implode(' ', $tarOptions);
ABHelper::backupLog("Final tar command: " . $finalTarCommand, ABHelper::LOGLEVEL_DEBUG);

$output = $resultcode = null;
exec($finalTarCommand . " 2>&1 " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
ABHelper::backupLog("Tar out: " . implode('; ', $output), ABHelper::LOGLEVEL_DEBUG);
if ($resultcode > 0) {
Expand Down Expand Up @@ -145,6 +146,7 @@
$finalTarCommand = 'tar ' . implode(' ', $tarOptions);
ABHelper::backupLog("Final tar command: " . $finalTarCommand, ABHelper::LOGLEVEL_DEBUG);

$output = $resultcode = null;
exec($finalTarCommand . " 2>&1 " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
ABHelper::backupLog("Tar out: " . implode('; ', $output), ABHelper::LOGLEVEL_DEBUG);
if ($resultcode > 0) {
Expand All @@ -167,6 +169,7 @@
if (!file_exists(ABSettings::$qemuFolder)) {
ABHelper::backupLog("VM manager is NOT enabled! Cannot restore VM meta", ABHelper::LOGLEVEL_ERR);
} else {
$output = $resultcode = null;
exec('tar -C ' . escapeshellarg($tarDestination) . ' -xzf ' . escapeshellarg($restoreSource . '/vm_meta.tgz') . " " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
ABHelper::backupLog("tar return: $resultcode, output: " . print_r($output, true), ABHelper::LOGLEVEL_DEBUG);
if ($resultcode != 0) {
Expand Down

0 comments on commit a3dfca1

Please sign in to comment.