
How to export Laravel Database dump easily in 20 lines of coding - Backup DB
¶Why Needs Database backup regularly ?
For a website, sometimes, you should keep backup your database regularly so that you could handle any bad scenarios when things just bloated up. Some hackers could hack your site and can destroy the database. If he. destroy database, then your all life-long investment into that website will gone into dustbin. So I believe it’s very much important for a site owner to make a backup of their website database regularly. And I’ve added a quick simple way to make backup a laravel blog website database regularly.
¶Let’s make Laravel database backup code -
¶Step 1:
Open the routes/web.php
file and add the following code:
web.php
Route::get('/export-db', 'BackupController@exportDB')->name('export');
¶Step 2:
Go to app/Http/Controllers
. Create a file called BackupController.php
. Let’s put the following code in it -
BackupController.php
¶Step 3:
So, we’ve done. Now let’s get our backup by calling this URL daily - http://localhost:8000/export-db?password=astrongpassword
[Note: http://localhost:8000 would be your website domain name]
Whenever you’ll hit this route, you’ll get your database backup sql file like so - dbname-2023-01-01.sql
Hope you enjoyed this simple approach to backup Laravel based database regularly.
PHP If-else-elseif and Switch-case
PHP String Functions - All necessary String functions in PHP to manage strings better.
Popular Tutorials
Categories
-
Bash Scripting
1
-
Bootstrap CSS
0
-
C Programming
8
-
C#
0
-
ChatGPT
1
-
Code Editor
2
-
CSS
2
-
Design Pattern in PHP
2
-
E-Book
1
-
Git Commands
1
-
HTML
19
-
Interview Prepration
2
-
Java Programming
0
-
JavaScript
11
-
Laravel PHP Framework
37
-
Mysql
1
-
Node JS
1
-
Online Business
0
-
PHP
28
-
Programming
7
-
Python
1
-
React Js
19
-
React Native
1
-
Redux
2
-
Tailwind CSS
1
-
Typescript
10
-
Uncategorized
0
-
Vue JS
1
-
Windows Operating system
1
-
Woocommerce
1
-
WordPress Development
2
Tags
- Bash Scripting
- Business
- C
- C-sharp programming
- C++
- Code Editor
- CSS
- Database
- Design pattern
- Express JS
- git
- Git Commands
- github
- HTML
- Java
- JavaScript
- Laravel
- Mathematics
- MongoDB
- Mysql
- Node JS
- PHP
- Programming
- Python
- React Js
- Redux
- TypeScript
- Vue JS
- Windows terminal
- Woocommerce
- WordPress
- WordPress Plugin Development