Ensuring data backup is the most vital part of any application’s redundancy plan. It allows developers to ensure the second state of data in case of any accidental failures, so that the continuation of processes doesn’t get affected and the overall operation always stays in flow.
Therefore, backup is an integral part of any application development life cycle, as it provides a suitable layer of data persistence in the events of unwanted disasters. That being said, let’s take a look at how to take backup of Laravel application with the database.
The latest version of this package requires PHP 7.2 or higher with the ZIP module and Laravel 5.7 or higher. If you are using the old version of Laravel then version 5 and version 4 of this package available.
At first, you need to install the package by running the command below:
composer require spatie/laravel-backup
Once you installed the package, run the next command below which will publish the config file to
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
A user can also include and exclude the directories for backup. For the include we have passed the value
base_path() and for exclude option values are
base_path(‘node_modules’). It means don’t include
nod_modules folders in the final backup.
We are also passing a disks value as
local. Doing so, our backup will stored in the
So far we are done with the installation and setup. Now We all set to run our first backup. Open the terminal in your project root directory and run the command:
php artisan backup:run
From here learn setting up backup and cron job scheduling for automatic backup Laravel app.