Laravel is known to be a great PHP framework that contains an elegant, simple and expressive syntax that assists in coming up with great applications. The Laravel is known to ease process of development by making the repetitive tasks that are used in the development of most web applications including and not limited to caching, routing, authentication and session’s simple. Here in this article, I am going to explain to Backup Laravel Apps.
.
The Laravel app is also known to provide some great features such as the scalability, extension ability, quick institution and development speed. It also provides great programming results when compared to other programming tools hence most developers are known to prefer using the Laravel. Also, Learn how to backup MySQL database in PHP
How to Backup Laravel Apps?
To backup your Laravel apps, run:
1 2 3 | php artisan backup:run |
In case you are interested in backing up a specific disk, you will run:
1 2 3 | php artisan backup:run --only-to-disk=name-of-your-disk |
To back up the db, run:
1 2 3 | php artisan backup:run --only-db |
To back up only the files and skip dumping databases, run:
1 2 3 | php artisan backup:run --only-files |
How to Determine the Backup Content
The configuration below will help you determine the databases and files that will be backed up.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | 'backup' => [ /* * use this name to monitor the monitor back ups */ 'name' => env('APP_URL'), 'source' => [ 'files' => [ /* * The files and directories list that will be in the backup. */ base_path(), ], /* * The files and directories will be exempted from the back up. */ 'exclude' => [ base_path('vendor'), base_path('node_modules'), ], /* * Determines if symlinks should be followed. */ 'followLinks' =>false, ], /* * Connections name to the database that should be backed up. * Only MySQL- and PostgreSQL-databases are supported. */ 'databases' => [ 'mysql', ], ], 'destination' => [ /* * Names of disk where backups will be stored. */ 'disks' => [ 'local', ], ], ] |
Together will the selected and zipped files, the specified databases will be damped and the zip file named as
The more files you will back up the bigger the zip file will be. Hence, it is important you ensure there is enough free space on the desk in order to create the zip file. The source file will be deleted after the zip file has been copied to destinations.
Determine Backup Destination
You can copy the zipped backup to one or more file systems. Here is where you will specify the file systems destinations.
1 2 3 4 5 6 7 8 9 10 | 'destination' => [ /* * Names of disks where backups will be stored. */ 'disks' => [ 'local' ], ], |
Get Notified When Backup fails
It is possible to get notified whenever backup goes wrong.
You should start backing up your websites in production in case you have not been doing so. You need to be prudent with your back ups so that incase there is a data loss you will be able to easily and quickly recover.
Most of the projects today are version controlled hence, the project files will always be automatically backed up to a remote respiratory.
There are two major ways you can perform the Laravel apps back up. They include:
- A dedicated external service that handles the backup
- The application that handles the backup itself through the code
Self Handling Back ups
For example, I always use the Spatie’s Laravel Backup package in taking care of myself handling backups. The Spatie is easy to set up and enables you to save your database backups offsite to any file system that you have configured in the Laravel 5. However, extra features have been promised in the next release that will take place in a few months.
One of the alternative packages that I have not managed to try but seems to be common on the GitHub is the framework agnostic Backup Manager. This backup manager comes with the Laravel driver making it trivial to set up and get back ups going in minutes.
The External Back up Service
The external back up service will always make the backing up many websites much easier and provides one with a single dashboard that will be able to handle all the backups. I have managed to try two different ones, the BitCan and the Ottomatik
- Otoomatik
- BitCan
The Ottomatick is a service that has been specifically designed for the Laravel apps. The Ottomatick requires one to install a small application on the server before you can commence in configuring your backups.
The BitCan will allow you to configure servers either by installing applications that are similar to the Ottomatik or by installing their public SSH key. The public key approach
Conclusion
You need to be careful with the ‘—only-files’ and ‘—only-db’ when you are monitoring your backups. However, when you are monitoring backups, the package will never make a distinction between a backup that only contains databases and files and full backups.
Comments (1)