Tutorials

Restoring a website from a backup

Step-by-step guide to restoring your website backup from files to database; post-restoration health checks, troubleshooting common errors, and security tips you should know.

Tutorials

Why Is Restoring a Backup Usually Harder Than Taking One?

Most website administrators take backups seriously; but when it comes to restoring a backup, that's when the problems begin. You upload the files, import the database, but the site throws an error. This article is written precisely for that moment: when you need to restore a site from a backup and don't want to get stuck halfway.

In this guide, we assume you're working with cPanel or DirectAdmin, and your backup consists of two main parts: website files (including PHP code, images, themes, and plugins) and database export (SQL file). The order matters: first files, then database, and finally health checks. If you don't follow this order, your site might remain half-broken.

Step One: Preparation Before Restoring the Backup

Before anything else, do a quick check to avoid disaster:

  • Check hosting space: In cPanel, open the Disk Usage section and make sure you have at least twice the backup size in free space. If the backup is 2 GB, you need at least 4 GB of space.
  • Note the PHP version: If the backup is old and your site ran on PHP 7.4, now that PHP 8.2 is active on the server, old code might throw errors. In cPanel, check the Select PHP Version section.
  • Take a fresh backup of the current state: Even if your site is currently broken, still make a copy of the current files and database before restoring. You might need a specific file later.

Required Tools

You'll need these tools to restore the backup:

  • An FTP/SFTP client like FileZilla for uploading files
  • Access to phpMyAdmin (in cPanel) or a similar tool
  • SSH access (optional, but recommended for large sites)

Step Two: Restoring Website Files

This step is the simplest part, but it has common mistakes. If your backup is a compressed file like site-backup.zip, you have two options:

Method One: Upload and Extract on the Host

  1. Upload the compressed file via FileZilla to the public_html folder (or www in DirectAdmin).
  2. In cPanel, go to File Manager and select the file.
  3. Right-click the file and choose the Extract option.
  4. Set the extraction path to /public_html and click Extract.

If the backup size is over 500 MB, extraction via File Manager might time out. In that case, use SSH:

cd /home/username/public_html
unzip site-backup.zip

If your file is .tar.gz:

tar -xzvf site-backup.tar.gz

Method Two: Full Restore from cPanel Backup

If your backup was taken through cPanel itself (files with .tar.gz extension in the backup folder), you can go to the Backup section in cPanel and select the Restore a Home Directory Backup option. This method restores all files to their original location.

Common mistake: Many users upload files into a nested folder. For example, after extraction, files end up in public_html/site-backup/ instead of public_html itself. Result: your site comes up at example.com/site-backup. After extraction, always verify that the index.php or wp-config.php file is directly in public_html.

Step Three: Restoring the Database

After files, it's time for the database. This is the most sensitive part of backup restoration, because a small mistake can destroy all data.

Creating a New Database

If the previous database was deleted or its name changed, first create a new database:

  1. In cPanel, go to MySQL Databases.
  2. Create a new database with a desired name (e.g., mydb_backup).
  3. Create a new user and grant all privileges (ALL PRIVILEGES) to it.
  4. Note down the database name, user, and password; you'll need them later in the site's config file.

Importing the SQL File

Now import the .sql file:

  1. Log into phpMyAdmin.
  2. Select the new database from the left menu.
  3. Click on the Import tab.
  4. Choose the SQL file and click the Go button.

If the SQL file is large (over 50 MB), phpMyAdmin usually throws a timeout error. Solution: import the file via SSH:

mysql -u username -p mydb_backup < /home/username/backup.sql

If the file is compressed, first decompress it:

gunzip backup.sql.gz
mysql -u username -p mydb_backup < backup.sql

Updating the Config File

After importing, you need to update the database connection information in the site's config file:

  • WordPress: Edit the wp-config.php file and replace the DB_NAME, DB_USER, and DB_PASSWORD values with the new information.
  • Laravel: Edit the .env file and change the DB_DATABASE, DB_USERNAME, and DB_PASSWORD values.
  • Joomla: Edit the configuration.php file.
Common mistake: If the previous database still exists and you import the new SQL file onto it, you might get a Table already exists error. Solution: Before importing, drop all previous tables. In phpMyAdmin, select the database, go to the Operations tab, and choose the Drop all tables option. Or via SSH:
mysql -u username -p -e "DROP DATABASE mydb_backup; CREATE DATABASE mydb_backup;"

Step Four: Post-Restoration Health Check

After restoring the backup, open the site. If you see an error, don't panic. These are the most common issues and their solutions:

Checking Files and Permissions

The first thing to do is check file permissions. The correct permission for directories is 755 and for files is 644. If the site gives a Permission denied error, run this command via SSH:

find /home/username/public_html -type d -exec chmod 755 {} \;
find /home/username/public_html -type f -exec chmod 644 {} \;

Checking Database Connection

If you see an Error establishing a database connection error, it means the database information in the config file is wrong. Check three things:

  1. Is the database name exactly what you created in cPanel? (It usually starts with the username_ prefix)
  2. Are the username and password correct?
  3. Is the database host localhost or a different address?

Checking Links and Site URL

If the site loads but images and links are broken, the issue is the site URL. In WordPress, do this via phpMyAdmin:

UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value = 'https://example.com' WHERE option_name = 'home';

If your site doesn't use WordPress, you might need to rewrite the .htaccess file. In cPanel, go to File Manager, open the .htaccess file, and make sure its content matches the backup version.

Checking PHP Errors

If you see a white screen (White Screen of Death), enable PHP errors. In the wp-config.php file (for WordPress), add this line:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

Then check the wp-content/debug.log file. The most common error after backup restoration is PHP version incompatibility. If you see errors related to old functions, revert the PHP version in cPanel to the one the site was running on.

Additional Tips for Successful Restoration

Restoring Large Sites

If your site is over 5 GB, restoring via FTP is time-consuming. The best way is to use SSH and the rsync tool:

rsync -avz --progress /home/backup/site/ /home/username/public_html/

This method is faster, and if the connection drops, you can run the same command again to continue from where it left off.

Restoring Databases with Specialized Tools

For very large databases (over 1 GB), use the BigDump tool. Upload this PHP script to your site's folder and import the SQL file through the browser. This is the best option for shared hosting that doesn't have SSH.

Summary

Restoring a backup isn't complicated if done in the right order. Summary of steps:

  1. Check space and PHP version.
  2. Restore files in public_html.
  3. Create a new database and import the SQL file.
  4. Update the config file with the new database information.
  5. Check permissions, links, and PHP errors.

If you follow these steps in order, in 90% of cases your site will come up without issues. For the remaining 10%, check the error logs and make sure the PHP version and plugins are compatible with your backup. If your hosting supports an automated backup management tool (many Iranian hosting services offer this feature), definitely use it so that in emergencies, backup restoration can be done in a few clicks.

ServerNet Support

ServerNet engineering & editorial team — specialists in infrastructure, networking and web hosting.

WordPress Hosting
Share:

Comments 0

No comments yet — be the first!

Leave a comment

Related service

WordPress Hosting

A purpose-built WordPress stack on LiteSpeed Enterprise and NVMe — auto-install, secure updates, staging and caching that keeps you on top of Google.