The HBase snapshot feature allows you to obtain lightweight backup of tables with minimal impact on performance. You can create, import, or export snapshots on an E-MapReduce (EMR) cluster that contains the HBase service by using HBase Shell or command lines. You can use the snapshots to create new tables or restore table data. This topic describes how to use HBase snapshots.
Create a snapshot
Run the hbase shell command to connect to HBase. For more information, see the Connect to HBase section of the "Use HBase Shell" topic. After you connect to HBase, run the following command to create a snapshot named table1-snapshot for table1: You can configure the SKIP_FLUSH, TTL, or MAX_FILESIZE parameter in the snapshot command to add limits based on your business requirements.
snapshot 'table1', 'table1-snapshot'The snapshot name must be unique. You can run the list_snapshots command to view all existing snapshots.
Create a table by cloning a snapshot
You can run the clone_snapshot command to clone a snapshot to create a table that contains the same data as the snapshot.
For example, after you run the hbase shell command to connect to HBase, you can run the following command to create a table named table2 from table1-snapshot:
clone_snapshot 'table1-snapshot', 'table2'Restore table data by using a snapshot
You can run the restore_snapshot command to restore the table data at the time when the snapshot is created. Before you use a snapshot to restore table data, you must disable the table.
For example, after you run the hbase shell command to connect to HBase, you can run the following commands to disable table1, restore data in table1 by using table1-snapshot, and re-enable table1.
disable 'table1'
restore_snapshot 'table1-snapshot'
enable 'table1'Import a snapshot
You can use the command line to import HBase snapshots in other paths. When you import a snapshot, you must specify the name and the source path of the snapshot, the destination address to save the snapshot, and the number of mappers for the import task.
For example, you can run the following command to import a snapshot from the OSS-HDFS service of a DataServing cluster to the OSS-HDFS service of another DataServing cluster:
hbase snapshot export \
-snapshot 'table1-snapshot' \
-copy-from oss://${Endpoint of the OSS-HDFS service}/oss-dir \
-copy-to oss://${Endpoint of the OSS-HDFS service}/hbase \
-mappers 2Parameter | Description |
| The name of the snapshot to be imported. Example: table1-snapshot. |
| The source address of the snapshot to be imported and the destination address to save the snapshot. You can copy the endpoint of the OSS-HDFS service in the Port section of the Overview page of your bucket in the Object Storage Service (OSS) console. For more information, see the Procedure section of the "Use OSS-HDFS as the storage backend of HBase" topic. |
| |
| The number of mappers for the import task. In this example, this parameter is set to 2. Important If you do not configure this parameter when you import snapshots, HBase calculates the value based on the table size. If the value is excessively large, the tasks that are running in HBase are affected. We recommend that you configure the |
Export a snapshot
You can use the command line to export snapshots from a cluster to the Hadoop Distributed File System (HDFS) or OSS-HDFS service of another cluster. When you export a snapshot, you must specify the name and the destination path of the snapshot to be exported, and the number of mappers for the export task.
For example, you can run the following command to export table1-snapshot from the current cluster to the OSS-HDFS service of another cluster: If you want to export a snapshot to the HDFS service of another cluster, you must set the -copy-to parameter to the corresponding HDFS path.
hbase snapshot export \
-snapshot 'table1-snapshot' \
-copy-to oss://${Endpoint of the OSS-HDFS service}/oss-dir \
-mappers 2Delete a snapshot
After you run the hbase shell command to connect to HBase, you can run the following command to delete table1-snapshot:
delete_snapshot 'table1-snapshot'References
For more information, see Apache HBase Reference Guide on the official website of Apache HBase.