The use of Data Migration tool from M1 to M2

<h1>The Beginnings:</h1>
This is the article for [Magento 2 Advent Calendar 2018](https://adventar.org/calendars/3176) on 19th day.

Today, I am going to write some of my experience on data migration from M1 to M2. It is a tool that is used for migrating data from Magento 1. X system to Magento 2. X system. By using this [git hub link](https://github.com/magento/data-migration-tool) I tried to migrate data and setting from Magento1 to Magento2.

<h1>Execution Enviroment</h1>
<h6>Magnento 1 Server</h6>
Magento 1.7.0.2
Vagrant 
Ubuntu 18.04.1 LTS 
PHP 7.1.23 
MySQL 5.7.24 Apache 2.4.29

<h6>Magnento 2 Server</h6>
Magento 2.2.7
Vagrant 
Ubuntu 18.04.1 LTS 
PHP 7.1.23 
MySQL 5.7.24 Apache 2.4.29

<h1>References</h1>
http://devdocs.magento.com/guides/v2.0/migration/migration-tool.html 
https://github.com/magento/data-migration-tool 
http://devdocs.magento.com/guides/v2.0/migration/migration-manually.html 
http://devdocs.magento.com/guides/v2.0/migration/migration-migrate-after.html

As I am doing this task for the first time it gives me lot of nightmare because of unknown errors I have faced.
By referring these links I have duplicate the Magento 1 DB and then move this to Magento 2 server by using Data Migration Tool.

<h1>Magento 1 DB replication step</h1>
For the Magento 1 DB replication I had done following steps:
1. Go to magento 1 mysql and then use command `mysqldump -u root -p magento1 > magento1.dump` this will dump the db of Magento 1.
2. Then move this dump file of Magento 1 into Magento 2 server.
3. Now create new DB name magento1db and then use command `mysqldump -u root -p magento1db < magento1.dump` this will restore the magento 1 db into Magento2 server. This completes replication of Magento 1 db.

<h1>Installation of Data Migration Tool</h1>
I have used this github link https://github.com/magento/data-migration-tool to install the data migration tool.
1. First command is `composer config repositories.data-migration-tool git https://github.com/magento/data-migration-tool`
2. Second command is `composer require magento/data-migration-tool:2.2.6`

Here 2.2.6 is the data migration tool version I'm going to use.
Now we need to setup the config files which are located into the `Document root/vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.7.0.2`.
The installed directory should be as follows:
![スクリーンショット 2018-12-19 18.34.46.png](https://qiita-image-store.s3.amazonaws.com/0/327994/d01c1402-e88c-183c-01b3-042502b25ee5.png)


There are two files we need to change. First one is `config.xml.dist` and next is `map.xml.dist`.

![スクリーンショット 2018-12-19 18.41.43.png](https://qiita-image-store.s3.amazonaws.com/0/327994/9e73a9a9-0ded-1131-2d84-eaeb75118224.png)


In `config.xml.dist` file we need to change the following:
![スクリーンショット 2018-12-19 18.39.54.png](https://qiita-image-store.s3.amazonaws.com/0/327994/d2db2c0e-a78c-4d48-b6ae-e92cc6d0ff75.png)


`<source>
<database host="127.0.0.1" name="Magento1DB" user="username" password="password"/>
</source>
<destination>
<database host="127.0.0.1" name="Magento2DB" user="username" password="password"/>
</destination>
<options>
<crypt_key>The secret key of Magento1 directory app/etc/local.xml</crypt_key>
</options>`
Here, we need to replace username by the actual username of Magento 1 and Magento 2 and so as password field.


The crypt_key field need to be replaced by the secret key found in the Magento 1 directory /app/etc/local.xml. Now next step is to migrate data and settings.

<h1>Migrating data and settings</h1>
For migrating process I had used following procedures:
1. `sudo php /var/www/magento2/bin/magento migrate:settings -vvv vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.7.0.2/config.xml.dist` this will migrate all the settings from M1 to M2.
2. `sudo php /var/www/magento2/bin/magento migrate:data -vvv vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.7.0.2/config.xml.dist` this will migrate all the data and tables of M1 to M2.

If this completes with no errors then data migration is completed.
But in my case gives the error like this:

`
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: EAV Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: Customer Attributes Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: Map Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: Url Rewrite Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: Log Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: integrity check][step: Ratings Step]: started
[2018-10-16 17:10:27][INFO][mode: data][stage: volume check][step: EAV Step]: started
100% [============================] Remaining Time: 1 sec
[2018-10-16 17:10:27][ERROR]: Class catalog/product_attribute_backend_finishdate does not exist but mentioned in: eav_attribute.backend_model for attribute_id=78
[2016-09-13 21:48:27][ERROR]: Class category_attribute_source_block_proportions does not exist but mentioned in: eav_attribute.source_model for attribute_id=138
`
To resolve this issue I have used this command `sudo php /var/www/magento2/bin/magento migrate:data -r -a vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.7.0.2/config.xml.dist`
this will just ignore all those missing fields and settings.
This command will successfully complete the data migration process.

<h1>After Data Migration</h1> 
The last but least I need to do further procedures:
1. Run the cache clean steps to clear the cache of Magento 2. command is `php bin/magento cache:clean`
2. Reindex all the tables and data using command `php bin/magento indexer: reindex`

This will reflect all the migrated data into the website. Now, run the web url and see the changes by yourself.

<h1>Finally</h1>

I tried to do all the data migration procedure without having any troubles during the steps. But it gave me lot of troubles and at last I was able to solve all of those troubles. But after the completion this first migration step I was able to cope with all the troubles and able to complete data migration successfully in other two data migration projects.