WordPress backup is a task that is frequently ignored when maintaining a WordPress. Any blogger and WordPress administrator should backup WordPress frequently to ensure that WordPress can be restored and recovered in the shortest time possible in case of a failure, or in case it is hacked. The sooner you can recover your WordPress blogs and websites, the less downtime your business will experience.
In this article I will explain the basics of a WordPress installation setup, which is important to understand if you want to make a manual WordPress backup. If you are looking for a fully automated WordPress backup solution, we recommend you the WordPress backup plugin Backup Buddy.
The basics of a WordPress Installation – How it works
WordPress is a simple database driven PHP web application. Therefore for a complete WordPress backup you need to;
- Backup the WordPress blog and website files which contain the WordPress web application files, WordPress theme files, plugins files and your uploaded content. Typically all these files are found in the root of your website.
- Backup the WordPress MySQL database where the content, user information, passwords and privileges, website settings, theme settings, WordPress plugins settings and other similar data is stored. If you are not sure what is your WordPress database name, you can find it in the wp-config.php file, in the root of your WordPress.
Backup WordPress, themes, plugins and uploads
Unless you have any customizations, you only need to backup the wp-config.php file from the WordPress’ root directory and the wp-content directory.
WordPress wp-config.php File
The WordPress wp-config.php file includes the database connection details and other configurable parameters, such as the WordPress security keys, debug options and more. As such you can live without backup up this file because you can always retrieve the database connection details from other sources, but it is easier and safer to back it up.
WordPress Plugins, Themes and Uploads
All the WordPress plugins and theme you have installed, and all the files you uploaded to WordPress such as images and videos are stored in the /wp-content/ sub directory. The plugins are stored in the /wp-content/plugins/ directory, the themes in the /wp-content/themes/ and your uploads in the /wp-content/uploads/ directory.
Complete WordPress Backup and Customizations
As explained in the above paragraphs, by backing up your WordPress wp-config.php file and wp-content sub directory you have a complete WordPress backup. The rest of the files are WordPress core files which can always be downloaded from the WordPress website.
Though if you have customizations or static pages do not forget to back them up as well unless you uploaded them to the wp-content sub directory. To play it safe, and if you are not sure I would recommend you to backup all the files in the root of your website.
To backup all these files you can use the Backup option from your hosting provider CPanel. Alternatively, you can access your website using an FTP client and download all the files to your computer or to an online safe storage. Remember that backup files should always be stored on a separate media.
WordPress Database backup
A standard WordPress database contains 11 tables, all of which are listed below:
As you can notice, all of the tables in the WordPress database start with the wp_ prefix. The prefix of the WordPress database can be changed to improve security. To change the prefix, refer to Change the WordPress Database Prefix.
Does your WordPress database contain more tables? Do not worry. Some plugins and themes store data in the WordPress database by creating their own tables, hence it is normal to have additional tables in your WordPress database.
Backup your WordPress database from CPanel
- Login to your hosting provider CPanel and click on the Backup icon in the Files section.
- Once in the backup options page, click on the WordPress database name listed under the section ‘Download a MySQL Database backup’.
- Once you click on the WordPress database name, a compressed SQL script file is automatically downloaded to your computer.
Store the WordPress database file in a secure place, ideally on a different media.
Backup WordPress database using MySQL command line
If you host your own web server and have access to it via SSH or other protocol, you can make a database backup using a standard MySQL tool called mysqldump. As the name implies, the mysqldump tool dumps a MySQL database into a text file which can later be used to restore the WordPress database.
In the below example, I am using the MySQL root user to connect to the MySQL server, select the WordPress database called wpdatabase and export it to a text file called wpdb_backup.sql.
Mysqldump –u root –p wpdatabase > wpdb_backup.sql
Below is a breakdown of the switches and parameters used in the above command:
-u is used to specify the username to connect to the MySQL server. In the above example we are using the root account.
-p is used to specify the password of the account you are using to connect to the MySQL database server. You can specify the password in the command line, but if you do not, like in the above example you will be prompted to specify the password once you issue the command. For security reasons it is better not to specify the password via command line since it will be stored in the command line history.
wpdatabase is the WordPress database name.
> This sign means export. It is used to specify where to export the MySQL server database dump.
Wpdb_backup.sql is the name of the file where the database dump will be stored. If the file does not exist it will be automatically generated by the tool. Once the database is dumped into this file, download it to your computer and store it in a secure location, ideally on a separate media.
Backup WordPress database using phpMyAdmin
phpMyAdmin, a MySQL Server admin web based tool can be accessed directly via a specific URL or else from your hosting provider’s CPanel, under the Databases section. To backup the WordPress database from the phpMyAdmin follow the below procedure:
- Once logged in to phpMyAdmin, select the WordPress database by clicking on it.
- Once you click on the database name you can see the list of tables the database contains. Click on Export, highlighted in the below screenshot to export/backup the WordPress database to a file.
- From the Export options page, select Custom Export and ensure that:
- All tables are highlighted, as seen in the below screenshot
- The option Add Drop…. from the Object Creation options is enabled. This is useful for when you are restoring the WordPress database onto an existing one.
Useful Tips for Storing your WordPress Backup
The WordPress backup files contain sensitive data, such as the WordPress database connection details, the list of WordPress users and much more. Such files should be stored in a secure location where other users do not have access to. You can also compress the WordPress backups into a password protected zip file or store it on an encrypted drive, so you ensure the content of the files cannot be read in case someone manages to gain access to them.
You should also keep multiple copies of your WordPress backups and save them on different media and locations, such as an external drives, USB sticks, online drives/locations etc. By storing the backups in multiple locations you ensure the backup’s integrity even if your computer breaks down or is infected with malware.