diff --git a/src/Console/BackupDatabaseCommand.php b/src/Console/BackupDatabaseCommand.php index 1abbcd6..0376b9f 100644 --- a/src/Console/BackupDatabaseCommand.php +++ b/src/Console/BackupDatabaseCommand.php @@ -27,13 +27,15 @@ class BackupDatabaseCommand extends Command protected function configure(): void { $this->addArgument('name', InputArgument::OPTIONAL, 'Database name'); + $this->addArgument('file', InputArgument::OPTIONAL, 'Backup file name'); } protected function execute(InputInterface $input, OutputInterface $output): int { $db = $this->getDatabaseName($input, $output); + $fileName = $input->getArgument('file'); - $backupName = $this->bs->backup($db); + $backupName = $this->bs->backup($db, $fileName); $output->writeln(sprintf('Backup written to: %s', $backupName)); return Command::SUCCESS; diff --git a/src/Service/BackupService.php b/src/Service/BackupService.php index 57b8724..19d4d70 100644 --- a/src/Service/BackupService.php +++ b/src/Service/BackupService.php @@ -21,15 +21,22 @@ class BackupService $fileName = sprintf('%s_%s_backup.sql', $db, $date); } - $filesystem = new Filesystem(); $process = new Process([ 'mysqldump', '-u', $this->credentials->getUser(), $db, ]); $process->setEnv(['MYSQL_PWD' => $this->credentials->getPassword()]); - $process->run(); - $filesystem->dumpFile($fileName, $process->getOutput()); + $process->start(); + + $stream = fopen($fileName, 'w+'); + foreach ($process as $type => $data) { + if ($process::OUT === $type) { + fwrite($stream, $data); + } else { // $process::ERR === $type + echo "\nError: " . $data; + } + } return $fileName; }