Skip to content

Commit

Permalink
Let user choose optional target destination
Browse files Browse the repository at this point in the history
  • Loading branch information
Commifreak committed Mar 31, 2023
1 parent 4f81949 commit 5b3731a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 40 deletions.
103 changes: 66 additions & 37 deletions src/pages/content/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,56 +22,85 @@
<li>Restore extra files</li>
<li>Restore backup configuration</li>
</ul>
<p><b>You have to create the docker containers by its restored template yourself!</b></p>
<br/>
<p>The restore process <b>is NOT able to</b>:</p>
<ul>
<li>Create your docker containers</li>
<li>Take care of stopping containers prior restore
<ul>
<li>Please stop all maybe affected containers yourself prior to the restore!</li>
</ul>
</li>
</ul>

<form id="restoreForm">

<div class="title"><span class="left"><i class="fa fa-folder title"></i>Step 1: Select source</span></div>
<dt><b>Backup source:</b></dt>
<dd><input type='text' required class='ftAttach' id="restoreSource" name="restoreSource"
value="<?= empty($abSettings->destination) ? '' : $abSettings->destination ?>"
data-pickfilter="HIDE_FILES_FILTER" data-pickfolders="true">
<button onclick="checkRestoreSource(); return false;">Check</button>
</dd>

<dt><b>Backup destination:</b></dt>
<dd>The destination will be the same as it were during backup. If the destination does not exist, it will be
created. Any existing data will be overwritten!
</dd>
<dl>
<dt><b>Backup source:</b></dt>
<dd><input type='text' required class='ftAttach' id="restoreSource" name="restoreSource"
value="<?= empty($abSettings->destination) ? '' : $abSettings->destination ?>"
data-pickfilter="HIDE_FILES_FILTER" data-pickfolders="true">
</dd>
</dl>

<blockquote class='inline_help'>
<p>The folder which contains <code>ab_xxx</code> folders.</p>
</blockquote>


<dl>
<dt><b>Backup destination:</b></dt>
<dd>
<div style="display: table">The <b>default</b> destination will be the same as it were during backup. If the
destination does not exist, it will be
created. Any existing data will be overwritten!<br/>
<b>If you want to force a custom destination</b>, enter it below. The archive will be extracted
there<br/>
<b>THIS IS ONLY APPLICABLE TO ARCHIVES!</b><br/>
<input type='text' class='ftAttach' id="customRestoreDestination" name="customRestoreDestination"
placeholder="Force custom destination"
data-pickfilter="HIDE_FILES_FILTER" data-pickfolders="true"><br/><br/>
<button onclick="checkRestoreSource(); return false;">Next</button>
</div>
</dd>
</dl>


<div id="restoreBackupDiv" style="display: none">
<div class="title"><span class="left"><i class="fa fa-folder title"></i>Step 2: Select backup</span></div>
<dt><b>Select backup:</b></dt>
<dd><select required id="restoreBackupList" name="restoreBackupList"></select>
<button onclick="checkRestoreItem(); return false;">Next</button>
</dd>
<dl>
<dt><b>Select backup:</b></dt>
<dd><select required id="restoreBackupList" name="restoreBackupList"></select>
<button onclick="checkRestoreItem(); return false;">Next</button>
</dd>
</dl>
</div>

<div id="restoreItemsDiv" style="display: none">
<div class="title"><span class="left"><i class="fa fa-folder title"></i>Step 3: Select items</span></div>
<p><b>Note:</b> If one item is not selectable, the chosen backup does not contain needed data.</p>

<dt><b>Restore backup config?:</b></dt>
<dd><input type="checkbox" id="restoreItemConfig" name="restoreItem[config]"> Yes</dd>

<dt><b>Restore extra files?:</b><br/><small><b>CAUTION!</b> The files will be restored to the ORIGINAL
location!</small></dt>
<dd><input type="checkbox" id="restoreItemExtraFiles" name="restoreItem[extraFiles]"> Yes</dd>
<br/>
<dt><b>Restore VM meta?:</b><br/><small><b>CAUTION!</b> Restore will override /etc/libvirt/qemu contents!
Restart VM manager after restore!</small></dt>
<dd><input type="checkbox" id="restoreItemVmMeta" name="restoreItem[vmMeta]"> Yes</dd>
<br/>
<dt><b>Restore templates?:</b></dt>
<dd>
<div style="display: table;" id="restoreTemplatesDD"></div>
</dd>

<dt><b>Restore containers?:</b><br/><small><b>CAUTION!</b> The files will be restored to the ORIGINAL
location!</small></dt>
<dd>
<div style="display: table;" id="restoreContainersDD"></div>
</dd>
<dl>
<dt><b>Restore backup config?:</b></dt>
<dd><input type="checkbox" id="restoreItemConfig" name="restoreItem[config]"> Yes</dd>

<dt><b>Restore extra files?:</b></dt>
<dd><input type="checkbox" id="restoreItemExtraFiles" name="restoreItem[extraFiles]"> Yes</dd>
<br/>
<dt><b>Restore VM meta?:</b></dt>
<dd><input type="checkbox" id="restoreItemVmMeta" name="restoreItem[vmMeta]"> Yes</dd>
<br/>
<dt><b>Restore templates?:</b></dt>
<dd>
<div style="display: table;" id="restoreTemplatesDD"></div>
</dd>

<dt><b>Restore containers?:</b></dt>
<dd>
<div style="display: table;" id="restoreContainersDD"></div>
</dd>
</dl>

<button onclick="startRestore(); return false;">Do it!</button>
</div>
Expand Down
11 changes: 8 additions & 3 deletions src/scripts/restore.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
$config = json_decode($argv[1], true);
ABHelper::backupLog(print_r($config, true), ABHelper::LOGLEVEL_DEBUG);

$tarDestination = empty(trim($config['customRestoreDestination'])) ? '/' : $config['customRestoreDestination'];
if (!file_exists($tarDestination)) {
mkdir($tarDestination, 0777, true);
}

$restoreSource = $config['restoreBackupList'];


Expand Down Expand Up @@ -88,7 +93,7 @@
ABHelper::backupLog("Restoring $container");

$tarOptions = [
'-C /',
'-C ' . escapeshellarg($tarDestination),
'-x',
'-f ' . escapeshellarg($restoreSource . '/' . $container)
];
Expand Down Expand Up @@ -126,7 +131,7 @@
$extraFile = file_exists($restoreSource . '/extra_files.tar.zst') ? 'extra_files.tar.zst' : 'extra_files.tar.gz';

$tarOptions = [
'-C /',
'-C ' . escapeshellarg($tarDestination),
'-x',
'-f ' . escapeshellarg($restoreSource . '/' . $extraFile)
];
Expand Down Expand Up @@ -162,7 +167,7 @@
if (!file_exists(ABSettings::$qemuFolder)) {
ABHelper::backupLog("VM manager is NOT enabled! Cannot restore VM meta", ABHelper::LOGLEVEL_ERR);
} else {
exec('tar -C / -xzf ' . escapeshellarg($restoreSource . '/vm_meta.tgz') . " " . ABSettings::$externalCmdPidCapture, $output, $resultcode);
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) {
ABHelper::backupLog("restore failed, please see debug log.", ABHelper::LOGLEVEL_ERR);
Expand Down

0 comments on commit 5b3731a

Please sign in to comment.