It is very important to backup your website regularly. Many things can happen, that make it necessary to repair your website with the help of a backup. You can learn more about making backups in this post.
Something is wrong, what’s next?
At any given moment something could go wrong with your website. A code-injection, messed up configuration, a corrupted database. These things can be caused in many ways. Every problem has its own solution. It is impossible to cover all problems and solutions in this post. That is why I have chosen a few situations that may arise in practice, describing the problem and its possible solution using the backup.
Keep the backup at hand
Some web hosting companies and online backup services offer a possibility to make a full backup with just one mouse click. They also offer the possibility to restore a full backup with just one mouse click. Everything that was backed up, will be overwritten by the restore, even the good things! Sometimes you just have to restore a single file, like functions.php or .htaccess, to be back online. No matter what kind of restore you need, always be sure you have a recent, reliable backup at hand.
Restoring a part of the website
As mentioned before, it is not always necessary to do a full restore. A full restore can overwrite a lot of good work, that was done after the website was backed up. In other words: you may loose a lot of work that will be overwritten by the restore, even though this work may not have caused the problem. Quite often the problem can be solved by restoring just a file of a folder.
What is in your backup file?
Do you make backups with BackWPup? Then you know what every backup file contains. Even if you have just one backup file, you should be able to retrieve all necessary files and database(s). In this example, I assume that the backup file has been sent to Dropbox. When your Dropbox is synchronized with your personal computer, you can find the backupfile(s) there too!
After unzipping the file(s) you will have an overview similar to this one:
What do you see here? A full backup of a WordPress website, containing:
- A full copy of the WordPress installation, recognizable by the folder structure and wp-config.php
- A xml-export of WordPress, the file xxxxx.xml
- A sql-export of the database, the file xxxxx.sql
- A list of plugins, the file xxx-pluginlistxxxxx.txt
With a backup like this, you should be able te perform every kind of restore you want to solve the problem with your website.
Solving the problem
A non-functioning website has a reason. You will have to investigate the cause of the problem. Because it is impossible to mention all the problems you can encounter, I described a few examples most site owners will experience some day.
Example 1: No database connection
This error will occur from time to time:
Error establishing a database connection
This error means that there is no connection being made to the database. First place to look for the solution is wp-config.php. Are your username and password correct? Have you changed wp-config.php recently and by accident changed username and/or password for the database? If you’re not sure, you can restore wp-config.php by uploading it through ftp. You can do this with Filezilla for example.
In this example on the left side you can see the backup files, on right the “live” WordPress installation. On the left side of the screen, double-click on wp-config.php. It will be uploaded after you confim that the file will be overwritten. If you don’t want it to be overwritten, you can first rename it to wp-config.php.org and then upload the file from the backup.
Next you can check your website to see if it is working again. If it does, you’re done. You can delete wp-config.php.org. If it doesn’t then wp-config.php wasn’t the problem, your database is.
Example 2: Corrupted database
The error in first example can also be caused by a corrupt database. In that case you first have to try to repair the database with phpMyAdmin.
Log in to your cPanel or DirectAdmin and choose the option phpMyAdmin.
If you have more than one database, choose the database you want to repair. Click on the option “Structure”. Next, at the bottom of the screen, you select “Check all” to select all tables. Finally, you select the option “Repair table” under the drop-down menu “With selected:”. All tables in the databases will be checked and repaired if necessary.
Now you can try your website again. If it works, you’re done. If it doesn’t, you will have to restore the database backup.
To restore the backup of the database, you first have to drop all tables off the “live” website. Again under “Structure” you select all tables. After that, you select the option “Drop table” from the drop-down menu. All tables will be dropped. Caution: dropping the tables cannot be undone. If you are not comfortable with editing the database, please consult a specialist.
All the tables are dropped. Now you can restore the database backup. Select the tab “Import”. Under “File to import”, browse to the xxxxx.sql file in the backup folder. Leave the other settings as they are. Click on “Go” and all tables will be imported. Next, you can check your website again. The problem should be solved by now…
Example 3: Malware discovered
These days it is not unthinkable WordPress files gets infected with malware. For example a php-file gets injected with malicious code, that makes your server part of a botnet. Several plugins can protect you, but neither of them 100% guarantee safety. Finding out which file had been infected can be very difficult. Your web host can do that, but it takes time and cost you money.
The best option is to completely restore the WordPress installation. Of course you need to be sure that the backup files aren’t infected. If they are, you will have to do a new install of the WordPress installation files.
You can restore the WordPress installation files in the same way you restore wp-config.php.
In Filezilla make sure you have the same files and folders on the left and the right side of the screen. In the right side, delete the folders wp-admin, wp-content and wp-includes. Next, remove all php-files and .htaccess from the root. Essentially you delete all files and folders you can restore from your backup you can see on the left side of the screen.
After you have removed all files, you select the backup files and -folders on the left. Right-click and select “Upload” to upload the entire installation backup to your web server. The malware should be gone now. Use a plugin like Wordfence of Shield to check the WordPress installation for infected files. They should find nothing.
You should consider installing a security plugin if you haven’t done so. You can avoid most of the problems with malware, sql-injection and php-injection. This will save you a lot of time and trouble!
Example 4: Restore theme
Let’s say your theme has been updated. You noticed the update and used the automatic update functionality to install the update. Next, you go to your website and everything is wrong. As it turns out, the updated theme is a lot different from the old version. Even the child theme doesn’t work that well with the update.
This a typical moment you want to be able to fall back on a recent backup. Because before you can install the updated theme, you first have to make changes, so it works well with your website. In the meantime, you keep the old theme alive.
The same way as in example 3, you can restore just your theme from the backup. In Filezilla, choose the themes folder in wp-content on both sides. On the right side, delete the folder of the theme you are using. On the left side, choose the backup theme folder and upload it to the themes folder on your web server. You’re done!
There is a solution for every problem. With a recent backup, you can resolve a lot of problems you can have with your website. It is not always easy to detect the cause of the problem. It is possible you caused it yourself and you can undo these changes without the need of a backup. In other cases your backup is your safety net!
Restoring (parts of) a backup seems difficult. As long as you stay focused and do everything step by step, you should be able to do it. But, when in doubt, always consult a specialist or have somebody else do it for you. That may cost a little. But being able to save your content by having a recent backup, is priceless!
Do you have any experience with having to fall back on a backup? Please tell your story in the comments section below!