Skip to content

Instantly share code, notes, and snippets.

@ercanertan
Last active October 16, 2017 13:01
Show Gist options
  • Save ercanertan/3210d9c470a19ce0ce87d8239c2daa64 to your computer and use it in GitHub Desktop.
Save ercanertan/3210d9c470a19ce0ce87d8239c2daa64 to your computer and use it in GitHub Desktop.
Mysql Export/Import for Laravel
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
//Export
$process = new Process('mysqldump -u'.env('DB_USERNAME').' -p'.env('DB_PASSWORD').' '.env('DB_DATABASE').' > db-backups/'.Carbon::now()->timestamp.'.sql');
//Import (on production add password as well '-p'.env('DB_PASSWORD'))
$process = new Process('mysql -u'.env('DB_USERNAME').' '.env('DB_DATABASE').' '.'< db-backups/1508156934.sql');
$process->run(); // to run Sync
// OR
$process->start(); // Running Processes Asynchronously
// while ($process->isRunning()) {
// }
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
return $process->getOutput();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment