Create a backup schedule for Database with Cron Job

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.

Create a backup schedule for Database with Cron Job Picture 1

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

4.2 ★ | 5 Vote

May be interested

  • Image resizing utility on zero-day WordPress errorPhoto of Image resizing utility on zero-day WordPress error
    hackers are exploiting the error of the image resizing utility timthumb, which is widely used in wordpress blogging platform. some fixes have been included in the latest version of timthumb.
  • Successful lesson from TumblrPhoto of Successful lesson from Tumblr
    community sharing is an invincible power if you make it the easiest thing possible. tumblr micro-blogging service tumblr has just received a $ 85 million financial investment ...
  • Set up copyright in WordPressPhoto of Set up copyright in WordPress
    in the previous tutorial, we introduced you to several steps to validate copyright in each article with google, but what if you want to do the same in wordpress?
  • Instructions for creating a Wordpress blog pagePhoto of Instructions for creating a Wordpress blog page
    when it was first released, the blog quickly became a popular word and one thing was certain: the internet was like a podium and millions of people built their voices through blogs - a short word of 'web log'. .
  • Assign SSL security mechanism to WordPress blogPhoto of Assign SSL security mechanism to WordPress blog
    one of the most important issues when we operate, work or play on the internet is security. whether you are at home, work, library or public access point, the surroundings are always full of disasters from malware, keylogger programs, hackers ...
  • 11 security tips for WordPress blogsPhoto of 11 security tips for WordPress blogs
    in terms of technical nature, the need to do immediately after configuration, setting up wordpress blog is to ensure the level of security and security needed. in the following article, we will introduce you to 11 basic tips that can be applied in many situations to accomplish this ...