Magento Tutorials

How to Use Magento Database Repair Tool

Magento Database Repair Tool compares 2 databases (corrupt and target), then updates the target database so it has the same structure as the corrupted database.

Magento database repair tool

About the Repair Tool

This tool is used to fix the database of an existing Magento installation which has one or some of these errors: missing tables, missing fields, inconsistent data from tables, missing foreign keys and indexes.

Step 1: Limit Access to Website

You should restrict access to your website while repairing the database. The following example restricts your Magento instance to your IP address exclusively. Other visitors, including search spiders, will get the HTTP “503 Service Unavailable” error.

Step 2: Create a Rewrite rule

  1. Create a file named 503.php in Magento root which contains the code below:
<?php
header('HTTP/1.1 503 Service Unavailable');
header('Content-Type: text/plain; charset=UTF-8');
echo "503 Service Unavailable";
  1. Add the following rewrite rule in .htaccess or in Apache server configuration. Replace the IP address xxx\.x\.x\.x (xxx.x.x.x) with your own IP address.
    #FileETag none RewriteEngine On RewriteCond %(REMOTE_ADDR) !^xxx\.x\.x\.x$ RewriteRule !503.php /503.php L
  2. Save the .htaccess file or reload the Apache configuration. Your site will be down until the end of the process when you restore its original state.

Step 3: Install the Database Repair Tool

  1. Download the archived Magento Database Repair tool from the Magento Community Edition download page.
  2. Upload the archived file to your server, and extract it to any folder, or extract the archive. Then, upload the file magento-db-repair-tool-1.2.php to any folder on your server.

Step 4: Backup and Clone your database

  1. Back up your existing database which has the problem. (The database 1)
  2. Clone the “database 1” as the new “database 2” on the same server
  3. Create new empty database (database 3)
  4. Then do one of the following:
  • Copy the entire Magento folder (without the cache and sessions) to a new location, and install “database3.” Then, update the local.xml file with the database credentials.
  • Since access to the site is restricted, you can update the database credentials to “database3” for the current Magento instance. Then, clean the cache and launch Magento. The new database will be installed automatically.

Now you have “database2,” which is a clone of your original database, and a Magento installation with the empty “database3.”

Step 5: Run Database Repair

  1. Now run http://url-of-your-server/path-to-folder/magento-db-repair-tool-1.0.php
  2. Enter access credentials to “database2” as “corrupted” database and to “database3” as “reference” database
  3. Set table prefixes, if applicable
  4. Press Continue and you will see result screen where you will see what was done to the “corrupted” database.

Step 6: Examine the results, perform the repair, remove the database repair file, and restore access to your website.


See also:
How Magento Database Structure will “take over” your job
How to Create the Magento Database Schema
A Detailed Comparison between Magento Community and Enterprise Edition

Is it helpful?

A knowledge craver who always strive to be wiser everyday.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments