Move check to start function

This commit is contained in:
fogelito
2023-08-15 12:49:08 +03:00
parent bebe3a217f
commit 4fdd76dc95
3 changed files with 56 additions and 47 deletions
Generated
+6 -6
View File
@@ -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",
+25 -21
View File
@@ -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;
}
}
+25 -20
View File
@@ -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;
}
}