Advertisement
rafal007

[php] archiwe mysql

May 28th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. //http://motylpro.pl/kategoria-produktu/kosmetyka/
  2. //use Symfony\Component\Process\Process;
  3. <?php
  4.  
  5. namespace App\Console\Commands;
  6.  
  7. use Illuminate\Console\Command;
  8. use Symfony\Component\Process\Process;
  9. use Symfony\Component\Process\Exception\ProcessFailedException;
  10.  
  11. class BackupDatabase extends Command
  12. {
  13.     protected $signature = 'db:backup';
  14.  
  15.     protected $description = 'Backup the database';
  16.  
  17.     protected $process;
  18.  
  19.     public function __construct()
  20.     {
  21.         parent::__construct();
  22.  
  23.         $this->process = new Process(sprintf(
  24.             'mysqldump -u%s -p%s %s > %s',
  25.             config('database.connections.mysql.username'),
  26.             config('database.connections.mysql.password'),
  27.             config('database.connections.mysql.database'),
  28.             storage_path('backups/backup.sql')
  29.         ));
  30.     }
  31.  
  32.     public function handle()
  33.     {
  34.         try {
  35.             $this->process->mustRun();
  36.  
  37.             $this->info('The backup has been proceed successfully.');
  38.         } catch (ProcessFailedException $exception) {
  39.             $this->error('The backup process has been failed.');
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement