GBase 8a
适配迁移
文章

8a集群间数据迁移两种办法简介

发表于2025-01-02 14:13:48247次浏览1个评论

之前项目有两种方法可以实现数据迁移,第一使用数据流转平台(datax等),第二使用数据导出导入。

datax实现数据迁移对于客户学习成本较低,同时可以配合dataworks平台的功能设置,实现定时操作等功能。为了配合某项目的功能实现,已经适配了对应的datax的reader和writer插件,具体可以找公司申请。使用办法有对应的插件说明。

数据导出导入作为8a的集成功能,项目内说明简要如下:

两步执行,第一步在原集群select into outfile导出数据到文件,第二步在目标集群执行load data,将第一步的数据文件导出到目标表。这两步操作只能在服务器通过gccli命令行执行。
第一步导出文件:
gccli 登录集群,执行数据导出:
修改参数    set global gbase_export_directory=off;
 

示例sql:
select * from test.lineorder limit 1000000 into outfile '/opt/test.lineorder.txt' fields terminated by '&|?' null_value 'gbasenull' lines terminated by '=??=';
修改红色部分为各个库表名,可以做成脚本,批量执行。

第二部导入数据:
gccli登录目标集群,执行数据导入:

示例sql:
load data infile 'ftp://gbase:gbase@109.201.96.89//opt/test.lineorder.txt' into table test.lineorder data_format 3 fields terminated by '&|?' null_value 'gbasenull' lines terminated by '=??=';
使用ftp服务,需要先保证服务器安装了ftp服务,并且服务可用,并且ftp账号对文件有响应的读写权限。目前可以实现该功能的是gbload服务器。
load data infile 'sftp://gbase:gbase@109.201.96.89//opt/test.lineorder.txt' into table test.lineorder data_format 3 fields terminated by '&|?' null_value 'gbasenull' lines terminated by '=??=';
使用sftp服务器,在默认情况下,只需要保证文件权限即可。基本所有集群机器都可以实现。
load data infile 'file://gbase:gbase@109.201.96.89//opt/test.lineorder.txt' into table test.lineorder data_format 3 fields terminated by '&|?' null_value 'gbasenull' lines terminated by '=??=';
使用file协议,只能在集群gc节点机器上,需要保证第一步文件导出的时候,直接将文件导出到目标集群机器上。因此需要将第一步的文件导出修改为如下方式:

示例sql:
[gbase@m89f01012 gbload_server]$ gccli -ugclustergbase -p -h109.201.96.90
Enter password:

GBase client 9.5.2.39-OLAP.126761. Copyright (c) 2004-2021, GBase.  All Rights Reserved.

gbase> rmt:select * from test.lineorder limit 1000000 into outfile '/opt/test.lineorder1.txt' fields terminated by '&|?' null_value 'gbasenull' lines terminated by '=??=';

gccli加上-h  参数,实现远程登录,跳过rmt协议,将文件直接落在执行sql的机器上,然后文件加载就可以使用file协议。
红字部分对应第一步数据导出。

评论

登录后才可以发表评论
崔哥发表于 6个月前
黄河九天上,人鬼瞰重关。长风怒卷高浪,飞洒日光寒。峻似吕梁千仞,壮似钱塘八月,直下洗尘寰。万象入横溃,依旧一峰闲。仰危巢,双鹄过,杳难攀。人间此险何用,万古袐神奸。不用燃犀下照,未必佽飞强射,有力障狂澜。唤取骑鲸客,挝鼓过银山。