mercredi 9 octobre 2019

mysqldump command not working fro controller function in laravel

This command working from cpanel cron but i need to run this from Artisan::call() as well. But when i try to call artisan from controller function it throws a error

public function __construct()
    {
        parent::__construct();

        $file_path = 'backups/' . strtotime(Carbon::now()) . '-backup.sql';

        $this->process = new Process(sprintf(
            'mysqldump -u%s -p%s %s > %s',
            config('database.connections.mysql.username'),
            config('database.connections.mysql.password'),
            config('database.connections.mysql.database'),
            storage_path($file_path)
        ));
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        try {
            $this->process->mustRun();

            $this->info('The backup has been proceed successfully.');

        } catch (ProcessFailedException $exception) {
            \Log::info($exception->getMessage());
            $this->error('The backup process has been failed.');
        }
    }

Error when run from controller Artisan::call()

    [2019-10-09 19:32:56] production.INFO: The command "mysqldump -uedu99999 -pDGFGFG edudb > /home/eduworld/public_html/storage/backups/1570627976-backup.sql" failed.

Exit Code: 2(Misuse of shell builtins)

Working directory: /home/eduworld/public_html/public

Output:
================


Error Output:
================
mysqldump: Got error: 2002: "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" when trying to connect


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire