phplaravellaravel-4.2

How to backup MySQL Database laravel 4.2 with cronjob


I have an project laravel 4.2 and now I will automatically make weekly backup of the database.
I find script but its not working

    public function fire()
    {
        try {
            $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('backups/backup.sql')
            ));

            $this->info('The backup has been proceed successfully.');
        } catch (ProcessFailedException $exception) {
            $this->error('The backup process has been failed.');
        }
    }

    protected function getArguments()
    {
        return array();
    } 

Showing error

PHP Fatal error: Call to undefined function config() in /var/www/html/guitarni_portal/app/commands/BackupDatabase.php on line 25 Error in exception handler: The stream or file "/var/www/html/guitarni_portal/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /var/www/html/guitarni_portal/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:107


Solution

  • You are using too old laravel. But still, you can use,

    Config::get instead of config.

    Should work.