Exec by id

This commit is contained in:
fogelito
2023-08-09 23:08:07 +03:00
parent d9ece4c761
commit 125e388ded
2 changed files with 20 additions and 4 deletions
+9 -1
View File
@@ -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);
+11 -3
View File
@@ -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);