HBase的备份和还原

来源:互联网 发布:微信 淘宝双十一红包群 编辑:程序博客网 时间:2024/04/27 19:56

1)HBase热备份的方法
(2)HBase热备的还原
(3)HBase冷备份
(4)HBase冷备的还原


(1)启动Hbase
./start-hbase.sh

(2)创建表
hbase shell
create ‘test’,{NAME=>’CF’,VERSIONS=>3}

3.导出数据
hadoop dfs -ls /
./hbase org.apache.hadoop.hbase.mapreduce.Export test /export
hadoop dfs -ls /

4使用copyTable实现热备份
将test表中的数据复制到test3
create ‘test3’, ‘cf’
exit
./hbase org.apache.hadoop.hbase.mapreduce.CopyTable –new.name=test3 test

二热备还原
1.删除数据
./hbase shell
list
disable ‘test’
drop ‘test’
list
2.
create ‘test’, ‘cf’
./hbase org.apache.hadoop.hbase.mapreduce.Import test /export
scan ‘test’

三HBase冷备份
(使用hadoop的distcp命令实现Hbase的冷备份,Hbase是关闭的但是hadoop是必须开启的)
1.启动Hadoop
start-all.sh
2.启动Hbase
start-hbase.sh

3.创建测试表并且插入测试数据
create ‘test’,’cf’
put ‘test’,’r001’,’cf:a’,’v1’
scan ‘test’
exit
4.停止HBase
./stop-hbase.sh
5.进行备份
hadoop distcp /hbase /hbasebackup
hadoop dfs -ls /

四HBase冷备的还原
1.启动HBase,删除测试数据
./start-hbase.sh
./hbase shell
list
disable ‘test’
drop ‘test’
list
2.停止HBase
./stop-hbase.sh
hdfs dfs -mv /hbase /hbase_tmp
hadoop distcp -overwrite /hbasebackup /hbase
haddop dfs -ls /hadoop dfs -rmr .hbase_temp
3.启动HBase
./start-hbase.sh
hbase shell
list
sacn ‘test’

0 0