将数据从Magento 1.x迁移到Magento 2.x

本文介绍了如何将数据从Magento 1.x站点迁移到Magento 2.x站点。

我们将使用Magento的官方数据迁移工具模块

–可以通过CLI命令完成数据迁移。
–可以迁移类别,产品,订单,配置设置等数据。
-数据迁移取决于XML文件中定义的规则集。

安装数据迁移工具模块

本模块假定:

–您已经安装了Magento 2站点–您尚未在该Magento 2站点中
添加任何数据。

因此,让我们检查一下Magento 2网站的版本:

–打开终端/命令提示符
–转到Magento 2站点的install / root目录
–运行以下命令:

	
php bin/magento --version

输出可以是这样的:

Magento CLI version 2.2.5

这表明我有2.2.5版本的Magento。

从GitHub安装data-migration-tool模块

–打开终端
–转到Magento 2站点的根目录
–运行以下命令:

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

在这里,<version>表示您的Magento 2网站的版本。就我而言,如您在上面看到的,我有版本2.2.5。因此,对我来说,命令将是:

composer require magento/data-migration-tool:2.2.5

这将要求用户名密码repo.magento.com

要获取repo.magento.com的用户名和密码,必须从https://marketplace.magento.com/customer/account/生成访问密钥。

–转到https://marketplace.magento.com/customer/account/
–登录
–登录后,单击My Access Keys链接
–在My Access Keys页面上,单击Generate Keys按钮
–然后,您将看到两个键(PublicPrivate
– Public Key将是您的Username
– Private Key将是你的Password

从repo.magento.com安装数据迁移工具模块

–打开终端
–转到Magento 2站点的根目录
–运行以下命令:

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

在这里,<version>表示您的Magento 2网站的版本。就我而言,如您在上面看到的,我有版本2.2.5。因此,对我来说,命令将是:

composer require magento/data-migration-tool:2.2.5

这将要求用户名密码repo.magento.com

您可以通过登录Magento Marketplace网站并访问“访问密钥”页面来获取用户名和密码。上面提到了这些步骤。

两种安装过程(来自github和来自repo.magento.com)都非常相似。唯一的区别是composer config命令。

启用模块

–打开终端
–转到Magento 2站点的根目录
–运行以下命令以启用data-migration-tool模块:

php bin/magento module:enable Magento_DataMigrationTool
php bin/magento setup:upgrade
php bin/magento clean:cache

配置Magento数据迁移工具

映射和配置文件目录:

– Go to <Your-Magento2-root-directory>/vendor/magento/data-migration-tool/etc/

– You will see the following directories over there:
    – commerce-to-commerce (to migrate from Magento 1.x Enterprice Edition (EE) to Magento 2.x Enterprise Edition (EE))
    – opensource-to-commerce (to migrate from Magento 1.x Community Edition (CE) to Magento 2.x Enterprise Edition (EE))
    – opensource-to-opensource (to migrate from Magento 1.x Community Edition (CE) to Magento 2.x Community Edition (CE))

– There are some XSD files are well. They are the XML Schema files.
– For example, the config.xsd file is the Schema for the config.xml file present inside the above-mentioned folders.
mukesh:etc chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2/vendor/magento/data-migration-tool/etc
 
mukesh:etc chapagain$ ls
class-map.xsd            groups.xsd            module.xml            settings.xsd
commerce-to-commerce        magento_path.php        opensource-to-commerce
config.xsd            map.xsd                opensource-to-opensource

让我们假设:

–您正在从迁移Magento 1.x Community Edition (CE)Magento 2.x Community Edition (CE)

–您正在从迁移Magento version 1.9.3.8Magento version 2.x

要从Magento 1.x CE迁移到Magento 2.x CE,我们必须进入文件夹opensource-to-opensource

mukesh:etc chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2/vendor/magento/data-migration-tool/etc
 
mukesh:etc chapagain$ cd opensource-to-opensource/
 
mukesh:opensource-to-opensource chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2/vendor/magento/data-migration-tool/etc/opensource-to-opensource
 
mukesh:opensource-to-opensource chapagain$ ls
1.6.0.0                    1.9.2.2                    customer-document-groups.xml.dist
1.6.1.0                    1.9.2.3                    deltalog.xml.dist
1.6.2.0                    1.9.2.4                    eav-attribute-groups.xml.dist
1.7.0.0                    1.9.3.0                    eav-document-groups.xml.dist
1.7.0.1                    1.9.3.1                    log-document-groups.xml.dist
1.7.0.2                    1.9.3.2                    map-customer.xml.dist
1.8.0.0                    1.9.3.3                    map-document-groups.xml.dist
1.8.1.0                    1.9.3.4                    map-eav.xml.dist
1.9.0.0                    1.9.3.6                    map-log.xml.dist
1.9.0.1                    1.9.3.7                    map-stores.xml.dist
1.9.1.0                    1.9.3.8                    map-tier-price.xml.dist
1.9.1.1                    1.9.3.9                    order-grids-document-groups.xml.dist
1.9.2.0                    class-map.xml.dist            settings.xml.dist
1.9.2.1                    customer-attribute-groups.xml.dist

opensource-to-opensource文件夹中,您将看到用于不同Magento 1版本的文件夹。

您还将看到.dist文件。

您可以:

–复制每个.dist文件并从复制文件的名称中删除.dist部分
–或者,您可以直接重命名.dist文件并从其名称中删除.dist

我将复制.dist文件并将其重命名。因此,复制并重命名后,文件opensource-to-opensource夹中将包含以下文件:

mukesh:opensource-to-opensource chapagain$ ls
1.6.0.0                    1.9.3.2                    log-document-groups.xml
1.6.1.0                    1.9.3.3                    log-document-groups.xml.dist
1.6.2.0                    1.9.3.4                    map-customer.xml
1.7.0.0                    1.9.3.6                    map-customer.xml.dist
1.7.0.1                    1.9.3.7                    map-document-groups.xml
1.7.0.2                    1.9.3.8                    map-document-groups.xml.dist
1.8.0.0                    1.9.3.9                    map-eav.xml
1.8.1.0                    class-map.xml.dist            map-eav.xml.dist
1.9.0.0                    class-map.xml.xml            map-log.xml
1.9.0.1                    customer-attribute-groups.xml        map-log.xml.dist
1.9.1.0                    customer-attribute-groups.xml.dist    map-stores.xml
1.9.1.1                    customer-document-groups.xml        map-stores.xml.dist
1.9.2.0                    customer-document-groups.xml.dist    map-tier-price.xml
1.9.2.1                    deltalog.xml                map-tier-price.xml.dist
1.9.2.2                    deltalog.xml.dist            order-grids-document-groups.xml
1.9.2.3                    eav-attribute-groups.xml        order-grids-document-groups.xml.dist
1.9.2.4                    eav-attribute-groups.xml.dist        settings.xml
1.9.3.0                    eav-document-groups.xml            settings.xml.dist
1.9.3.1                    eav-document-groups.xml.dist

在此示例中,我们尝试从Magento 1.9.3.8迁移到Magento2.x。因此,我们将进入文件夹1.9.3.8。

mukesh:opensource-to-opensource chapagain$ cd 1.9.3.8/
 
mukesh:1.9.3.8 chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2/vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.3.8
 
mukesh:1.9.3.8 chapagain$ ls
config.xml.dist        map-tier-price.xml.dist    map.xml.dist

在1.9.3.8文件夹中,您可以看到三个.dist文件。创建它们的副本,然后重命名它们,从名称中删除.dist部分。复制并重命名后,我们将拥有以下文件:

mukesh:1.9.3.8 chapagain$ ls
config.xml        config.xml.dist        map-tier-price.xml    map-tier-price.xml.dist    map.xml            map.xml.dist

编辑config.xml文件

从文件夹1.9.3.8中,打开config.xml文件。

编辑源和目标数据库凭证

config.xml文件中,找到以下代码,然后添加源和目标数据库主机,数据库名称,数据库用户名,数据库密码和数据库端口号。

源=您的magento 1网站
目标=您的magento 2网站

<source>
    <database host="localhost" name="magento1-db-name" user="magento1-db-username" password="magento1-db-password" />
</source>
<destination>
    <database host="localhost" name="magento2-db-name" user="magento2-db-username" password="magento2-db-password" />
</destination>

重命名映射文件名称

在同一个config.xml文件中的“选项”节点下,有映射文件名的列表。文件名包含.dist在其中。您只需.dist要从文件名中删除文本即可。

之前

<options>
    <map_file>etc/opensource-to-opensource/1.9.3.8/map.xml.dist</map_file>
    <eav_map_file>etc/opensource-to-opensource/map-eav.xml.dist</eav_map_file>
    ...
    ...

重命名后

<options>
    <map_file>etc/opensource-to-opensource/1.9.3.8/map.xml</map_file>
    <eav_map_file>etc/opensource-to-opensource/map-eav.xml</eav_map_file>
    <eav_document_groups_file>etc/opensource-to-opensource/eav-document-groups.xml</eav_document_groups_file>
    <eav_attribute_groups_file>etc/opensource-to-opensource/eav-attribute-groups.xml</eav_attribute_groups_file>
    <log_map_file>etc/opensource-to-opensource/map-log.xml</log_map_file>
    <log_document_groups_file>etc/opensource-to-opensource/log-document-groups.xml</log_document_groups_file>
    <settings_map_file>etc/opensource-to-opensource/settings.xml</settings_map_file>
    <customer_map_file>etc/opensource-to-opensource/map-customer.xml</customer_map_file>
    <customer_document_groups_file>etc/opensource-to-opensource/customer-document-groups.xml</customer_document_groups_file>
    <customer_attribute_groups_file>etc/opensource-to-opensource/customer-attribute-groups.xml</customer_attribute_groups_file>
    <delta_document_groups_file>etc/opensource-to-opensource/deltalog.xml</delta_document_groups_file>
    <order_grids_document_groups_file>etc/opensource-to-opensource/order-grids-document-groups.xml</order_grids_document_groups_file>
    <map_document_groups>etc/opensource-to-opensource/map-document-groups.xml</map_document_groups>
    <class_map>etc/opensource-to-opensource/class-map.xml</class_map>
    <tier_price_map_file>etc/opensource-to-opensource/1.9.3.8/map-tier-price.xml</tier_price_map_file>
    <stores_map_file>etc/opensource-to-opensource/map-stores.xml</stores_map_file>

添加数据库表前缀

如果源数据库(Magento 1.x)或目标数据库(Magento 2.x)具有前缀名称,则需要在config.xml文件中指定它们。有用于source_prefix和dest_prefix的XML节点。

如果您的数据库表没有前缀,那么您可以简单地忽略此步骤。

<source_prefix />
<dest_prefix />

添加密钥

config.xml文件中,您需要添加Magento 1.x站点的加密密钥。

您的Magento 1.x站点的加密密钥在以下文件中找到: app/etc/local.xml

<crypt_key>abxcadfa232sdasdf</crypt_key>

为迁移做好准备

在将数据从Magento 1.x迁移到Magento 2.x时,需要确保没有数据插入Magento 1.x数据库。

因此,

–您需要停止Magento 1.x站点的所有cron作业
–将Magento 1.x站点置于维护模式

迁移资料

迁移命令格式如下:

php bin/magento migrate:<mode> [-r|--reset] {<path to config.xml>}
 
where:
 
<mode> may be: settings, data, or delta
[-r|--reset] is an optional argument that starts the migration from the beginning
{<path to config.xml>} is the absolute file system path to config.xml; this is a required argument

迁移顺序为:

–首先,我们需要迁移设置。
–然后,我们迁移数据。
–之后,如果有更改,我们将进行更改。

迁移设定

首先,我们需要迁移不同的设置。我们将运行一个命令,该命令会将配置设置,商店设置和网站设置从Magento 1.x迁移到Magento2.x。

–转到您的Magento 2根目录。

mukesh:magento2 chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2

–运行以下命令:

php bin/magento migrate:settings --reset vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.3.8/config.xml

迁移资料

现在,我们将运行命令从Magento 1.x迁移不同的数据,例如产品,类别,订单,客户。到Magento2.x。

–转到您的Magento 2根目录。

mukesh:magento2 chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2

–运行以下命令:

php bin/magento migrate:data vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.3.8/config.xml

运行此命令时,如果出现以下错误:

未映射源文档
目标文档未映射
源字段未映射
目标字段未映射

在这种情况下,文档指的是数据库表。

这意味着源(Magento 1.x站点)中存在的表/字段在目标(Magento 2.x站点)中不存在。

要解决此错误,您需要在文件中添加忽略字段或忽略文档代码map.xml

<source>
    <document_rules>
        <ignore>
            <document>table_name</document>
        </ignore>
        ...
 
<destination>
    <document_rules>
        <ignore>
            <document>table_name</document>
        </ignore>
        ...
 
<source>
    <field_rules>
        <ignore>
            <document>field_name</document>
        </ignore>
        ...
 
<destination>
    <field_rules>
        <ignore>
            <document>field_name</document>
        </ignore>
        ...

迁移变更/增量迁移

增量迁移意味着仅迁移自上次迁移数据以来所做的那些数据更改。

将数据从Magento 1.x迁移到Magento 2.x之后,如果Magento 1.x站点中的数据发生了某些更改,则可以使用此命令仅从Magento 1迁移那些最近的更改。 x站点到Magento 2.x站点。

–转到您的Magento 2根目录。

mukesh:magento2 chapagain$ pwd
/Users/mukeshchapagain/Sites/magento2

–运行以下命令:

php bin/magento migrate:delta vendor/magento/data-migration-tool/etc/opensource-to-opensource/1.9.3.8/config.xml

这就是有关Magento官方数据迁移工具模块的全部内容。

以下是对数据迁移期间可能会遇到的一些常见错误消息进行故障排除的链接:https : //devdocs.magento.com/guides/v2.1/migration/migration-troubleshooting.html

希望这可以帮助。谢谢。

赞(0)
微信
支付宝
微信二维码图片

微信扫描二维码打赏

支付宝二维码图片

支付宝扫描二维码打赏

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论