Automatic DB backup in Laravel
Hi all, this is Adi again with a Laravel-related article. This time in a shorter format. As Laravel developers, we need a way to back up our apps' databases somewhere for both saving/keeping data and for analysis. I want to share with you a simple solution that I have devised for some of my smaller projects. I have tested this method only on MySQL DB and on a VPS, but I think it’s pretty much the same for any database.
You may also like:
Website Backups in 7 Simple Steps
TL;DR
The outline of my solution is as follows. There’s an artisan command that handles the backup and runs periodically using a cron. This command makes use of the mysqldump
tool that comes with all MySQL installations. mysqldump
dumps the given DB into a .sql
and we can control where it is dumped. And that’s how my solution works. Now let’s see some code.