Last active
October 16, 2017 13:01
-
-
Save ercanertan/3210d9c470a19ce0ce87d8239c2daa64 to your computer and use it in GitHub Desktop.
Mysql Export/Import for Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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