Files and Database Restoration

Learn how to restore a cart from a backup.

Olga Tereshina avatar
Written by Olga Tereshina
Updated over a week ago

Generally speaking, restoring a store from a backup copy is an inverse procedure to creating a backup copy. When restoring the store, you are expected to use the same tools you used to create the backup copy. Like creating the backup, restoring does not cause any serious difficulties, but it yet requires the standard sequence of operations: restore the store files and restore the database. One of the major rules to be observed is to restore data from the backup to a newly created directory within the WWW part of your hosting account. You must keep with this rule no matter whether you copy/move the store to a new location or replace an existing installation with the backup copy. After you have restored your store from the backup, you may need to adjust some configuration settings, including the values of the variables in the main configuration file config.php, paths to images, file permissions, etc.

The instructions below generally describe how to restore X-Cart files from a backup copy. Examples and notes are provided for UNIX- and Windows-based servers. Many of the listed operations can be carried out through your server/hosting control panel (if any).

Restoring X-Cart Files from a Backup

To restore the software files from a backup:

  1. Log in to your server or your hosting account.

  2. Go to the directory that contains all your Internet projects (usually referred to as the WWW directory), and create a new directory to deploy the store from the backup. For example, on a UNIX-based server, you can create a new directory using the following shell command.

    mkdir xcart

    You can create a new directory on a Windows-based server using the graphic user interface (GUI). As a result, you should get an empty directory that is accessible through the Internet.

  3. Go to the directory you have just created and upload the X-Cart files (or the archive with X-Cart files) onto the directory using FTP, SCP, your control panel, or other suitable facilities.

  4. If you have the X-Cart files in an archive, extract them using the available utilities. For example, you can extract files from the archive on a Unix-based server using the following shell command.

    tar -xfv <archive_name>

    OR

    tar –xzvf <archive_name> # If the archive has file extension *.tar.gz, *.gz or *.zip

    OR

    tar –xjvf <archive_name> # If the archive has file extension *.tbz.

    On a Windows-based server, you can extract the archive with one of the available file archive managers for Windows, including WinRAR, WinZIP, PKZip, or 7Zip.

  5. Check the X-Cart directory. It must contain the standard X-Cart file structure. If it only contains one directory with the X-Cart files, move its content to the current directory.

  6. If necessary, edit the main X-Cart configuration file /etc/config.php:

    • Locate the file /etc/config.php and open it for editing in your favorite plain text editor.

    • Set correct values for the following variables:

      [database_details] hostspec = "localhost" socket = "" port = "" database = "database" username = "username" password = "password" table_prefix = "xc_"

      and

      [host_details] http_host = "<HOST>" https_host = "<HOST>" web_dir = "/xcart"
  7. Create a new database for the store using a database management system (DBMS) that you usually use to manage your MySQL databases. For example, on a Unix-based server, you can create a database using the following shell command:

    mysqladmin -u USER -pPASSWORD create NEWDATABASE

    The system will ask you to enter your password for the MySQL account. After the password is accepted, the system will create a new empty database for your store.

The name/address of the MySQL server, the name of the MySQL database, the username, and the password for the MySQL account must be the same as the values of the respective variables in the X-Cart configuration file /etc/config.php.

Restoring the Database from an SQL Dump

When you restore a database from an SQL dump, the existing database tables get overwritten. Therefore, we strongly recommend that you always back up the current store database before restoring data from an SQL dump, as it allows you to avoid any possible data loss. Another critical issue here is that you can restore the database only if you created the SQL dump for the same X-Cart version.

The store administrator can restore the database either through the X-Cart Admin area or manually. If you decide to carry out this task manually, ensure that you have access to the respective tools and facilities, including different client implementations of the SSH protocol like OpenSSH or PuTTY, Telnet, phpMyAdmin, MySQL console, the control panel of your hosting account, Remote Desktop client and other. In this case, the exact instructions on how to restore the database from the backup will depend on the utility you use.

Restoring the Database Using X-Cart Admin Area

To restore the database from the X-Cart Admin area:

  1. Open the “Restore database” page in your store Admin area (System Tools -> Database -> Restore database)

    541-restore-database-page.png

  2. Make sure the storefront is closed as described here.

    541-database-page-closed.png

  3. Restore the database from an SQL dump using the instructions below.

    If the SQL dump was done using the Create SQL file option, i.e., was saved as a file on the webserver (‘var/backup/sqldump.sql.php’):

    • Click the ‘Restore from server’ button.

    • Wait until the system displays a message saying that the database has been restored successfully.

    If restoring the database this way, the current database backup will be done automatically by the system.

    If the SQL dump is saved on a local computer:

    • Click the ‘Choose file’ button to display the dialog box for uploading files.

    • Select the file with the SQL dump.

    • Click the ‘Upload and Restore’ button. Then, wait until the system displays a message saying that the database has been restored successfully.

Restoring the Database Using Terminal Access

To restore the database using terminal access to the server:

  1. First, log in to your server or your hosting account.

  2. Run the following shell command.

    mysql -u USER -pPASSWORD DATABASE < /path/to/dump.sql

    The system will ask you to enter your password for the MySQL account. After the password has been accepted, the system will populate the database with the data from the SQL dump.

    The name/address of the MySQL server, the name of the MySQL database, the username, and the password for the MySQL account must be the same as the values of the respective variables in the X-Cart configuration file config.php.

Safety Tips

Remove the SQL dump and the archive from the WWW directory of your server or hosting account. It is strongly recommended not to leave an SQL dump of the store database and the packed archive with X-Cart files anywhere in the publicly accessible WWW directory of your server or hosting account. Otherwise, your store data can be easily stolen as anybody will be able to access the database dump through the Web.

A good practice here is to keep the backup on a local computer or in a directory on a remote server that cannot be accessed through the Web. For example, if the root directory of your hosting account is /u/user/ and the web directory is /u/user/public_html/, you must move the SQL dump and the store archive from the directory /u/user/public_html/ to somewhere in the directory /u/user/.

Troubleshooting

Problem

Possible cause

Solution

The system says you do not have enough privileges to write to the file.

A user who has run the PHP script is not allowed to write files to the directory.

Set writable permissions to the directory where you are trying to save the SQL dump and repeat the task.

The system says you do not have enough free disk space to complete the operation.

The file system does not have enough free disk space.

Since some data has been saved to the file before the error message, remove the file with the backup. Then either make available more free space and repeat the task or choose to save the file to another location.

The task was terminated, and the system says you will be redirected to the previous page.

The memory allocated to the script has exhausted.

Increase the amount of memory allocated to the script by increasing the default value of the $memory_limit variable in the php.ini file. If you do not have access to the php.ini file, ask your hosting team to help you. NOTE: It may be necessary to increase the allocated memory several times because it is impossible to predict how much memory you really need.

Did this answer your question?