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

From X-Cart 4 Classic
Jump to: navigation, search
(Backing up Store Database)
(Backing up Store Files)
Line 118: Line 118:
  
 
===Backing up Store Files===
 
===Backing up Store Files===
 +
 +
Creating a backup copy of the store files presumes that you pack all the files in the X-Cart root directory into an archive and then copy or move the archive to a new location on the remote server or your local computer.
 +
 +
{{Note1|Note: If you have previously saved the database dump into the predefined file in the X-Cart root directory (folder <u><xcart_dir>/var/tmp/</u>), the file will also be included into the archive.}}
 +
 +
To create an archive you need to use a file archive manager. The exact choice of the archive manager will depend on the operating system you use. On a '''UNIX-based server''', the most popular archive manager, which is currently installed on the majority of servers, is TAR. Later in this section you will find an example of how to archive the X-Cart files with the TAR archive manager. On a '''Windows-based server''', you can create the archive with one of the available file archive managers for Windows, including WinRAR, WinZIP, PKZip and 7Zip. You need to pack the whole X-Cart root directory to an archive and then save the archive to the directory that is parent to the X-Cart root directory.
 +
 +
Alternatively, if it is not possible to pack the X-Cart files into an archive directly on your server, you can copy the X-Cart root directory to your local computer or another remote server using '''FTP''' or other suitable facility. Before that, make sure the new location, to which you are planning to copy the X-Cart root directory, has enough free disk space. Besides, the '''control panel''' of your hosting provider may offer its own facilities for backing up your account data.
 +
 +
==== Backing up store files with the TAR archive manager (UNIX-based servers only) ====
 +
 +
In UNIX-based systems, TAR is known to be one of the most reliable and trustworthy utilities for creating and manipulating file archives. It is now commonly used in tandem with external compression utilities like GZIP, BZIP2 or LZMA, which enables you not only to create an archive, but also compress the data in the archive. As a result, with TAR you can create a lightweight archive of your store and then restore it using the same utility. To find out whether TAR is installed on your server, run the following shell command.
 +
 +
<pre>
 +
> tar --version
 +
</pre>
 +
 +
If TAR is installed on your server, the system will display a message with the version of the utility; otherwise you will see an error message. In case of the latter, please contact your hosting team for help.
 +
 +
To back up files with the TAR archive manager:
 +
 +
1. Log in to your server or your hosting account.
 +
 +
2. Go to the X-Cart root directory.
 +
 +
3. In the X-Cart root directory run the following shell command.
 +
 +
<pre>
 +
> tar -czfv ../store_backup.tgz *
 +
</pre>
 +
 +
After you have run the command, TAR will pack all the files in the X-Cart root directory to the file store_backup.tgz and compress it with the ZIP data compression algorithm. The file will be saved to the directory that is parent to the X-Cart root directory. For example, if the X-Cart root directory is <u>u/user/public_html/xcart</u>, the file store_backup.tgz will be saved to directory <u>u/user/public_html</u>.
  
 
==Restoring the Store from a Backup==
 
==Restoring the Store from a Backup==

Revision as of 16:15, 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

Creating a backup copy of the store files presumes that you pack all the files in the X-Cart root directory into an archive and then copy or move the archive to a new location on the remote server or your local computer.

Note: If you have previously saved the database dump into the predefined file in the X-Cart root directory (folder <xcart_dir>/var/tmp/), the file will also be included into the archive.

To create an archive you need to use a file archive manager. The exact choice of the archive manager will depend on the operating system you use. On a UNIX-based server, the most popular archive manager, which is currently installed on the majority of servers, is TAR. Later in this section you will find an example of how to archive the X-Cart files with the TAR archive manager. On a Windows-based server, you can create the archive with one of the available file archive managers for Windows, including WinRAR, WinZIP, PKZip and 7Zip. You need to pack the whole X-Cart root directory to an archive and then save the archive to the directory that is parent to the X-Cart root directory.

Alternatively, if it is not possible to pack the X-Cart files into an archive directly on your server, you can copy the X-Cart root directory to your local computer or another remote server using FTP or other suitable facility. Before that, make sure the new location, to which you are planning to copy the X-Cart root directory, has enough free disk space. Besides, the control panel of your hosting provider may offer its own facilities for backing up your account data.

Backing up store files with the TAR archive manager (UNIX-based servers only)

In UNIX-based systems, TAR is known to be one of the most reliable and trustworthy utilities for creating and manipulating file archives. It is now commonly used in tandem with external compression utilities like GZIP, BZIP2 or LZMA, which enables you not only to create an archive, but also compress the data in the archive. As a result, with TAR you can create a lightweight archive of your store and then restore it using the same utility. To find out whether TAR is installed on your server, run the following shell command.

> tar --version

If TAR is installed on your server, the system will display a message with the version of the utility; otherwise you will see an error message. In case of the latter, please contact your hosting team for help.

To back up files with the TAR archive manager:

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

2. Go to the X-Cart root directory.

3. In the X-Cart root directory run the following shell command.

> tar -czfv ../store_backup.tgz *

After you have run the command, TAR will pack all the files in the X-Cart root directory to the file store_backup.tgz and compress it with the ZIP data compression algorithm. The file will be saved to the directory that is parent to the X-Cart root directory. For example, if the X-Cart root directory is u/user/public_html/xcart, the file store_backup.tgz will be saved to directory u/user/public_html.

Restoring the Store from a Backup

Prerequisites

Restoring Store Files from Archive

Restoring Store Database from SQL Dump

Safety Tips

Troubleshooting