Migrate data from Magento 1 to Magento 2

Data Migration from Magento 1 to Magento 2 is a bit technical if you are a newbie or a new Magento learner. You can start the migration process by installing the Magento 2 Data Migration Tool via composer.

To install this tool, make sure that the version of Magento 2 and Data Migration Tool matches exactly. For example, if you are using Magento v2.1.2, you must install Data Migration Tool v2.1.2.

If you are worried about the version of your Magento 2, you can find it out by navigating to the root directory of your Magento 2 via SSH terminal and enter the following command:

php bin/magento --version

Now, once you know the version of your Magento 2 store, you can now install the Data Migration Tool. I am sharing 2 CLI commands with you. The 1st command will update the location of the Data Migration Tool package in the composer.json file and the 2nd command will install the tool in your Magento 2 store. Run the following commands to carry out this job:

composer config repositories.magento composer https://repo.magento.com
composer require magento/data-migration-tool:<version>

In the above CLI command, <version> refers to the version of Data Migration Tool which must match with the Magento 2 version discovered earlier. For example, if you are using Magento 2.1.2, enter the exact below commands:

composer config repositories.magento composer https://repo.magento.com
composer require magento/data-migration-tool:2.1.2

You will be asked to enter your authentication keys. Go to Magento Marketplace. Sign in using your login credentials, click My Access Keys and get your public and private key. After that within few seconds, the Data Migration Tool will be successfully installed on your Magento 2 store.

After the installation, the following directories will contain mapping and configuration files for the Data Migration Tool:

Magento 2 root dir/vendor/magento/data-migration-tool/etc/ce-to-ce

contains configuration and scripts for migrating from Magento 1 Community Edition to Magento 2 Community Edition, and

Magento 2 root dir/vendor/magento/data-migration-tool/etc/ce-to-ee

contains configuration and scripts for migrating from Magento 1 Community Edition to Magento 2 Enterprise Edition, and

Magento 2 root dir/vendor/magento/data-migration-tool/etc/ee-to-ee

contains configuration and scripts for migrating from Magento 1 Enterprise Edition to Magento 2 Enterprise Edition.

Before you migrate any settings and data, you must create a config.xml file in the relevant directory. For example, if you are performing data migration from Magento 1 CE to Magento 2 CE, navigate to the Magento 2 root dir/vendor/magento/data-migration-tool/etc/ce-to-ce/<Magento 1.x version> directory and rename config.xml.dist to config.xml.

Next, open config.xml in a code editor and specify the following:

<source>
<database host="localhost" name="Magento1-DB-name" user="DB-username" password="DB-password"/>
</source>
<destination>
<database host="localhost" name="Magento2-DB-name" user="DB-username" password="DB-password"/>
</destination>
<options>
<crypt_key>Magento1-Encrypted-Key</crypt_key>
</options>

In the above code, <source> has the database information of Magento 1 and <destination> has the relevant information of Magento 2. <crypt_key> is mandatory to fill in. It is the encryption key of Magento 1 which can be found in Magento 1 root dir/app/etc/local.xml file in <key> tag.

When finished, save the config.xml and you are done!

Now, To migrate the settings, navigate to your Magento 2 root directory via SSH terminal and run the following command:

php bin/magento migrate:settings --reset <path to your config.xml>

where <path to your config.xml> this would be vendor/magento/data-migration-tool/etc/ce-to-ce/<Magento 1.x version>/config.xml. I have also used --reset argument in the above command which forces the Data Migration Tool to start from the beginning.

And finally, to migrate data, run the following CLI command:

php bin/magento migrate:data --reset <path to your config.xml>

As this command runs, the Data Migration Tool saves its current progress, and in the case of any errors, stops the process and resumes the progress from the last known good state. Also, the Data Migration Tool may report some errors during the migration. I advise you to refer the Troubleshooting page of the Data Migration Tool for further assistance.

Once the data migration is completed, you will receive a success message. For further reference, you can visit the below blog post:

How To Migrate From Magento 1 To Magento 2