Answer the question
In order to leave comments, you need to log in
How to correctly form a request to restore a database from a backup for new Process from Symphony?
There is a method that restores a database from a backup. Looks like this:
private function restoreSnapShot()
{
$snapshot = $this->option('snapshot');
if (!$snapshot) {
$this->error("Snapshot option is required.");
}
try {
$storage = Storage::disk('local');
$found = $storage->get('/backups/' . $snapshot . '.sql');
$tempLocation = '/tmp/' . config('database.connections.mysql.database') . '_' . date("Y-m-d_Hi") . '.sql';
// create a temp file
$bytes_written = File::put($tempLocation, $found);
if ($bytes_written === false) {
$this->info("Error writing to file: " . $tempLocation);
}
// run the cli job
$this->process = new Process([
'mysql',
'--host=' . config('database.connections.mysql.host'),
'--user=' . config('database.connections.mysql.username'),
'--password=' . config('database.connections.mysql.password'),
config('database.connections.mysql.database'),
$tempLocation
]);
$this->process->mustRun();
if ($this->process->isSuccessful()) {
$this->info("Restored snapshot: " . $snapshot);
}
} catch (\Exception $e) {
$this->info('File Not Found: ' . $e->getMessage());
}
}
$this->process = new Process([" mysql -u user -pPassword < mydatabase.sql"])
, doesn't work either. Answer the question
In order to leave comments, you need to log in
$this->process = Process::fromShellCommandline( 'mysql -u $username -p"$password" $database < $file' );
$this->process->run( null, [
'username' => $username,
'password' => $password,
'database' => $database,
'file' => $file,
] );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question