MoveTo命令可以实现表和分区数据的迁移功能。本文为您介绍MoveTo命令的使用方法。
前提条件
- 本地安装了Java JDK 8。
- 已创建集群,详情请参见创建集群。
背景信息
MoveTo命令可以在拷贝底层数据结束后,自动更新元数据,使表和分区的数据完整地迁移到新路径;可以通过条件筛选,一次拷贝大量分区。在数据迁移过程中,还使用了多种措施保护数据的完整性,确保数据安全。
使用限制
EMR-3.36.0及后续版本或EMR-5.2.0及后续版本的集群,支持使用MoveTo命令。
使用MoveTo命令
重要 集群上每次仅允许运行一个MoveTo进程。如果集群上有正在运行的MoveTo进程,启动新的MoveTo进程时会因为获取不到配置锁而退出,并告知正在运行的MoveTo进程。此时,您可以终止掉正在运行的MoveTo进程,启动新的MoveTo进程,或者等待正在运行的MoveTo进程结束。
- 通过SSH方式登录集群,详情请参见登录集群。
- 执行以下命令,获取帮助信息。
jindo table -help moveTo帮助信息类似如下所示。<dbName.tableName> The table to move. <destination path> The destination base directory which is always at the same level of a 'table location', where the moved partitions or un-partitioned data would located in. <condition>/-fullTable A filter condition to determine which partitions should be moved, supporting common operators (like '>') and built-in UDFs (like to_date) (UDFs not supported yet...), while -fullTable means that all partitions (or a whole un-partitioned table) should be moved. One but only one option must be specified among -c "<condition>" and -fullTable. <before days> Optional, saying that table/partitions should be moved only when they are created (not updated or modified) more than some days before from now. <parallelism> The maximum concurrency when copying partitions, 1 by default. <OSS storage policy>: Storage policy for OSS destination, which can be Standard (by default), IA, Archive, or ColdArchive. Not applicable for destinations other than OSS. NOTE: if you are willing to use ColdArchive storage policy, please make sure that Cold Archive has been enabled for your OSS bucket. -o/-overWrite Overwriting the final paths where the data would be moved. For partitioned tables this overwrites partitions' locations which are subdirectories of <destination path>; for un-partitioned table this overwrites the <destination path> itself. -r/-removeSource Let the source data be removed when the corresponding table/partition is successfully moved to the new destination. Otherwise (by default), the source data would be left as it was. -skipTrash Applicable only when [-r/-removeSource] is enabled. If present, source data would be immediately deleted from the file system, bypassing the trash. -e/-explain If present, the command would not really move data, but only prints the table/partitions that would be moved for given conditions. <log directory> A directory to locate log files, '/tmp/<current user>/' by default.MoveTo命令语句如下所示。jindo table -moveTo \ -t <dbName.tableName> \ -d <destination path> \ [-c "<condition>" | -fullTable] \ [-b/-before <before days>] \ [-p/-parallel <parallelism>] \ [-s/-storagePolicy <OSS storage policy>] \ [-o/-overWrite] \ [-r/-removeSource] \ [-skipTrash] \ [-e/-explain] \ [-l/-logDir <log directory>]参数 描述 是否必选参数 -t <dbName.tableName> 待移动的表名称,格式为 数据库名.表名。数据库和表名之前以半角句号(.)分隔。表可以是分区表或非分区表。
是 -d <destination path> 待移动的目标位置。无论是移动分区还是移动非分区表的整表,该位置都对应 "表" 一级的位置。如果移动的是分区,则分区的完整路径是该路径+分区名。例如 <destination path>/p1=v1/p2=v2/。是 -c "<condition>" | -fullTable 两者必须且只能提供一个,即要么指定 -c "<condition>",要么指定-fullTable。- 指定
-fullTable时,则为移动整表,既可以是非分区表也可以是分区表。 - 指定
-c "<condition>"时,则提供了一个过滤条件,用来选择希望移动的分区,支持常见运算符,例如大于号(>)。例如,数据类型为String的分区ds,希望分区名大于 'd',则代码为
-c " ds > 'd' "。
否 -b/before <before days> 仅创建时间距离现在超过一定天数的表或者分区才会被移动。 否 -p/-parallel <parallelism> 迁移操作的并行度。 否 -s/-storagePolicy <OSS storage policy> 拷贝到OSS时,在OSS上的存储策略。存储策略如下: - Standard:归档存储。
- IA:低频 (Infrequent Access)存储。
- Archive:标准存储。
- ColdArchive:冷归档存储。说明 使用前请确保OSS Bucket开通了该功能。
否 -o/-overWrite 是否强制覆盖目标写入路径。如果是分区表,则只会清空待移动分区的分区路径,不会清空整个表路径。 否 -r/-removeSource 移动完成,元数据也同步更新后,是否清理源路径。如果是分区表,则只会清理成功移动的分区的源路径。 否 -skipTrash 清理源路径时是否跳过Trash。 说明 在指定了参数-r/-removeSource时适用。否 -e/-explain 如果出现该选项,则为解释(explain )模式,只会显示待移动的分区列表,而不会真正移动数据。 否 -l/-logDir <log directory> 指定Log文件目录。 否 - 指定
配置锁目录
MoveTo工具实现了进程锁,需要提供一个HDFS的路径放置锁文件。默认情况下,该路径为hdfs:///tmp/jindotable-lock/。
重要 放置锁文件的路径只能是HDFS路径。如果您对该路径无操作权限时,可以按照如下步骤添加自定义配置,配置该路径。
- 进入HDFS服务页面。
- 登录阿里云E-MapReduce控制台。
- 在顶部菜单栏处,根据实际情况选择地域和资源组。
- 单击上方的集群管理页签。
- 在集群管理页面,单击相应集群所在行的详情。
- 在左侧导航栏,选择。
- 登录阿里云E-MapReduce控制台。
- 修改配置。
- 在HDFS服务的配置页面,单击hdfs-site或core-site页签。
- 单击右上角的自定义配置。

- 在新增配置项对话框中,添加配置项jindotable.moveto.tablelock.base.dir,参数值为一个已存在的HDFS路径。
重要 自定义配置锁目录时,请确保整个集群的所有节点上不存在正在运行的MoveTo进程,否则可能导致MoveTo执行失败,甚至导致数据污染。
- 保存配置。
- 单击右上角的保存。
- 在确认修改对话框中,输入执行原因,单击确定。
该文章对您有帮助吗?