Before I tell you how to backup and restore WordPress, it is necessary that you learn why you need to backup your WordPress site from time to time.
You know what? There is no shortage of online threats. There are hackers who want to hack your website. There are possibilities of malware injection. Some people will simply try to hack your site or launch a DDoS or DoS attack on your site out of sheer fun.
You truly don’t need to have a very popular site to become a victim of such malicious actors.
If you have a WordPress site, or any site for that matter, you are vulnerable even with most sophisticated of the threat detection and prevention mechanism in place.
When security becomes smart, malicious players come up with smarter methods to infiltrate. The cycle is never-ending, which means, you are never truly safe.
You can deploy countermeasures, but you cannot be sure that they will protect you always.
There is no guarantee!
This lack of guarantee and the ever-present looming threat is what calls for backing up your website.
This is what I prefer calling, the last line of defence.
Yes, having a backup of your website and its database will ensure that even if your website is hacked and or deleted, or infected with a malware, you will have a copy of your website that will help you restore it back quickly.
After all, you shouldn’t be lying there doing nothing and see your weeks, months or perhaps years of work flushing down the drain.
So, deploy the last countermeasure! BACKUP your WordPress site. Do that frequently!
Just how frequently?
Umm… I will say everyday or every night after you finish publishing a new post. That way, in the event of a mishap, you will always have the freshest possible copy of your website. In the worst-case scenario, you will lose a day’s work. That’s better than losing the whole website.
This is precisely why many managed WordPress hosting providers offer daily or nightly backups.
But that such automatic backups are not available with most of the shared hosting providers. With cloud hosting, you may decide to enable backups, but mostly they will be weekly backups. So, it is wise that you take manual backups frequently.
So, how to backup and restore WordPress?
Let’s find out…
Method 1: Use a Plugin – the Easy Way
Perhaps, one of the easiest ways of backing up WordPress is to use a backup plugin. For a WordPress site to work there must be two components – the website files and folders and the database.
A well-designed plugin will backup both the WordPress files and folder, and the database. It will also allow quick restoration of the backups with a single click.
Perhaps the most popular backup plugin is UpdraftPlus. With well over 3 million active installs, UpdraftPlus is, by far, one of the most trusted backup plugins you can lay your hands on.
The plugin is free to use, but you may opt to buy their premium version if you want. The free version is good enough to fulfill your needs.
The whole setup process of UpdraftPlus is simple. Once you set it up, the plugin will allow you to backup your website into the cloud. There are multiple options to select from. The various cloud options that you will find include:
- UpdraftPlus Vault
- Google Drive
- Amazon S3
- S3 Compatible storage (such as DigitalOcean Spaces, Linode Object Storage, Nifty, Eucalyptus, etc.)
- Google Cloud
- OpenStack (Swift)
- Microsoft Azure
- Rackspace Cloud Files
- Microsoft OneDrive
In is not necessary to save the files on any cloud storage. You can leave the backups on your server and later download them directly to your desktop or laptop. However, it is not really recommended to keep the backup files on your server because of two reasons:
- Backup files can eat up valuable storage space.
- If you lose access to your server, you will lose your website and the backups.
So, even if you decide to keep the backups on your server, make sure that you are at least downloading them to your computer.
Once you install the UpdraftPlus plugin on your site from the plugins segment of your dashboard, you can visit the setting page of UpdraftPlus and head over to the ‘Settings’ tab before touching anything else.
This is where you need to configure the plugin the way you want it to work.
This is where you can (and you should) schedule the backups. Ideally, it should be a ‘daily’ backup for both files and database. You can also set how many backup copies you want to retain.
You can move forward and decide on the cloud storage you want to use. If you don’t want to use cloud storage, that’s fine.
You can also decide what to backup and what not to backup. The default selections are just perfect.
Note: You may not see ‘snapshots’ in the exclude list because that something that comes from my hosting provider (DigitalOcean).
Rest of the default settings are just fine. You can go ahead and save the plugin settings. Once you have saved the settings, you can head over to the first tab which reads Backup / Restore and click on the Backup Now button to run a manual backup.
Alternatively, if you have created scheduled backup settings, you can wait for the backups to run automatically.
Once you hit the Backup Now button without setting a cloud storage option, you will see a notification which says what to include and that the backup will not be sent to a cloud storage.
This is what you will see:
Once you have checked whatever you want to check in the popup notification, you can hit the Backup Now button.
After UpdraftPlus creates a backup, you will see a notification popup stating that the backup has been created. The popup will go by itself and you will see this:
You can see a few buttons which read – Database, Plugins, Themes, Uploads, Others.
Clicking on these buttons will download those specific backups to your local drive.
You can also see other buttons that read Restore, Delete, and View Log. By clicking on the Restore button you can restore the entire backup to revive the site. Clicking the Delete button will remove the backup zip from the server. The View Log file will show you all the actions taken by UpdraftPlus. You can download the log file if you want to debug any issue.
Once you click on the buttons provided for downloading the backups, you will see this option:
For every option you will the option to download that part of the backup to your computer or delete it from the server.
If you click on the Restore button, you will see the following options on your screen:
You can decide what to restore and what not to restore. Once you select the options and click on the next button, the plugin will process all the files and prepare them for restoration. You will see the following screen:
You can now click on the restore button to restore your website! That’s all! The process is simple and effective.
If you downloaded the backup files to your local computer for restoring them later, you can upload the files from the plugin interface. The upload option is available in the first tab of the plugin (that is, Backup / Restore):
Once you upload the files, you can move forward with onscreen instructions to complete the backup restoration process.
If you want more advanced features, you can purchase the UpdraftPlus Premium plugin that will give you access to the following:
- Ability to clone or migrate your site.
- Incremental backups (will backup only the files that have changed) since the last backup was taken.
- Will automatically backup your website before updating themes, plugins, or WordPress core.
- You can backup non-WordPress files and databases.
- You can schedule backups to happen at specific times.
- You will have Command Line access.
- Encrypt sensitive databases.
- Import backups from other plugins.
- Lock UpdraftPlus settings area with a password so that no one else can use it.
- Get access to UpdraftVault Storage to store, manage, and download all your backups from one centralized location.
First thing first, BackupBuddy is a premium plugin. There is no free version available for this plugin. If you want a free alternative, you can look at a plugin named Duplicator that works exactly the same way, but there are certain limitations.
However, if you purchase BackupBuddy, you are in for a real treat! The plugin simple and easy to use.
Here is the modus operandi of using BackupBuddy:
Step 1: Purchase, Download, and Install the plugin to your WordPress site.
Step 2: From WordPress dashboard, go to BackupBuddy >> Restore/Migrate.
Step 3: Click on the button which reads ‘Download importbuddy.php.’ This will download a php file to your local computer. You will have to set a password for importbuddy. Make sure that you keep a proper note or remember the password. You will need it later.
Step 4: Now, go to BackupBuddy >> Backups and create a full site backup or just backup your database. I will recommend you go for a full site backup. Once the backup is created, you will get the option of downloading the backup to your local computer or move it to a remote destination.
Unlike UpdraftPlus, the number of offsite locations you get is quite limited. BackupBuddy will provide you what they call BackupBuddy Stash – a secure offline location for storing backups.
Step 5: Once you have backup of everything, connect to your website server using FTP to delete all files from the root folder. If you have cPanel, you can use the File Manager and delete everything you see there.
Step 6: Once you have deleted the files, upload the importbuddy.php and the backup file (zip file) to the root folder of your server. You can use either the FTP client or the File Manager. In case you don’t have cPanel, FTP will be the best option.
Step 7: After you have uploaded the two files, type in the domain name followed by the importbuddy.php in the following format:
Replace example.com with the actual domain name. Once you have typed in the URL, hit the enter key on your keyboard. You will see this:
This is where you need to enter the password that you created while downloading importbuddy.php.
Once you enter the password and hit the Authenticate button, you will see a screen with the details of the backup file you uploaded. In case you skipped uploading the backup file earlier, you can upload it now.
You can select what to restore. You can restore only the files or only the database or both. After you have selected what you want to restore, click on the Restore Backup button. The backup restoration process will start.
This is where BackupBuddy will extract the files and ask you to database details
This is where things can become a bit messy. You may be restoring your site after a hack or a malware injection episode. This will require you to either drop the tables of the existing database or create an entirely new database. Using the old database will bring back the issues.
So ideally, you should have a new database. If you are creating a new database, make sure that you are keeping the database name, database user, and database password safe. You will need them all.
You can create a new database from cPanel
In case you know your website is not infected by a malware or it has not been hacked, you can use the old database details.
On the screen where BackupBuddy asks you to provide database details, you will see this screen:
In the New Database fields, you can enter the details of the newly created database, or if you want to use the old database details intact, you can hit the arrow icons to copy the old database details to the new database fields.
Once you have added the details, hit the Next Step button and the restoration will be completed quickly. Moving forward you will see this:
After the restoration is complete, go ahead and check the website for any errors. If you don’t see any errors, you can go ahead and click the Finish Cleanup button. This will ensure that all the temporary files and folders are removed.
That’s it! You have successfully restored your website from a backup.
What I understand after dealing with BackupBuddy is that it is not just a straightforward backup plugin, but also gives you the added functionality of moving your site from one domain to another or from one host to another.
In fact, you can achieve the same result with a free plugin called Duplicator. You can also use it to create manual backups. The free version of Duplicator is powerful enough to do everything that BackupBuddy can do except that you cannot send your backups to external locations. You need to download the backups to your local computer.
If you want, you can always go ahead and purchase the premium version of Duplicator plugin and enjoy much more features.
Method 2: Manually Backup Your Site
This is my preferred method because of two reasons:
- I don’t need to keep an extra plugin on my site just for taking backups.
- I get more granular control.
In the manual backup format, I need to download the website files and folders using FTP and then backup my site from phpMyAdmin using the export function.
Backing Up & Restoring Website Files and Folders
For this method you will need access to your FTP credentials. If you are using a shared hosting server, the hosting provider should have mailed you the FTP credentials. In case you don’t have the credentials, you can create FTP account directly from cPanel.
Assuming that you have access to your FTP credentials, open any FTP client of your choice. I prefer using FileZilla.
Once you connect to your server using FileZilla or your preferred FTP client, navigate to the directory where your website files sit. Open the directly and select everything.
On the left side, select the destination location where you want to download the files and folders. Once you have selected the destination, move to the right panel, right-click on the selected files and click on download.
Once you click on the download option, all files from the server will start transferring to the selected folder or location on your local computer.
Remember that the files that will download to your computer will not be in zip format because FileZilla doesn’t support zip. FileZilla is open-source while zip is proprietary.
You can wait till the transfer is complete, or you can minimize the FileZilla window and move on to download your database.
FileZilla will continue downloading the files even when you minimize the application window.
To restore the files and folders to your server from your computer, you need to select the remote location (server directory where you want to place the files and folders) and then navigate to the local folder where you the backup files are present.
Select all backup files and then right-click on it and then click on upload. The files from your local computer will start uploading to the remote server’s chosen directory.
Backing Up & Restoring Database
For downloading your database, you need to access phpMyAdmin. The simplest way to access it is to phpMyAdmin is to type your domain name in the URL bar and append it with /phpMyAdmin/.
This is what it should look like:
Once you have typed in the URL, hit the enter key on your keyboard and you should then be able to see the web interface of phpMyAdmin.
You need to enter the user id and password. Usually the user id is ‘admin’ (but it can also be ‘root’) and the password that your hosting provider gave you for phpMyAdmin.
In case you are on a cloud hosting server, you need to get the details by using the command line interface.
Assuming that you already have the id and password, login to the phpMyAdmin interface. This is what you will see when you login:
Select the database. Usually the database name starts with the prefix ‘wp,’ but in this example, the name is ‘wordpress.’
Once you click on the appropriate database name, you can see the tables. On the top you can see the ‘Export’ tab. Click on the tab.
On the Export tab, you can see this:
By default, the export format is set to SQL. Leave it that way and click on the Go button you see on the right.
This will download a copy of the database to your local computer.
That’s it! You have successfully downloaded a backup of your website’s database.
Now, to restore the downloaded database backup, you need to get back to phpMyAdmin and select the database where you want to import the downloaded SQL database.
If you are moving to a new server, you need to create one database and then import the backup to that database. If you are creating a new database, make sure that you are noting the database name, database username, and database password that you set during creation of the new database. You need to put the details in the wp_config.php file.
If you are not changing server, and you can just revert to an older database. Even in this case, you need to import the SQL database backup file.
To do that, navigate to the Import tab of your database in phpMyAdmin and choose the backup database from your local computer:
Once you have selected the database you want to restore, click on the Go button you see at the bottom. Make sure that you are not fiddling around with other settings. Everything is what it should be.
Once you click on Go, the database import will finish quickly. It doesn’t take a lot of time.
That’s it! You have successfully restored your database manually.
What we learned here today is backing up your WordPress files and database and restoring them.
That’s quite different from migrating your site from one server to another. Migrating follows the same rules. You need to take backups and then move them to the new server.
When you are only reverting to an older backup on the same server, you will most likely not change the database credentials that include the database name, database user, and database password. So, your website should function properly.
But when you are migrating from one server to another, or from one domain to another, or you are changing the database of an existing WordPress installation on your existing server, certain errors can show up. Some of the common errors you can encounter are:
- Error Establishing Database Connection (This mostly happens because you failed to properly update the new database credentials in wp_config.php file. Updating details correctly will eliminate the error.)
- 404 on single page or post (This usually happens because of incorrect permalink structure. Just update the permalink structure by logging into your WordPress dashboard and the issue should resolve.)
- Internal Server Error (This can be caused by many factors including incorrect permalink structure, a corrupt .htaccess file, problem with PHP memory limit, etc. There are different solutions that you can use.)
- Login Page Redirect (This too can be cause by several factors like a corrupt .htaccess file, incorrect WordPress URL settings, browser cookies, corrupted plugins, etc.)
- White Screen of Death (This can be caused by a faulty plugin, a low PHP memory limit, problem with the current theme’s functions.php file, or something else).
It is virtually impossible to give proper guides for fixing all these issues here in this single article. If you want me give you the tutorials for them, drop a comment.