Add restore command
This commit is contained in:
@ -33,8 +33,8 @@ class BackupDatabase extends Command
|
||||
{
|
||||
$db = $this->getDatabaseName($input, $output);
|
||||
|
||||
$output = $this->bs->backup($db);
|
||||
dump($output);
|
||||
$backupName = $this->bs->backup($db);
|
||||
$output->writeln(sprintf('Backup written to: %s', $backupName));
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
52
src/Console/RestoreDatabase.php
Normal file
52
src/Console/RestoreDatabase.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Service\BackupService;
|
||||
use App\Service\DatabaseService;
|
||||
use App\Service\Traits\SelectDatabaseQuestion;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class RestoreDatabase extends Command
|
||||
{
|
||||
use SelectDatabaseQuestion;
|
||||
|
||||
protected static $defaultName = 'app:db:restore';
|
||||
|
||||
public function __construct(
|
||||
private DatabaseService $db,
|
||||
private BackupService $bs,
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this->addArgument('name', InputArgument::OPTIONAL, 'Database name');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$question = $this->getHelper('question');
|
||||
$db = $this->getDatabaseName($input, $output);
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->in(__DIR__ . '/../..');
|
||||
$files = [sprintf('%s_backup.sql', $db)];
|
||||
foreach ($finder->files()->name('*_backup.sql') as $file) {
|
||||
$files[] = $file->getFilename();
|
||||
}
|
||||
$selectQuestion = new ChoiceQuestion('Backup name (*_backup.sql): ', $files);
|
||||
$fileName = $question->ask($input, $output, $selectQuestion);
|
||||
|
||||
$this->bs->restore($db, $fileName);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user