HowTo: Migrate data from Magento2 Commerce to Magento2 CE

I recently was asked to work on a data migration from Adobe Commerce 2.3.7-p3 to a Magento Community 2.4.3-p2 instance. I have done similar tasks in the past using the official Magento Data Migration Tool so that was my weapon of choice. In the following lines I will try to describe the process.

Important: It is important to mention that the MDMT was created to migrate data from Magento1 to Magento2 and mainly from Community to Commerce.

Still, I decided to carry on using this weapon for the task because in essence the tool:

  • The tool migrates data from one Magento to another.
  • If we think about it, Adobe Commerce db and Magento CE db and almost identical.
  • This is the tool I had experience working with :)

What do you need

  • A source database dump: in this case a database dump of the Adobe Commerce website.
  • The <crypt_key> used in the Adobe Commerce website: this is required if you need to migrate passwords.
  • A local environment with the destination Magento instance.
  • A backup of destination database: You are going reset your destination env multiple times so better be prepared.
  • Patience :)

Notice: If you (or me) are reading this is because you are working on a similar data migration task, so I am going to skip the story part and focus on the steps I did to successfully migrate the data.

Summary

The whole process can be summarized as follows:

  1. Create an empty database into the same server the Magento 2 CE is and import the source database (in this case the Adobe Commerce database).
  2. Install the MDMT in the Magento instance you need to migrate data to.
  3. Extend the MDMT with a custom module.
  4. Add configuration to the config.xml.
  5. Customize the steps.
  6. Run the command and fix errors/warnings.
  7. Post migrating amends in the destination database.

If you are interested in the details, keep reading :-)

Import the source database

Rather than working with the live site, you can perfectly ask for a stripped and anonymized database dump or the source Adobe Commerce instance. Once you have it, import it into your local MySQL/MariaDB server. (The same server where you have the destination Magento Instance).

Note: If the Source and Destination databases are in different servers, you still use the MDMT by creating an SSH tunnel between the two.

Install the Data Migration Tool

This is pretty straight forward, just use composer to install the MDMT using the version of your destination Magento instance:

composer require "magento/data-migration-tool":"2.4.3"

Extend the MDMT

The MDMT can be customized in 2 ways:

  1. Modify things directly into vendor/magento/data-migration-tool where the data migration is installed.
  2. Create a custom module and extend Magento_DataMigrationTool.

For this job I choose the second approach because I think is cleaner, it allows to keep track of changes in the repository, revert, etc. Also, because the Magento_DataMigrationTool is a Magento module, so if you need to rewrite a class or something it is easier to do that way.

So, I created an empty module and inside the etc folder, created another called commerce-to-opensource, then copied one of the examples provided by MDMT module.

The final structure was similar to this:

app/code/Vendor/DataMigrationTool

|-- etc
|   |-- commerce-to-opensource
|   |   |-- 2.3.7
|   |   |   |-- config.xml.dist
|   |   |   |-- map-tier-price.xml.dist
|   |   |   `-- map.xml.dist
|   |   |-- class-map.xml.dist
|   |   |-- customer-attribute-groups.xml.dist
|   |   |-- customer-document-groups.xml.dist
|   |   |-- deltalog.xml.dist
|   |   |-- eav-attribute-groups.xml.dist
|   |   |-- eav-document-groups.xml.dist
|   |   |-- log-document-groups.xml.dist
|   |   |-- map-customer.xml.dist
|   |   |-- map-document-groups.xml.dist
|   |   |-- map-eav.xml.dist
|   |   |-- map-log.xml.dist
|   |   |-- map-stores.xml.dist
|   |   |-- map-tier-price.xml.dist
|   |   |-- order-grids-document-groups.xml.dist
|   |   `-- settings.xml.dist
|   |-- class-map.xsd
|   |-- config.xsd
|   |-- groups.xsd
|   |-- magento_path.php
|   |-- map.xsd
|   |-- module.xml
|   `-- settings.xsd
|-- composer.json
`-- registration.php

....

Add the configuration

The configuration of the MDMT resides in the config.xml file. Copy config.xml.dist and paste it as config.xml so you can keep a backup od the original one.

Here is where you specify:

  • Source and Destination db credentials.
  • Steps your data migration process will perform.
  • The <crypt_key> used to decode password hashes.
  • And some other settings such as db prefixes, direct table copy, etc.

Customize the steps

The MDMT comes with many steps, they are all grouped in 3 different groups:

  • settings
  • data
  • delta

Here is a bit of explanation of what each command does:

migrate:settings

Migrates stores, website and core_config_data.

migrate:data

Migrates pretty much all data except store configuration such as core_config_data. This command also creates db triggers and backlog needed for the migrate:delta command.

migrate:delta

Migrates incremental data. This is useful if for any reason new data (customers, sales, etc.) have been created in the source database since the moment you performed the migration.

Run the migrate:data command and fix issues

Normally you should run the migrate:settings then migrate:data and finally the migrate:delta commands but for this specific case I only needed to migrate Sales and Customers so the other two commands are not needed.

bin/magento migrate:data -r app/code/Vendor/DataMigrationTool/etc/commerce-to-opensource/2.3.7/config.xml

Related links and resources

Comments

Previous Post