Anyone who has had their website hacked or inadvertently changed something they should not have on their websites database, will know the importance of backing up your live websites on a regular basis. The steps involved in backing up and restoring a WordPress database using PHPMyAdmin is no different from any other MySQL powered website.
There are alternatives to manually backing up and restoring your database in this way. In this article we will be showing you how you can backup and restore your WordPress database using the built-in import and export tool, using PHPMyAdmin, using CPanel and using a host of WordPress plugins and services.
If your chosen method of backup only backs up your websites database, your site could still be somewhat vulnerable. It is advisable to backup your website files manually as well so that you have a backup of uploaded files such as images, videos etc and any non-WordPress related files that are important (there are solutions for backing up files only).
WordPress is modular but yet very coherent in nature and doing a full backup is not difficult when you know what that you need to backup.
WordPress site consists of several components:
- WordPress code (which you can always get from WordPress.org – or you can use Fantastico/CPanel WP installation)
- wp-config.php (this file holds your database connection information, it is automatically created if you use Fantastico)
- .htaccess (in most cases you can regenerate it from WordPress admin)
- wp-content folder (contains your images, attachments, themes and plugins)
- Database (contains WordPress settings and posts)
Basically since you can always get WordPress code you just need to backup remaining four things.
You can even live without wp-config.php if you have the database backup, as you can always make new database and create new wp-config.php.
Theoretically you could live without wp-content backup too, as you can install the plugins and theme again and re-upload your photos if you still have them. So that means that your database is the most important part of your WordPress installation and we will start with backing it up first.
[highlight color=”red, black”]Backing Up And Restoring Content Using WordPress[/highlight]
WordPress has a built in import (restore) and export (backup) system for transferring content from one location to another. It backs up posts, pages, comments, custom fields, categories, and tags. Unfortunately, things like attachment files aren’t backed up.
The export function can be found at http://www.yoursite.com/wp-admin/export.php. You will have the option of backing up all content or just posts or pages here. You also have the option of backing up any additional custom post formats you have installed e.g. forums, coupons, job-listings etc (quite a large percentage of good WordPress plugins use custom post formats to store data so you may have custom post formats and not even know it). The data is exported in XML format.
To restore your content, either on the same website or a different location, you need to use the import function. This can be found at http://www.yoursite.com/wp-admin/import.php.
WordPress lets you import content from a number of different blogging platforms such as Blogger and Live Journal and WordPress related products such as bbPress too.
There is a good chance that you don’t have the WordPress importer installed on your website so you will probably have to install it (should only take a few seconds).
The import function is very straight forward. All you have to do is upload your exported XML file and click on the ‘Upload file and import’ button. This screen also highlights one of the limitations of the WordPress export and import functions; the file size limit of 2mb. Thankfully, there are steps you can take to increase this limit so that you can upload your file correctly.
After you have uploaded your backed up database you will have the option of assigning posts to an existing user or creating a brand new account for those posts. This is a useful feature when merging the content from two blogs or websites together.
In this screen you can also import file attachments. The backup file you exported earlier saves the location of all of your uploaded files so if the site you backed up is still live on the internet you have the option of importing these attachments to the new location. This is handy if you are moving servers but it isn’t a practical solution for importing attachments from a backed up file if the old website is no longer live.
Finally, WordPress shows you a list of the entries that were imported onto your new website. If the content already exists, it won’t be transferred to your new site, therefore you don’t have to worry about ending up with two copies of your posts or pages if you accidentally upload the file again.
The WordPress import and export function is a user friendly method of backing up, that WordPress beginners are sure to find useful.
Backing Up And Restoring Your Files And Database Via cPanel
One of the most popular hosting platforms used online is cPanel. You should see an icon for backups on your cPanel home page (it’s exact location depends on the version of cPanel you are using and the theme your host has chosen).
To download a database you simply go to ‘Download a MySQL Database Backup’ and choose the database you want to backup. The file will be downloaded as a *.gz file. You can restore your database from this area too (you just need to upload your *.gz file).
You can also download and restore a home directory backup from this area (again, a *.gz file is used). This will backup all of your website files including your core WordPress files, uploads, plugins, themes and non-WordPress related files.
It’s a quick and easy method of transferring WordPress files and the WordPress database from one location to another. Though you do need cPanel to be installed on both locations (or at least be using a hosting platform that supports this type of importing).
Backing Up Your Database Via PHPMyAdmin
PHPMyAdmin is the most common way of administrating MySQL databases. You can access PhpMyAdmin directly through your hosting area (e.g. cPanel) though a great way to backup or modify your database through PhpMyAdmin is by installing the Portable phpMyAdmin plugin which allows you to use the tool through your WordPress admin area.
Once you are logged into PHPMyAdmin, you need to choose the database you want to backup, from the top left hand side (check your WordPress wp-config.php file if you are not 100% sure which one it is).
You then need to click on the export tab, which can be found in the navigation menu at the top. Some versions of PHPMyAdmin have a quick backup option that simply asks which format you want to back your database up in. It’s generally best to backup with the options like they are shown below.
Advanced options are usually available. The most important thing is to make sure that all of the database tables are selected before you click to backup (otherwise you run the risk of backing up one table rather than your whole database). You should also make sure that you click the option which says that it will ‘create a table if it does not exist’ (usually separated into two options to be checked). By default, the correct settings are usually selected but it’s important to make sure before you move to the next step.
Lastly, you may be asked how you want to compress your database. You can select none, zipped, gzipped and bzipped. It doesn’t matter much what you choose as PHPMyAdmin can unzip all of these formats when importing.
The steps for importing a database are very similar. Again, you need to login to PHPMyAdmin and make sure you choose the correct database. Then you need to click on the import tab at the top of the page.
All you need to do now is upload your exported file and click on the go button, ensuring that you chose SQL as your format.
When Moving Your WordPress Website
If you are moving your WordPress website to a new server all you have to do is:
Backup your files and upload them to the new host.
Export your database and import it to your new host.
Ensure that your wp-config.php has the correct login information so that WordPress can access the database.
If your website is changing URL’s you have to make sure that your database has the correct information or WordPress will keep forwarding your website to the old URL.
The smartest way to do this is to change your WordPress address (URL) and Site address (URL) to your new URL before backing up (you do this at http://www.yoursite.com/wp-admin/options-general.php). For example, you would login to your site at http://www.yoursite.com/wp-admin/, change both URLs from http://www.yoursite.com/ to http://www.mynewsite.com and then start the backup process.
If you fail to take these steps, don’t worry. All you have to do is login to PHPMyAdmin and look for the wp_options table and click browse.
You should now see your site address (URL) in the first row. The option_name is siteurl. You simply need to click on the edit link and update this from your old URL to your new one.
The home address (URL), which is the first URL you see at http://www.yoursite.com/wp-admin/options-general.php, can be found on row 39 under option_name home. Simply click the edit link and then update the entry with your new URL. This whole process is relatively painless though it is much easier if you simply update the URLs on your old website before you back up.