一、需要在hbase集群停掉的情况下迁移

  步骤:(1)执行hadoop distcp -f filelist "hdfs://new cluster ip:9000/hbasetest"
       (2)在new cluster执行./hbase org.jruby.Main add_table.rb /hbase/table20111222,将拷贝来的表加入到.MEAT.中(会出现region的数目不一致的问题,这个需要重启hase才能解决)
  说明:(1)filelist为hdfs上的列表文件,内容如下:
              /hbase/table20111222
            /hbase/table20120131
       (2)如果两个集群的hadoop版本不一致,需要在new cluster上执行hadoop distcp,否则会出现读写异常;

二、在集群运行的时候进行数据迁移
1、Replication:这个是动态的备份(可以理解为实时备份)

     步骤:(1)在old cluster将需要迁移的表属性进行修改:
               disable 'your_table'
              alter 'your_table', {NAME => 'family_name', REPLICATION_SCOPE => '1'}
              enable 'your_table'
         (2)打开new cluster集群的replication,修改hbase-site.xml
            <property>
              <name>hbase.replication</name>
              <value>true</value>
            </property>
         (3)添加peer,在new cluster的hbase shell中执行:add_peer '1','old cluster ip:2181:/hbase',启动replication,执行start_replication
     说明:需要两个集群的hadoop版本一致,否则出现读写错误


2、CopyTable:可以在本集群中拷贝一张表,也可以将表拷贝到其他的集群中。

    命令:./hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=new cluster ip:2181:/hbase zy_test
    说明:(1)拷贝完成,不需要重启机器,在new cluster中就可以看到该表;
         (2)稳定性还需要考虑,测试过程中遇到一个问题,拷贝过程中始终都停留在这里Lookedup root region location, 查看日志没有什么错误和相关的信息。


3、Export and Import

    步骤:(1)在old cluster上执行:./hbase org.apache.hadoop.hbase.mapreduce.Export test hdfs://new cluster ip:9000/zhuangyang/test
         (2)在new cluster上执行:./hbase org.apache.hadoop.hbase.mapreduce.Import test hdfs://new cluster ip:9000/zhuangyang/test
    说明:(1)一定要写全路径,不能写相对路劲;
         (2)在import前,需要将表事先在new cluster中创建好.