最近,因为公司准备要更换数据中心;因此,需要将hbase数据库中的数据进行迁移。在进行hbase数据库数据迁移时,使用其自带的工具import和export是很方便的。只不过,在迁移大量数据时,可能需要运行很长的时间,甚至可能出错。这时,是可以通过指定行键范围和列族,来减少单次export工具的运行时间。
我们来看一下,export工具支持的参数,如下:
Usage: Export [-D <property=value>]* <tablename> <outputdir> [<versions> [<starttime> [<endtime>]] [^[regex pattern] or [Prefix] to filter]]
Note: -D properties will be applied to the conf used.
For example:
-D mapred.output.compress=true
-D mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec
-D mapred.output.compression.type=BLOCK
Additionally, the following SCAN properties can be specified
to control/limit what is exported..
-D hbase.mapreduce.scan.column.family=<familyName>
-D hbase.mapreduce.include.deleted.rows=true
-D hbase.mapreduce.scan.row.start=<ROWSTART>
-D hbase.mapreduce.scan.row.stop=<ROWSTOP>
For performance consider the following properties:
-Dhbase.client.scanner.caching=100
-Dmapred.map.tasks.speculative.execution=false
-Dmapred.reduce.tasks.speculative.execution=false
For tables with very wide rows consider setting the batch size as below:
-Dhbase.export.scanner.batch=10
可以看出,支持的选项有好几个。假如,我们想导出表test的数据,且只要列族Info,行键范围在000到001之间,可以这样写:
./hbase org.apache.hadoop.hbase.mapreduce.Export -D hbase.mapreduce.scan.column.family=Info -D hbase.mapreduce.scan.row.start=000 -D hbase.mapreduce.scan.row.stop=001 test /test_datas
这样就可以了,且数据将会保存在hdfs中。
通过指定列族和行键范围,可以只导出部分数据,避免export启动的mapreduce任务运行时间过长。也就是可以分多次导出数据。