diff --git a/composer.lock b/composer.lock index 295b7ef387..043927746c 100644 --- a/composer.lock +++ b/composer.lock @@ -3253,16 +3253,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.16.0", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -3303,9 +3303,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2023-06-25T14:52:30+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phar-io/manifest", diff --git a/src/Appwrite/Platform/Tasks/Backup.php b/src/Appwrite/Platform/Tasks/Backup.php index 32009a8ebb..2d9f52f0f1 100644 --- a/src/Appwrite/Platform/Tasks/Backup.php +++ b/src/Appwrite/Platform/Tasks/Backup.php @@ -30,8 +30,6 @@ class Backup extends Action */ public function __construct() { - $this->checkEnvVariables(); - $this ->desc('Backup a database') ->param('database', null, new Text(20), 'Database name, for example db_fra1_01') @@ -49,6 +47,8 @@ class Backup extends Action */ public function action(string $database, Group $pools): void { + $this->checkEnvVariables(); + $this->database = $database; $this->dsn = $this->getDsn($database); if (is_null($this->dsn)) { @@ -87,8 +87,8 @@ class Backup extends Action } } while ($attempts < $max); - $this->setProcessors(); $this->setContainerId(); + $this->setProcessors(); sleep(20); @@ -100,7 +100,7 @@ class Backup extends Action public function start(): void { $start = microtime(true); - $time = date('Y_m_d_H_i_s'); + $time = date('Y_m_d-H_i_s'); self::log('--- Backup Start ' . $time . ' --- '); @@ -261,22 +261,6 @@ class Backup extends Action return null; } - public function setProcessors() - { - $stdout = ''; - $stderr = ''; - Console::execute('nproc', '', $stdout, $stderr); - if (!empty($stderr)) { - Console::error('Error setting processors: ' . $stderr); - Console::exit(); - } - - $processors = str_replace(PHP_EOL, '', $stdout); - $processors = intval($processors); - $processors = $processors === 0 ? 1 : $processors; - $this->processors = $processors; - } - public function setContainerId() { $stdout = ''; @@ -288,7 +272,6 @@ class Backup extends Action } $containerId = str_replace(PHP_EOL, '', $stdout); - if (empty($containerId)) { Console::error('Xtrabackup Container ID not found'); Console::exit(); @@ -296,4 +279,25 @@ class Backup extends Action $this->xtrabackupContainerId = $containerId; } + + public function setProcessors() + { + $stdout = ''; + $stderr = ''; + Console::execute('docker exec ' . $this->xtrabackupContainerId . ' nproc', '', $stdout, $stderr); + if (!empty($stderr)) { + Console::error('Error setting processors: ' . $stderr); + Console::exit(); + } + + $processors = str_replace(PHP_EOL, '', $stdout); + $processors = intval($processors); + + if ($processors === 0) { + Console::error('Set Processors Error'); + Console::exit(); + } + + $this->processors = $processors; + } } diff --git a/src/Appwrite/Platform/Tasks/Restore.php b/src/Appwrite/Platform/Tasks/Restore.php index a7a50dc8ed..aa840feeb9 100644 --- a/src/Appwrite/Platform/Tasks/Restore.php +++ b/src/Appwrite/Platform/Tasks/Restore.php @@ -25,10 +25,6 @@ class Restore extends Action public function __construct() { - $this->checkEnvVariables(); - $this->setProcessors(); - $this->setContainerId(); - $this ->desc('Restore a DB') ->param('id', '', new Text(20), 'The backup identification') @@ -44,6 +40,10 @@ class Restore extends Action public function action(string $id, string $cloud, string $database): void { + $this->checkEnvVariables(); + $this->setContainerId(); + $this->setProcessors(); + $this->database = $database; $datadir = self::DATADIR; $this->dsn = $this->getDsn($database); @@ -284,22 +284,6 @@ class Restore extends Action return null; } - public function setProcessors() - { - $stdout = ''; - $stderr = ''; - Console::execute('nproc', '', $stdout, $stderr); - if (!empty($stderr)) { - Console::error('Error setting processors: ' . $stderr); - Console::exit(); - } - - $processors = str_replace(PHP_EOL, '', $stdout); - $processors = intval($processors); - $processors = $processors === 0 ? 1 : $processors; - $this->processors = $processors; - } - public function setContainerId() { $stdout = ''; @@ -318,4 +302,25 @@ class Restore extends Action $this->xtrabackupContainerId = $containerId; } + + public function setProcessors() + { + $stdout = ''; + $stderr = ''; + Console::execute('docker exec ' . $this->xtrabackupContainerId . ' nproc', '', $stdout, $stderr); + if (!empty($stderr)) { + Console::error('Error setting processors: ' . $stderr); + Console::exit(); + } + + $processors = str_replace(PHP_EOL, '', $stdout); + $processors = intval($processors); + + if ($processors === 0) { + Console::error('Set Processors Error'); + Console::exit(); + } + + $this->processors = $processors; + } }