Hbase数据备份&&容灾方案

标签(空格分隔): Hbase


一、Distcp

 在使用distcp命令copy hdfs文件的方式实现备份时,需要禁用备份表确保copy时该表没有数据写入,对于在线服务的hbase集群,该方式不可用,将静态此目录distcp 到其他HDFS文件系统时候,可以通过在其他集群直接启动新Hbase 集群将所有数据恢复。

二、CopyTable

执行命令前,需在对端集群先创建表

支持时间区间、row区间,改变表名称,改变列簇名称,指定是否copy删除数据等功能,例如:


hbase org.apache.hadoop.hbase.mapreduce.CopyTable --starttime=1265875194289 --endtime=1265878794289 --peer.adr= dstClusterZK:2181:/hbase --families=myOldCf:myNewCf,cf2,cf3 TestTable
1、同一个集群不同表名称
hbase org.apache.hadoop.hbase.mapreduce.CopyTable --new.name=tableCopy  srcTable
2、跨集群copy表
hbase org.apache.hadoop.hbase.mapreduce.CopyTable --peer.adr=dstClusterZK:2181:/hbase srcTable

跨集群copytable 必须注意是用推的方式,即从原集群运行此命令。

copytable eg

$ ./bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable --help
/bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable --help
Usage: CopyTable [general options] [--starttime=X] [--endtime=Y] [--new.name=NEW] [--peer.adr=ADR] <tablename> Options:
rs.class hbase.regionserver.class of the peer cluster,
specify if different from current cluster
rs.impl hbase.regionserver.impl of the peer cluster,
startrow the start row
stoprow the stop row
starttime beginning of the time range (unixtime in millis)
without endtime means from starttime to forever
endtime end of the time range. Ignored if no starttime specified.
versions number of cell versions to copy
new.name new table's name
peer.adr Address of the peer cluster given in the format
hbase.zookeeer.quorum:hbase.zookeeper.client.port:zookeeper.znode.parent
families comma-separated list of families to copy
To copy from cf1 to cf2, give sourceCfName:destCfName.
To keep the same name, just give "cfName"
all.cells also copy delete markers and deleted cells Args:
tablename Name of the table to copy Examples:
To copy 'TestTable' to a cluster that uses replication for a 1 hour window:
$ bin/hbase org.apache.hadoop.hbase.mapreduce.CopyTable --starttime=1265875194289 --endtime=1265878794289 --peer.adr=server1,server2,server3:2181:/hbase --families=myOldCf:myNewCf,cf2,cf3 TestTable For performance consider the following general options:
It is recommended that you set the following to >=100. A higher value uses more memory but
decreases the round trip time to the server and may increase performance.
-Dhbase.client.scanner.caching=100
The following should always be set to false, to prevent writing data twice, which may produce
inaccurate results.
-Dmapred.map.tasks.speculative.execution=false

一些示例

hbase org.apache.hadoop.hbase.mapreduce.CopyTable –starttime=1478448000000 –endtime=1478591994506 –peer.adr=VECS00001,VECS00002,VECS00003:2181:/hbase –families=txjl –new.name=hy_membercontacts_bk  hy_membercontacts

#根据时间范围备份
hbase org.apache.hadoop.hbase.mapreduce.CopyTable –starttime=1478448000000 –endtime=1478591994506 –new.name=hy_membercontacts_bk hy_membercontacts
hbase org.apache.hadoop.hbase.mapreduce.CopyTable –starttime=1477929600000 –endtime=1478591994506 –new.name=hy_linkman_tmp hy_linkman #备份全表
hbase org.apache.hadoop.hbase.mapreduce.CopyTable –new.name=hy_mobileblacklist_bk_before_del hy_mobileblacklist #拓展根据时间范围查询
scan ‘hy_linkman’, {COLUMNS => ‘lxr:sguid’, TIMERANGE => [1478966400000, 1479052799000]}
scan ‘hy_mobileblacklist’, {COLUMNS => ‘mobhmd:sguid’, TIMERANGE => [1468719824000, 1468809824000]}
hbase org.apache.hadoop.hbase.mapreduce.CopyTable –new.name=hy_mobileblacklist_bk_before_del_20161228 hy_mobileblacklist

三、Export/Import(使用mapreduce)

Export 执行导出命令

可使用-D命令自定义参数,此处限定表名、列族、开始结束RowKey、以及导出到HDFS的目录

hbase org.apache.hadoop.hbase.mapreduce.Export -D hbase.mapreduce.scan.column.family=cf -D hbase.mapreduce.scan.row.start=0000001 -D hbase.mapreduce.scan.row.stop=1000000 table_name /tmp/hbase_export

可选的-D参数配置项

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
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

Import 执行导入命令

必须在导入前存在表

create 'table_name','cf'

运行导入命令

hbase org.apache.hadoop.hbase.mapreduce.Import table_name hdfs://flashhadoop/tmp/hbase_export/

可选的-D参数配置项

Usage: Import [options] <tablename> <inputdir>

By default Import will load data directly into HBase. To instead generate
HFiles of data to prepare for a bulk data load, pass the option:
-Dimport.bulk.output=/path/for/output
To apply a generic org.apache.hadoop.hbase.filter.Filter to the input, use
-Dimport.filter.class=<name of filter class>
-Dimport.filter.args=<comma separated list of args for filter
NOTE: The filter will be applied BEFORE doing key renames via the HBASE_IMPORTER_RENAME_CFS property. Futher, filters will only use the Filter#filterRowKey(byte[] buffer, int offset, int length) method to identify whether the current row needs to be ignored completely for processing and Filter#filterKeyValue(KeyValue) method to determine if the KeyValue should be added; Filter.ReturnCode#INCLUDE and #INCLUDE_AND_NEXT_COL will be considered as including the KeyValue.
For performance consider the following options:
-Dmapred.map.tasks.speculative.execution=false
-Dmapred.reduce.tasks.speculative.execution=false
-Dimport.wal.durability=<Used while writing data to hbase. Allowed values are the supported durability values like SKIP_WAL/ASYNC_WAL/SYNC_WAL/...>

四、Snapshot

即为Hbase 表的镜像。

需要提前开启Hbase 集群的snapshot 功能。

<property>
<name>hbase.snapshot.enabled</name>
<value>true</value>
</property>

在hbase shell中使用clone_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot命令可是是想创建快照,查看快照,通过快照恢复表,通过快照创建一个新的表等功能,

在创建snapshot后,可以通过ExportSnapshot工具把快照导出到另外一个集群,实现数据备份或者数据迁移,ExportSnapshot工具的用法如下:(必须为推送的方式,即从现集群到目的集群)

hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot table_name_snapshot -copy-to hdfs://flashhadoop_2/hbase -mappers 2

执行该命令后,在flashhadoop_2的hdfs中会把table_name_snapshot文件夹copy到/hbase/.hbase-snapshot文件下,进入flashhadoop_2这个hbase集群,执行list_snapshots会看到有一个快照:table_name_snapshot,通过命令clone_snapshot可以把该快照copy成一个新的表,不用提前创建表,新表的region个数等信息完全与快照保持一致。也可以先创建一张与原表相同的表,然后通过restore snapshot的方式恢复表,但会多出一个region.这个region 将会失效。

在使用snapshot把一个集群的数据copy到新集群后,应用程序开启双写,然后可以使用Export工具把快照与双写之间的数据导入到新集群,从而实现数据迁移,为保障数据不丢失,Export导出时指定的时间范围可以适当放宽。

五、Replication

可以通过replication机制实现hbase集群的主从模式,或者可以说主主模式,也就是两边都做双向同步,具体步骤如下:

1、 如果主从hbase集群共用一个zk集群,则zookeeper.znode.parent不能都是默认的hbase,可以配置为hbase-master和hbase-slave,总之在zk 中的znode节点命名不能冲突。

2,在主,从hbase集群的hbase-site.xml中添加配置项:(其实做主从模式的话,只需要将从集群hbase.replication设置为true 即可,其他可以忽略。)

<property>
<name>hbase.replication</name>
<value>true</value>
</property> <property>
<name>replication.source.nb.capacity</name>
<value>25000</value>
<description>主集群每次向从集群发送的entry最大的个数,默认值25000,可根据集群规模做出适当调整</description>
</property> <property>
<name>replication.source.size.capacity</name>
<value>67108864</value>
<description>主集群每次向从集群发送的entry的包的最大值大小,默认为64M</description>
</property> <property>
<name>replication.source.ratio</name>
<value>1</value>
<description>主集群使用的从集群的RS的数据百分比,默认为0.1,1.X.X版本默认0.15,需调整为1,充分利用从集群的RS</description>
</property> <property>
<name>replication.sleep.before.failover</name>
<value>2000</value>
<description>主集群在RS宕机多长时间后进行failover,默认为2秒,具体的sleep时间是: sleepBeforeFailover + (long) (new Random().nextFloat() * sleepBeforeFailover) </description>
</property> <property>
<name>replication.executor.workers</name>
<value>1</value>
<description>从事replication的线程数,默认为1,如果写入量大,可以适当调大</description>
</property>
3,重启主从集群,新集群搭建请忽略重启,直接启动即可。
4,分别在主从集群hbase shell中
add_peer 'ID' 'CLUSTER_KEY'

The ID must be a short integer. To compose the CLUSTER_KEY, use the following template:

hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent

This will show you the help to setup the replication stream between both clusters. If both clusters use the same Zookeeper cluster, you have to use a different zookeeper.znode.parent since they can't write in the same folder.

1,

增加主Hbase 到容灾 Hbase 数据表 同步
add_peer '1', "VECS00840,VECS00841,VECS00842,VECS00843,VECS00844:2181:/hbase"

2,

增加容灾Hbase 到主 Hbase 数据表 同步
add_peer '2', "VECS00994,VECS00995,VECS00996,VECS00997,VECS00998:2181:/hbase"

3,然后在主,备集群建表结构,属性完全相同的表。(注意,是完全相同)

主从集群都建立。
hbase shell>
create 't_warehouse_track', {NAME => 'cf', BLOOMFILTER => 'ROW', VERSIONS => '3', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}

4,在主集群hbase shell

enable_table_replication 't_warehouse_track'

5,在容灾集群hbase shell

disable 'your_table'
alter 'your_table', {NAME => 'family_name', REPLICATION_SCOPE => '1'}
enable 'your_table 此处的REPLICATION_SCOPE => '1'中的1,与第3步中设置到“ID”无关系,这个值只有0或者1,标示开启复制或者关闭。

Hbase数据备份&&容灾方案的更多相关文章

  1. hbase数据备份或者容灾方案

    HBase的数据备份或者容灾方案有这几种:Distcp,CopyTable,Export/Import,Snapshot,Replication,以下分别介绍(以下描述的内容均是基于0.94.20版本 ...

  2. [Hbase]Hbase容灾方案

    介绍两种HBase的数据备份或者容灾方案:Snapshot,Replication: 一.Snapshot 开启快照功能,在hbase-site.xml文件中添加如下配置项: <property ...

  3. 利用HDFS实现ElasticSearch7.2容灾方案

    利用HDFS实现ElasticSearch7.2容灾方案 目录 利用HDFS实现ElasticSearch7.2容灾方案 前言 快照版本兼容 备份集群 HDFS文件系统 软件下载 JDK环境 配置系统 ...

  4. centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾

    centos6.5环境通过shell脚本备份php的web及mysql数据库并做远程备份容灾 系统:centos6.5 1.创建脚本目录 mkdir -p /usr/local/sh/ 创建备份web ...

  5. 数据备份与恢复 半持久化 全持久化 fork aof rdb Backing up Disaster recovery 备份 容灾

    Redis数据备份与恢复 - 流年晕开时光 - 博客园 https://www.cnblogs.com/deny/p/11531355.html Redis数据备份与恢复 Redis所有数据都是保存在 ...

  6. MongDB集群容灾方案步骤

    MongoDB复制集优/特点支持大数据量.高扩展性.高性能.灵活数据模型.高可用性.同步机制数据复制的目的是使数据得到最大的可用性,避免单点故障引起的整站不能访问的情况的发生,Mongodb的副本集在 ...

  7. HBase数据备份及恢复(导入导出)的常用方法

    一.说明 随着HBase在重要的商业系统中应用的大量增加,许多企业需要通过对它们的HBase集群建立健壮的备份和故障恢复机制来保证它们的企业(数据)资产.备份Hbase时的难点是其待备份的数据集可能非 ...

  8. mysqldump备份容灾脚本

    目录 一.备份脚本 环境需求 全量脚本 增量脚本 二.备份策略 三.容灾测试 准备 测试 误删除 一.备份脚本 环境需求 编辑/etc/my.cnf文件添加在[mysqld]版块下添加如下变量,添加后 ...

  9. 【亲述】Uber容错设计与多机房容灾方案 - 高可用架构系列

    此文是根据赵磊在[QCON高可用架构群]中的分享内容整理而成.转载请事先联系赵磊及相关编辑. 赵磊,Uber高级工程师,08年上海交通大学毕业,曾就职于微软,后加入Facebook主要负责Messen ...

随机推荐

  1. 数据库(一):suse下MySQL安装

    1.准备工作从MySQL官网上分别下载mysql服务器端于客户端包:MySQL-server-5.5.31-1.linux2.6.x86_64.rpmMySQL-client-5.5.31-1.lin ...

  2. (转)linux chattr lsattr 命令

    转http://www.ha97.com/5172.html PS:有时候你发现用root权限都不能修改某个文件,大部分原因是曾经用chattr命令锁定该文件了.chattr命令的作用很大,其中一些功 ...

  3. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project kircp-js-plan-resource: The packaging for this project did not assign a file to the bu

    结合网上的相关资料,要使用Lifecycle下的install 原因好像是Lifecycle下才会走Maven完整的phase.

  4. 脚本_查看当前系统每个IP的连接数

    #!bin/bash#作者:liusingbon#功能:查看当前系统每个IP的连接数netstat -n | awk '/^tcp/ {print $5}'| awk -F: '{print $1}' ...

  5. iotop发现jdb2/sdb1-8 io使用过高解决办法

    一.现象 [root@push-- ~]# iotop otal DISK READ: 0.00 B/s | Total DISK WRITE: 6.26 M/s TID PRIO USER DISK ...

  6. 关于FileChannel的获取方式之open方法详解

    FileChannel.open(Path path, OpenOption... options); 例子使用JDK1.8 FileChannel open方法源码: public static F ...

  7. (转) 修改weblogic部署的应用名称

    通过weblogic管理后台console进行发布本地项目的时候,它会默认以WEB-INF的上一级目录作为访问路径, 如,假如你的项目WEB-INF目录的上一层是WebRoot,那么发布后, 访问的路 ...

  8. zencart后台订单详细页显示产品图片和链接

    方法一: 找到admin/order.php 大约491行 for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { 与 if (iss ...

  9. map1

    map2.insert(make_pair("sale", 1)); map2.count("development");//key为development的数 ...

  10. [易学易懂系列|rustlang语言|零基础|快速入门|(6)|变量绑定]

    [易学易懂系列|rustlang语言|零基础|快速入门|(6)] 有意思的基础知识 变量绑定 我们现在回过头来看看,一些基础知识. 因为理解了前面的重要概念:所有权,借用,生命周期. 我们现在看基础知 ...