lundi 3 septembre 2018

Database Backup failing in Laravel

I've created a cronjob for backing up database and works well locally. Below is the code for local machine:

public function handle()
    {
        $date = Carbon::now()->format('d-m-Y');            
        $user = env('DB_USERNAME');
        $password = env('DB_PASSWORD');
        $database = env('DB_DATABASE');
        $command = "mysqldump --user={$user} --password={$password} {database} > {$date}.sql";
        $path = 'User Database Backup/'.Carbon::now()->format('F').' '.Carbon::now()->format('Y');
        $process = new Process($command);        
        $process->start();    

        while ($process->isRunning()) {

            $public = Storage::disk('public');
            $public->put('users/'.$path.'/'.$date.".sql", file_get_contents("{$date}.sql"));       
            unlink("{$date}.sql");      
        }       
    }

But when i apply the same in my Laravel app in production it creates an sql file containing:

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

Below is the code im using in production app. I'm pushing the sql file to s3 storage.

public function handle()
    {
        $date = Carbon::now()->format('d-m-Y');            
        $user = env('DB_USERNAME');
        $password = env('DB_PASSWORD');
        $database = env('DB_DATABASE');
        $command = "mysqldump --user={$user} --password={$password} {$database} > {$date}.sql";
        $path = 'User Database Backup/'.Carbon::now()->format('F').' '.Carbon::now()->format('Y');
        $process = new Process($command);        
        $process->start();    

        while ($process->isRunning()) {

            $s3 = Storage::disk('s3');
            $s3->put('users/'.$path.'/'.$date.".sql", file_get_contents("{$date}.sql"));       
            unlink("{$date}.sql");      
        }       
    }

Can someone tell me why this happens? And how to solve this



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire