Restore website using a backup file
Backup file usually is a single archive in the ZIP, TAR or GZ format. You can extract archives in those formats using WinRar on our PC.
Backup contains all necessary data for website restoration - database dump in SQL format, scripts and styles (PHP, JS and CSS files) and uploaded resources (images, videos, etc.). There are two common types of backups (cPanel and CMS).
CPanel backup contains all data for virtual host. In this case you should find a DB dump (file in SQL format) in one of the folders like (mysql_data, db_dump, etc.). Scripts, styles and resources located in public_html folder.
In case of CMS backups, DB dump is usually in the root folder. There also should be scripts, styles and resources. Scripts may be in a folder (e.g. "decroot").
Process of restoring
Check compatibility (optional)
First of all, we need to be sure that the server where we want to restore is compatible with website DB and scripts. Usually we need to compare MySQL and PHP versions.
In the most of cases DB dumps contain information about MySQL version. We can open the SQL file with Notepad++ or other text editor and find commented lines on the top of the file (something like "MySQL Version: 5.5.54"). If the first number(s) are coincide with server's MySQL version, everything is fine.
In case of PHP comparison may be complicated. The backup may contain a manifest or ReadMe file, where should be information about PHP version or system requirements with minimal required version of PHP.
If there are disparities with versions, please contact with your hosting provider and ask to install the required version of PHP or MySQL.
Importing database
The most of hosting providers allow creation of multiple databases. It's а best practice to have a separate DB for each website. So, we need to create a new DB.
In the cPanel there is a database management tool, where you can create a new database and assign a MySQL user with all privileges to it. Please keep the MySQL user credentials for the next step.
If you use MySQL with command line, you should log on as a root user:
mysql -u root -p
then type root's password.
Then create a new DB and MySQL user for the website:
CREATE DATABASE db_name;
GRANT ALL ON db_name.* TO 'user_name' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
Replace "db_name" with your database name; "user_name" - database user name; "password" - database password.
Notice: You can use the same values from CMS config file and pass over next step ("Change MySQL configuration").
Now, we need to import the SQL dump to new DB.
In case of cPanel, we should open phpMyAdmin tool, log in with MySQL credentials (optional) and select newly created DB. Then you should choose "Import" tab and upload a SQL dump.
In case of command line access, you should upload a SQL file to a server via sFTP and import with the following command:
mysql -u user_name -p"password" db_name < path_to_sql_file.
Replace "db_name" with your database name; "user_name" - database user name; "password" - database password; path_to_sql_file - full path to SQL file.
Changing MySQL configuration
Every CMS has a config file which contains the MySQL user configuration. You can find the config file location in CMS document. For example: for WordPress it's a "wp-config. php" in the root folder; for Drupal - "/sites/default/settings.php"...
You should open config file, find MySQL settings part and change db_name, db_name and password settings (set MySQL credentials from previous step).
Uploading scripts and resources
You should open the folder of scripts (where you extracted a backup, it can be "docroot"; in case of cPanel backup it's "public_html"), delete SQL file (if there is), select all files and archive it in ZIP, TAR or GZ formats.
Then upload archive into a corresponding folder of your hosting (usually it's public_html) and extract it. Don't forget to delete the archive after extraction.
Notice: If you're restoring website under other domain name additional configuration may be needed.
That's it. If you've done everything correct, the website should work.