From 125e388ded326ff88b0e62da4954fb4f388c2b76 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 9 Aug 2023 23:08:07 +0300 Subject: [PATCH] Exec by id --- src/Appwrite/Platform/Tasks/Backup.php | 10 +++++++++- src/Appwrite/Platform/Tasks/Restore.php | 14 +++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Backup.php b/src/Appwrite/Platform/Tasks/Backup.php index 912794d5f7..4e1746bcf5 100644 --- a/src/Appwrite/Platform/Tasks/Backup.php +++ b/src/Appwrite/Platform/Tasks/Backup.php @@ -23,6 +23,7 @@ class Backup extends Action protected ?DSN $dsn = null; protected ?string $database = null; protected ?DOSpaces $s3 = null; + protected string $xtrabackupContainerId; /** * @throws Exception @@ -87,6 +88,13 @@ class Backup extends Action } } while ($attempts < $max); + $this->xtrabackupContainerId = shell_exec('docker ps -aqf "name=xtrabackup"'); + $this->xtrabackupContainerId = str_replace(PHP_EOL, '', $this->xtrabackupContainerId); + if (empty($this->xtrabackupContainerId)) { + Console::error('Xtrabackup Container ID not found'); + Console::exit(); + } + Console::loop(function () { $this->start(); }, self::BACKUP_INTERVAL_SECONDS); @@ -148,7 +156,7 @@ class Backup extends Action '2> ' . $logfile, ]; - $cmd = 'docker exec xtrabackup ' . implode(' ', $args); + $cmd = 'docker exec ' . $this->xtrabackupContainerId . ' ' . implode(' ', $args); self::log($cmd); shell_exec($cmd); diff --git a/src/Appwrite/Platform/Tasks/Restore.php b/src/Appwrite/Platform/Tasks/Restore.php index 8dd819cf05..52e348e3a9 100644 --- a/src/Appwrite/Platform/Tasks/Restore.php +++ b/src/Appwrite/Platform/Tasks/Restore.php @@ -21,11 +21,19 @@ class Restore extends Action protected ?DSN $dsn = null; protected string $database; protected ?DOSpaces $s3 = null; + protected string|null $xtrabackupContainerId = null; public function __construct() { $this->checkEnvVariables(); + $this->xtrabackupContainerId = shell_exec('docker ps -aqf "name=xtrabackup"'); + $this->xtrabackupContainerId = str_replace(PHP_EOL, '', $this->xtrabackupContainerId); + if (empty($this->xtrabackupContainerId)) { + Console::error('Xtrabackup Container ID not found'); + Console::exit(); + } + $this ->desc('Restore a DB') ->param('id', '', new Text(20), 'The backup identification') @@ -166,7 +174,7 @@ class Restore extends Action '2> ' . $logfile, ]; - $cmd = 'docker exec xtrabackup ' . implode(' ', $args); + $cmd = 'docker exec ' . $this->xtrabackupContainerId . ' ' . implode(' ', $args); $this->log($cmd); shell_exec($cmd); @@ -199,7 +207,7 @@ class Restore extends Action '2> ' . $logfile, ]; - $cmd = 'docker exec xtrabackup ' . implode(' ', $args); + $cmd = 'docker exec ' . $this->xtrabackupContainerId . ' ' . implode(' ', $args); $this->log($cmd); shell_exec($cmd); @@ -234,7 +242,7 @@ class Restore extends Action '2> ' . $logfile, ]; - $cmd = 'docker exec xtrabackup ' . implode(' ', $args); + $cmd = 'docker exec ' . $this->xtrabackupContainerId . ' ' . implode(' ', $args); $this->log($cmd); shell_exec($cmd);