Create a backup schedule for Database with Cron Job

To back up the database for WordPress, there are many plugins that can help you do this. However, if you are a longtime WordPress user, you will probably realize that the plugins are unreliable.

QuanTriMang - To backup the database for WordPress, there are many plugins that can help you do this. Some of them only back up the database for you, while there are also things to help backup the entire directory in WordPress. If you are a long-time WordPress user, you will realize that the plugins are unreliable. With thousands of reasons why they work every other day - unstable. It may be because they are not compatible with the version of WordPress you have just upgraded, or there is a conflict with certain plugins that have been installed or even because the database is too large for the plugin's handling capability.

The following article will show a solution to improve this problem, which is to replace plugins by using the Cron Job for your server and schedule a daily backup of the database.

Note: The following instructions can be used to backup every database, the only requirement is that you need to use a Linux server to store files.

Steps to take:

1. Log in to your web server control. If you use cPanel, go to the Cron job icon.

Picture 1 of Create a backup schedule for Database with Cron Job

2. You can set the time and frequency of database backup. Under the command field, copy and paste the following command:

mysqldump --opt -Q -u dbusername --password = dbpassword dbname |gzip > /path-to-store-the-backup-file/db_backup.sql.gz

  1. Replace dbusername with the database user
  2. Replace dbpassword with the password of the user database
  3. Replace dbname with the name of the database you need to backup
  4. Replace path-to-store-the-backup-file with the file path in your host, where you want to save the backup.

Note: In some servers, you may need to put single quotation marks for dbpassword so that it works. For example:

mysqldump --opt -Q -u dbusername --password = 'dbpassword' dbname |gzip > /path-to-store-the-backup-file/db_backup.sql.gz

Email database for yourself

Storing the database on the server can take up a lot of your space. You can save this space by sending a backup file to your own email.

1. Download php script here .

2 . Extract the .zip file and download it and open the backup.php file with a text editor.

3. Change the details in the database:

$ dbhost = "localhost";// usually localhost
$ dbuser = "dbuser"; // enter your username database here
$ dbpass = "dbpass"; // enter your database password here
$ dbname = "dbname"; // enter your database name here
$ sendto = "Send To "; // the email address to send the database to
$ sendfrom = "Send From ";
$ submitubject = "Daily Database Backup"; // the subject of the email
$ bodyofemail = "Here is the daily backup of my database.";

4. Save the file and upload the entire folder to your server. Note: This folder includes a .htaccess file to prevent any access from the browser. If you want to access it from your browser, you can remove the .htaccess file .

5. In the session of the Cron job in cPanel, enter the following command:

php -q /path-to-the-php-script-folder/backup.php

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile