Update UpdateSoftwareCommand.php
This commit is contained in:
parent
6de0c1eeb5
commit
86fedf3f35
|
@ -1,6 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
@ -289,33 +288,35 @@ class UpdateSoftwareCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
private function backupDatabase(): string
|
private function backupDatabase(): string
|
||||||
{
|
{
|
||||||
$backupFile = $this->backupDir . '/db_backup_' . time() . '.sql';
|
$backupFile = $this->backupDir . '/db_backup_' . time() . '.sql';
|
||||||
$dbUrl = $this->params->get('DATABASE_URL');
|
$dbUrl = $this->params->get('database_url');
|
||||||
$urlParts = parse_url($dbUrl);
|
$urlParts = parse_url($dbUrl);
|
||||||
|
|
||||||
$dbHost = $urlParts['host'] ?? 'localhost';
|
$dbHost = $urlParts['host'] ?? 'localhost';
|
||||||
$dbUser = $urlParts['user'] ?? 'root';
|
$dbUser = $urlParts['user'] ?? 'root';
|
||||||
$dbPass = $urlParts['pass'] ?? '';
|
$dbPass = $urlParts['pass'] ?? '';
|
||||||
$dbName = ltrim($urlParts['path'] ?? '', '/');
|
$dbName = ltrim($urlParts['path'] ?? '', '/');
|
||||||
|
|
||||||
$command = [
|
$command = [
|
||||||
'mysqldump',
|
'mysqldump',
|
||||||
'-h', $dbHost,
|
'-h', $dbHost,
|
||||||
'-u', $dbUser,
|
'-u', $dbUser,
|
||||||
'-p' . $dbPass,
|
'-p' . $dbPass,
|
||||||
$dbName,
|
$dbName
|
||||||
'>',
|
];
|
||||||
$backupFile
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->runProcess($command, $this->rootDir, new \Symfony\Component\Console\Output\NullOutput());
|
$process = new Process($command, $this->rootDir);
|
||||||
if (!file_exists($backupFile)) {
|
$process->setTimeout(3600);
|
||||||
throw new \RuntimeException('Failed to create database backup.');
|
$process->mustRun();
|
||||||
|
file_put_contents($backupFile, $process->getOutput());
|
||||||
|
|
||||||
|
if (!file_exists($backupFile) || filesize($backupFile) === 0) {
|
||||||
|
throw new \RuntimeException('Failed to create database backup.');
|
||||||
|
}
|
||||||
|
$this->logger->info("Database backup created at: $backupFile");
|
||||||
|
return $backupFile;
|
||||||
}
|
}
|
||||||
return $backupFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private function backupArchive(): string
|
private function backupArchive(): string
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue