WordPress database backup and restore – 4 ways
WordPress database backup and restore will be the main topic of discussion in this article. Generally speaking, the website developers could use a variety of SQL platforms but today we assume that you use Mysql. Practically the same instructions can be applied when using MariaDB.
Before diving into details and provide practical examples I would like to start with a couple of more general questions. What is WordPress database backup and what should we care about it.
As a database-driven application WordPress requires a database. This is not only the place where all usernames and passwords are stored. The application also keeps its important settings there. The list includes pages, posts, tags, comments, theme and plugins options, and so on.
When certain information is needed WordPress executes a query and retrieves the necessary details from its database.
As to why a reliable backup is needed I would say it may save the day. Not well-protected websites often got hacked which leads to data loss, broken websites, or stolen personal details.
WordPress database backup is usually a single file. It contains all the necessary information to resume the normal functionality of a website. This explains the importance of maintaining up-to-date backups.
In this article, I would like to present 4 different options to take a database backup. It can also be used to restore in case of an emergency situation.
Backup WordPress database using a plugin
Logically when thinking of adding a new feature to an existing website the first thing that comes to mind is installing a plugin. Though there are a number of plugins that support database backup features I personally prefer Updraft.
The plugin has a number of great features such as files and database backup, scheduled events, clone options, search and replace, remote storage, and so on. There are free and paid versions that support different options. The paid one as expected unlocks more features that ease the backup process.
Generating database backups using PhpMyAdmin
This is perhaps the most traditional way to back up a database. It can be used not only with WordPress but also with any other database. As you can see on the following screenshot the graphic interface is simple. All you have to do is select the database from the left column and then click Export. For beginners, it is recommended not to modify the default settings.
Once the download completes you will have your database exported and compressed in SQL file which later can be imported in PhpMyAdmin using the import option.
The other two methods are a little more complicated as they require more knowledge and this way more advanced users might be interested.
Mysqldump to generate WordPress database backup
Once you connect your server over SSH the command you should use is:
mysqldump -u [user] -p [password] wpp_database > backup-name.sql
The required Mysql details are stored in wp-config.php file. You may open it using your favorite editor and look for:
DB_NAME – you will find the database name next to this setting
DB_USER – this is the username
DB_PASSWORD – holds the password
Advanced users familiar with grep command can use:
grep DB wp-config.php
which will print all the necessary details to run mysqldump successfully.
Depending on the specific requirements except for backing up the entire database you could also export certain tables. Here is an example:
mysqldump -u [user] -p [password] wpp_database wpp_comments wpp_users > backup-name.sql
The above example will export wpp_comments and wpp_users tables from wpp_database and store the information in a file named backup-name.sql
WordPress backups using wp-cli
wp-cli stands for WordPress command-line interface and it is used by many to optimize, automate, or speed up maintenance. Basically, its general idea is to give the option to do anything without using the admin panel. For example, you can install and update themes and plugins, execute queries, set crons, generate backups, and many other things.
This tool simplifies the database backup process. The command you need is:
wp db export my-backup.sql
Wp-cli automatically detects all the necessary MySQL details and applies them to the command. Other options I often use:
wp db import backup.sql
wp db optimize
wp db repair
wp db check
It is important to note that wp-cli is not pre-installed by default. Detailed instructions on how to download and install it can be found here.
Some other thoughts in the end:
Backing up the WordPress database is important. As indicated this is the place where most of the important information is stored and a damaged or broken database may turn down the entire website.
Working on such problems is quite difficult as retrieving the information might be impossible. Here are a few well-known practices regarding maintaining backups:
- Always use offsite storage. Those could be remote servers or backup drives that you attach from time to time
- Try and keep at least 3 backup copies. Sometimes even the backups are broken.
- Backup your WordPress database regularly. Depending on the volume of the information you add this could vary from once per day to once per week.
- Encrypt your backups if that is an available option.
In addition, the WordPress database is also a subject of automation. If you are interested, please check the following article on the matter WordPress database management automation
|Рязане и пробиване на бетон||Сканиране на бетон||Безвзривно разрушаване на бетон|