Difference between revisions of "X-Cart:Backup and Restore"

From X-Cart 4 Classic
Jump to: navigation, search
(Prerequisites)
(Backing up Store Database)
Line 57: Line 57:
  
 
===Backing up Store Database===
 
===Backing up Store Database===
 +
 +
With X-Cart the store administrator can back up the store database in a few easy steps directly from the Admin area. However, this way of backing up the database may be unsuitable if, for example, X-Cart utilizes third-party add-on modules and custom code: new tables introduced by these modules and code may be excluded from the SQL dump, which is generated automatically.
 +
 +
In such situations you must back up the database manually so that the dump includes all the store data. For this purpose you can use any adequate facility, including different client implementations of the SSH protocol like OpenSSH or PuTTY, Telnet, phpMyAdmin, MySQL console, control panel of your hosting account, Remote Desktop client and other. Later in this section you will find an example of how to create a database dump using terminal access (SSH or Telnet) to the server or hosting account where X-Cart is installed.
 +
 +
==== Backing up the database through X-Cart Admin area ====
 +
 +
To back up the database through the X-Cart Admin area:
 +
 +
1. Log in to the Admin area.
 +
 +
2. Go to the <u>Database Backup/Restore</u> section (<u>Administration</u> menu -> <u>DB backup/restore</u>).
 +
 +
You will see the <u>Database Backup/Restore</u> box.
 +
 +
3. In the Backup database section of the box, click the Generate SQL file button. If necessary, additionally select the '''Write SQL dump to file '<file_name>'''' check box;
 +
 +
[[Image:maintaining-02.gif|640px|center]]
 +
 +
By selecting the check box you tell X-Cart to save the SQL dump to the default file and location on the server file system (file xcartdump.sql in the directory <u><xcart_dir>/var/tmp/</u>). It is good to save the SQL dump to the server if it is going to be rather large and you want to ftp it to your local computer or another location on the server later. If you leave the check box unselected, the SQL dump will be saved onto your local computer.
 +
 +
{{Note1|Important: If you do not have access to your server/hosting account through FTP, SSH or other suitable facility, do not select the check box and save the SQL file directly to your local computer.}}
 +
 +
==== Backing up the database using terminal access ====
 +
 +
To back up the database using terminal access to the server:
 +
 +
1. Log in to your server or hosting account.
 +
 +
2. Go to the X-Cart root directory.
 +
 +
3. Run the following shell command.
 +
 +
<pre>
 +
> mysqldump -h<db_host> -u<username> -p<password> -r<backup_filename> <db_name>
 +
</pre>
 +
 +
The abbreviations in the command mean:
 +
 +
{| class="wikitable"
 +
| db_host
 +
| :: The DNS name or the IP-address of your MySQL server.
 +
|-
 +
| username
 +
| :: The username for your MySQL user account.
 +
|-
 +
| password
 +
| :: The password for your MySQL user account.
 +
|-
 +
| backup_filename
 +
| :: The name and the path to the newly created SQL file with the database dump.
 +
|-
 +
| db_name
 +
| :: The name of the MySQL database that you use for X-Cart.
 +
|}
 +
 +
After you have run the command, the system will generate an SQL file and save it to the directory that you have specified in the <backup_filename> part of the command. If you have specified the name of the file for the backup only without mentioning the path, the file will be saved be saved to the X-Cart root directory, the directory where you are currently located.
 +
 +
If necessary, you can use a different path, but it is yet recommended that it be a location within the X-Cart root directory.
  
 
===Backing up Store Files===
 
===Backing up Store Files===

Revision as of 16:12, 27 January 2010

Overview

Backup generally refers to making a copy of a store, which can then be restored fast and easily, if need be. Regular data backup will help you prevent serious data loss and corruption that can follow a disaster or mishandling of your store. The rule here is to create a full backup copy of the store at regular intervals and before carrying out any tasks that may interfere with the software code and behavior, including software and hardware upgrades, custom programming, adjusting the store design, etc. At that, you should not rely on your hosting provider only, who is likely to include regular data backup into their hosting plan: In case of emergency, data cannot always be restored immediately while any possible delay can seriously affect your business. Another typical example of when you may need to back up your store is moving/copying the store to another host or directory. In such a situation, if a backup is available, you will be able to deploy a fully functioning copy of the store in a new location quickly.

When you create a backup copy of a store you need to carry out a number of typical steps and procedures, which include making a database dumb and creating an archive with the X-Cart code, templates and related files (images, static pages, the HTML catalog, files in the folder file/, etc.). In fact, X-Cart does not impose any restrictions on what tools you use to create a backup copy of your store - you can use any convenient facility, including SSH, FTP, phpMyAdmin, Remote Desktop, utilities that go with your hosting control panel and other available facilities. The exact set may vary depending on the operating system you use.

When you restore the store from a backup copy, it is supposed that you use the same tools and facilities to carry out inverse operations: restoring the store files from the archive and restoring the database content from the MySQL dump. In case you are restoring the store to a different location, in addition to this you will need to adjust some configuration settings.

For detailed instructions on how to handle store backups and carry out specific tasks, please refer to the following sections later in this chapter:

Remember that making a backup copy of a store and restoring the store from the backup are rather complicated tasks, which may become associated with a series of difficulties or even involve unpredictable effects. This document only provides a general description of the backup and restore procedures, and it does not intend to cover all types of situations that can occur while you back up or restore your store.

If you experience any difficulties in handling your store backups and you cannot find the answer in this document, you are welcome to address the alternative sources and services.

Backing up the Store

Prerequisites

Before you start making a back up copy of your store, make sure of the following:

  • You have enough free disk space on your server or hosting account where your store is installed.
To estimate the minimal required amount of free disk space correctly, you can use the following formula: 2 kilobytes (kB) per each product in the store database + size of the folder images/ + size of the folder files/ + 50 megabytes (MB).
For example, if your store database consists of 5000 products, the size of the folder images/ is 66.7MB and the size of the folder files/ is 35.77MB, then you need (2 kB * 5000)/1024 + 66.7MB + 35.77MB + 50MB = 9.76MB + 66.7MB + 35.77MB + 50MB = 162.23MB.
Note: If you do not have enough free disk space, try to remove the files that you do not longer use or move them to another location.
  • You can access your server or hosting account using one of these options: terminal SSH or Telnet access, FTP, remote desktop (available for Windows-based servers only), your hosting control panel.
Note: If you cannot access your server or hosting account via these or other alternative options, address your hosting team for help.
  • The directory to which you are going to save the backup copy has writable permissions.
  • The Customer area of your store is temporarily closed for maintenance.

Having the Customer area closed ensures that none of your website visitors will be able to shop through your store and place orders while you are backing up your store, and the backup will include all the info that is available by the moment you start this task.

To close the store for maintenance:

1. Log in to the Admin area.

2. Go to the General settings section (Administration menu -> General settings).

3. In the General options box, select the Check this to close your shop temporarily check box. If necessary, enter a key for accessing the Customer area into the Key for access to a temporarily closed shop field.

Maintaining-01.gif

4. Click the Save button.

From here on, all your store visitors will be automatically redirected to a special page saying that the store is temporarily inaccessible and can be visited later. To open the store back, log in to the Admin area and unselect the checkbox.

Backing up Store Database

With X-Cart the store administrator can back up the store database in a few easy steps directly from the Admin area. However, this way of backing up the database may be unsuitable if, for example, X-Cart utilizes third-party add-on modules and custom code: new tables introduced by these modules and code may be excluded from the SQL dump, which is generated automatically.

In such situations you must back up the database manually so that the dump includes all the store data. For this purpose you can use any adequate facility, including different client implementations of the SSH protocol like OpenSSH or PuTTY, Telnet, phpMyAdmin, MySQL console, control panel of your hosting account, Remote Desktop client and other. Later in this section you will find an example of how to create a database dump using terminal access (SSH or Telnet) to the server or hosting account where X-Cart is installed.

Backing up the database through X-Cart Admin area

To back up the database through the X-Cart Admin area:

1. Log in to the Admin area.

2. Go to the Database Backup/Restore section (Administration menu -> DB backup/restore).

You will see the Database Backup/Restore box.

3. In the Backup database section of the box, click the Generate SQL file button. If necessary, additionally select the Write SQL dump to file '<file_name>' check box;

Maintaining-02.gif

By selecting the check box you tell X-Cart to save the SQL dump to the default file and location on the server file system (file xcartdump.sql in the directory <xcart_dir>/var/tmp/). It is good to save the SQL dump to the server if it is going to be rather large and you want to ftp it to your local computer or another location on the server later. If you leave the check box unselected, the SQL dump will be saved onto your local computer.

Important: If you do not have access to your server/hosting account through FTP, SSH or other suitable facility, do not select the check box and save the SQL file directly to your local computer.

Backing up the database using terminal access

To back up the database using terminal access to the server:

1. Log in to your server or hosting account.

2. Go to the X-Cart root directory.

3. Run the following shell command.

> mysqldump -h<db_host> -u<username> -p<password> -r<backup_filename> <db_name>

The abbreviations in the command mean:

db_host :: The DNS name or the IP-address of your MySQL server.
username :: The username for your MySQL user account.
password :: The password for your MySQL user account.
backup_filename :: The name and the path to the newly created SQL file with the database dump.
db_name :: The name of the MySQL database that you use for X-Cart.

After you have run the command, the system will generate an SQL file and save it to the directory that you have specified in the <backup_filename> part of the command. If you have specified the name of the file for the backup only without mentioning the path, the file will be saved be saved to the X-Cart root directory, the directory where you are currently located.

If necessary, you can use a different path, but it is yet recommended that it be a location within the X-Cart root directory.

Backing up Store Files

Restoring the Store from a Backup

Prerequisites

Restoring Store Files from Archive

Restoring Store Database from SQL Dump

Safety Tips

Troubleshooting