DEV Community

loading...

How to Backup Laravel Files and Database

Ellis
・2 min read

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
Enter fullscreen mode Exit fullscreen mode

Once you installed the package, run the next command below which will publish the config file to config/backup.php.

php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
Enter fullscreen mode Exit fullscreen mode

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(‘vendor’), base_path(‘node_modules’). It means don’t include vendor and nod_modules folders in the final backup.

We are also passing a disks value as local. Doing so, our backup will stored in the storage/app/Laravel folder.

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
Enter fullscreen mode Exit fullscreen mode

Reference

From here learn setting up backup and cron job scheduling for automatic backup Laravel app.

Discussion (0)