4 months ago

Scheduling SQL backups with laravel outside storage path

Posted 4 months ago by Gabotronix

Hi everybody, I know it's possible to schedule commands to be run with laravel and cron job, my goal is tro create a command to backup my sql databases into my home directory inside my VPS, the example I found uses laravel storage path to drop the backups but I was wondering how can I choose another file outside my laravel app folder (my user home directory for example), is it possible to do?


namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

class BackupDatabase extends Command
    protected $signature = 'db:backup';

    protected $description = 'Backup the database';

    protected $process;

    public function __construct()

        $this->process = new Process(sprintf(
            'mysqldump -u%s -p%s %s > %s',

    public function handle()
        try {

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

Please sign in or create an account to participate in this conversation.