Skip to content

Commit

Permalink
Merge pull request #36 from Blasman/patch-1
Browse files Browse the repository at this point in the history
Add `pre-container` and `post_container` scripts which run right before and after creation of the tar
  • Loading branch information
Commifreak authored Aug 16, 2024
2 parents 83dc1c1 + a839dfc commit 190d02a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/include/ABHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,10 +619,15 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
foreach ($containerListOverride ? array_reverse($containerListOverride) : $sortedStopContainers as $_container) {
foreach (self::resolveContainer($_container, true) ?: [$_container] as $container) {
self::setCurrentContainerName($container);

ABHelper::handlePrePostScript($abSettings->preContainerBackupScript, 'pre-container', $container['Name']);

if (!self::backupContainer($container, $abDestination)) {
self::$errorOccured = true;
}

ABHelper::handlePrePostScript($abSettings->postContainerBackupScript, 'post-container', $container['Name']);

if (self::abortRequested()) {
return false;
}
Expand Down Expand Up @@ -684,10 +689,14 @@ public static function doBackupMethod($method, $containerListOverride = null,) {
return false;
}

ABHelper::handlePrePostScript($abSettings->preContainerBackupScript, 'pre-container', $container['Name']);

if (!self::backupContainer($container, $abDestination)) {
self::$errorOccured = true;
}

ABHelper::handlePrePostScript($abSettings->postContainerBackupScript, 'post-container', $container['Name']);

if (self::abortRequested()) {
return false;
}
Expand Down
4 changes: 3 additions & 1 deletion src/include/ABSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class ABSettings {
public string $preBackupScript = '';
public string $postBackupScript = '';
public string $postRunScript = '';
public string $preContainerBackupScript = '';
public string $postContainerBackupScript = '';
public array $includeFiles = [];
public array $globalExclusions = [];
public string $backupVMMeta = 'yes';
Expand Down Expand Up @@ -320,4 +322,4 @@ public function checkCron() {

if (!file_exists(ABSettings::$tempFolder)) {
mkdir(ABSettings::$tempFolder);
}
}
26 changes: 25 additions & 1 deletion src/pages/content/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,30 @@ class="fa fa-info"></i> Those must return exit code 0 for success detection</sma
path</code></p>
</blockquote>

<dl>
<dt>Pre-container-backup script</dt>
<dd><input style="width: 500px;" type='text' class='ftAttach' id="preContainerBackupScript" name="preContainerBackupScript"
value="<?= $abSettings->preContainerBackupScript ?>"
data-pickroot="/mnt/"/></dd>
</dl>

<blockquote class='inline_help'>
<p>Runs the selected script for each container immediately BEFORE creating the tarfile. Sent arguments: <code>pre-container</code>,
<code>container name</code></p>
</blockquote>

<dl>
<dt>Post-container-backup script</dt>
<dd><input style="width: 500px;" type='text' class='ftAttach' id="postContainerBackupScript" name="postContainerBackupScript"
value="<?= $abSettings->postContainerBackupScript ?>"
data-pickroot="/mnt/"/></dd>
</dl>

<blockquote class='inline_help'>
<p>Runs the selected script for each container immediately AFTER creating the tarfile. Sent arguments: <code>post-container</code>,
<code>container name</code></p>
</blockquote>

<dl>
<dt>Post-backup script</dt>
<dd><input style="width: 500px;" type='text' class='ftAttach' id="postBackupScript" name="postBackupScript"
Expand Down Expand Up @@ -1065,4 +1089,4 @@ function copyConfigFromProd() {
alert('Something went wrong :/')
});
}
</script>
</script>

0 comments on commit 190d02a

Please sign in to comment.