vendredi 27 mai 2016

Adding Task in laravel 5.2

I am trying to backup my database every day by Task Scheduling, I have created my own command & register it in $commands (in App\Console\kernel.php). My command is :

public function handle()
{
    $date = Carbon::now()->format('Y-m-d_H-i-s');

    $user = env('DB_USERNAME');
    $password = env('DB_PASSWORD');
    $database = env('DB_DATABASE');

    $command = "mysqldump --user={$user} ".((empty($password))?"":"-p{$password}")." {$database} > {$date}.sql";

    // run command
    $process = new Process($command);
    $process->start();

    // wait for process
    while($process->isRunning()){}        

    // copy sql file from root to storage folder
    \Storage::put("/DB_backups/".$date.".sql", file_get_contents(base_path($date.".sql")));   

    // delete sql file from root 
    unlink(base_path("{$date}.sql"));
    echo $process->getOutput();
}

my $signature = 'backup:database';

my kernal.php

class Kernel extends ConsoleKernel{

  protected $commands = [
   //Commands\Inspire::class,
   Commands\databaseBackup::class,
  ];


  protected function schedule(Schedule $schedule)
  {
      $schedule->command('backup:database')->everyFiveMinutes();

  }
}

I put it every 5 minutes to test it.

in Crontab I added:

* * * * * php /Users/rashid/Sites/plate/artisan schedule:run >> /dev/null 2>&1

I have restarted my server, but no result (NOTE: I am using Valet for my server) .

Any help to solve this issue :(



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire