From 5b3731a631db736ba96810b4ca3a1e74b31a0f99 Mon Sep 17 00:00:00 2001 From: Robin Kluth Date: Fri, 31 Mar 2023 19:19:01 +0200 Subject: [PATCH] Let user choose optional target destination --- src/pages/content/restore.php | 103 ++++++++++++++++++++++------------ src/scripts/restore.php | 11 +++- 2 files changed, 74 insertions(+), 40 deletions(-) diff --git a/src/pages/content/restore.php b/src/pages/content/restore.php index 10979ac..398fd80 100644 --- a/src/pages/content/restore.php +++ b/src/pages/content/restore.php @@ -22,56 +22,85 @@
  • Restore extra files
  • Restore backup configuration
  • -

    You have to create the docker containers by its restored template yourself!

    +
    +

    The restore process is NOT able to:

    +
    Step 1: Select source
    -
    Backup source:
    -
    - -
    - -
    Backup destination:
    -
    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! -
    +
    +
    Backup source:
    +
    +
    +
    + +
    +

    The folder which contains ab_xxx folders.

    +
    + + +
    +
    Backup destination:
    +
    +
    The default 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!
    + If you want to force a custom destination, enter it below. The archive will be extracted + there
    + THIS IS ONLY APPLICABLE TO ARCHIVES!
    +

    + +
    +
    +
    + diff --git a/src/scripts/restore.php b/src/scripts/restore.php index 8b7d8fc..b29919c 100644 --- a/src/scripts/restore.php +++ b/src/scripts/restore.php @@ -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']; @@ -88,7 +93,7 @@ ABHelper::backupLog("Restoring $container"); $tarOptions = [ - '-C /', + '-C ' . escapeshellarg($tarDestination), '-x', '-f ' . escapeshellarg($restoreSource . '/' . $container) ]; @@ -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) ]; @@ -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);