HBase Snapshots

HBase Snapshots

PHD 3.0

HBase Snapshots

HBase Snapshots allow you to take a snapshot of a table without much impact on Region Servers. Snapshot, Clone and restore operations don't involve data copying. In addition, exporting a snapshot to another cluster doesn't have impact on Region Servers.

Configuration

To turn on snapshot support, set the hbase.snapshot.enabled property to true. (Snapshots are enabled by default in 0.95+, and are off by default in 0.94.6+.)

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

Take a Snapshot

You can take a snapshot of a table regardless of whether it is enabled or disabled. The snapshot operation doesn't involve any data copying. As shown in the following example, start the HBase shell, and then clone the table:

$ hbase shell hbase> snapshot 'myTable', 'myTableSnapshot-122112'

List Snapshots

List all snapshots taken (by printing the names and relative information).

$ hbase shell hbase> list_snapshots

Delete Snapshots

You can remove a snapshot, and the files associated with that snapshot will be removed if they are no longer needed.

$ hbase shell hbase> delete_snapshot 'myTableSnapshot-122112'

Clone a Table from a Snapshot

From a snapshot you can create a new table (clone operation) with the same data that you had when the snapshot was taken. The clone operation doesn't involve data copies. A change to the cloned table doesn't impact the snapshot or the original table.

$ hbase shell hbase> clone_snapshot 'myTableSnapshot-122112', 'myNewTestTable'

Restore a Snapshot

The restore operation requires the table to be disabled, and the table will be restored to the state at the time when the snapshot was taken, changing both data and schema if required.

$ hbase shell hbase> disable 'myTable' hbase> restore_snapshot 'myTableSnapshot-122112'

Snapshot Operations and ACLs

If you are using security with the AccessController Coprocessor, only a global administrator can take, clone, or restore a snapshot. None of these actions capture ACL rights. Restoring a table preserves the ACL rights of the existing table, while cloning a table creates a new table that has no ACL rights until the administrator adds them.

Export to Another Cluster

The ExportSnapshot tool copies all the data related to a snapshot (hfiles, logs, snapshot metadata) to another cluster. The tool executes a Map-Reduce job, similar to distcp, to copy files between the two clusters. Because it works at file system level, the HBase cluster does not have to be online. The HBase Snapshot Export tool must be run as hbase user. The HBase Snapshot Export tool uses the temp directory specified by hbase.tmp.dir (for example, /grid/0/var/log/hbase), created on HDFS with hbase user as the owner.

To copy a snapshot called MySnapshot to an HBase cluster srv2 (hdfs://srv2:8020/hbase) using 16 mappers:

$ hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot -snapshot MySnapshot -copy-to hdfs://yourserver:8020/hbase_root_dir -mappers 16