Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 36 ยท Administration and Tuning

Backup, Snapshots and Replication

Protect HBase data with snapshots, ExportSnapshot, CopyTable, replication and incremental backup, and understand how cheap snapshots work with a runnable model.

HDFS keeps three copies of every block, but that protects against disk and server failures, not against mistakes: a bad deploy that overwrites data, an accidental truncate, a corrupted application write. HBase gives you several tools for real backups and for keeping a second cluster in step: snapshots, export, replication and, in recent versions, incremental backup.

HBase cannot run in the live editors. Shell commands are read-only. The runnable Java blocks model why snapshots are cheap and how replication ships edits, labelled as models.

Snapshots

A snapshot records the metadata of a table at one moment: the list of HFiles that make up each region. It does not copy any data, so it is nearly instant and costs almost no space at first. Because HFiles are immutable, the files a snapshot refers to cannot change; compaction writes new files, and the old files are kept in the archive while a snapshot still references them.

TEXT
snapshot 'events', 'events_2026_11_12'          # take a snapshot (table can stay online)
list_snapshots
clone_snapshot 'events_2026_11_12', 'events_copy'   # new table sharing the files
restore_snapshot 'events_2026_11_12'            # roll the table back (disable it first)
delete_snapshot 'events_2026_11_12'
  • clone_snapshot creates a new, writable table from a snapshot. It is the easy way to test something against real data without touching production.
  • restore_snapshot returns the original table to the snapshot state, so the table must be disabled first.
  • By default the snapshot type is flush: it flushes MemStores first, so recent writes are included. A SKIP_FLUSH snapshot takes only what is already in HFiles.
  • Snapshots are consistent per region, but not transactionally across regions; writes during the snapshot may be seen in some regions and not others.
Java Why snapshots are cheap (model)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

The snapshot is just a list of file names. The compaction after the bad write produced a new file, but the old files stayed in the archive because the snapshot refers to them, so the restore returns the old values.

Moving snapshots between clusters: ExportSnapshot

ExportSnapshot is a MapReduce job that copies the snapshot's HFiles and metadata to another HDFS or object store at file level, bypassing the region servers:

TEXT
hbase org.apache.hadoop.hbase.snapshot.ExportSnapshot \
  -snapshot events_2026_11_12 \
  -copy-to hdfs://backup-cluster:8020/hbase \
  -mappers 16 -bandwidth 200

It is the usual approach for off-site backups and for copying a table to a test cluster. Because it copies files, the load on the source region servers is small; throttle with -bandwidth (MB/s). On the target, run clone_snapshot or restore_snapshot.

Other copy tools

  • CopyTable: a MapReduce job that scans a table and writes it to another table or cluster. Slower and heavier than snapshots because it goes through the normal read and write path, but it can copy a row range or time range.
  • Export / Import: dump a table's cells to sequence files on HDFS and load them back.
  • CellCounter, RowCounter, VerifyReplication: validate copies and count data.

Replication

Replication streams every write of a table from a source cluster to one or more peer clusters, asynchronously, using the WAL. Uses: disaster recovery, a read-only analytics cluster, geographic distribution, migrating clusters.

TEXT
add_peer 'dc2', CLUSTER_KEY => 'zk1.dc2,zk2.dc2,zk3.dc2:2181:/hbase'
alter 'events', {NAME => 'd', REPLICATION_SCOPE => 1}      # replicate family d
list_peers
  • Replication is per column family (REPLICATION_SCOPE => 1), and is asynchronous: the peer is eventually consistent and lags by seconds under normal load.
  • The source ships WAL edits; the peer applies them as ordinary writes. Both directions (master-master) are possible; concurrent writes to the same cell are resolved by timestamp, so avoid writing the same rows in both clusters.
  • Data written before replication was enabled is not copied: bootstrap the peer first with a snapshot export.
  • Check consistency with VerifyReplication.
  • Recent HBase versions have serial replication (preserves per-row order when regions move) and a "sync replication" mode for stronger disaster-recovery guarantees, at the cost of write latency.
flowchart LR
  C["Clients"] --> S["Source cluster"]
  S -->|"WAL edits (async)"| P["Peer cluster"]
  S -->|"ExportSnapshot"| B["Backup storage"]

Replication is continuous and asynchronous; snapshots are point-in-time copies you can keep.

Java Asynchronous replication lag (model)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

At some ticks the peer is missing recent edits (the lag), and it catches up once the queue drains.

A backup plan that works

  1. Take regular snapshots (daily or hourly) with a retention policy; keep them on the same cluster for fast restores.
  2. Export snapshots to a separate system (another cluster or object storage) for real disaster protection.
  3. Use replication for a hot standby if you need a low recovery time.
  4. Test restores. An untested backup is a hope.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is taking a snapshot almost instant?

    HFiles are immutable, so a snapshot just references the current file list.
  2. 2. What does clone_snapshot do?

    clone_snapshot makes a new table sharing the files, good for testing on real data.
  3. 3. How does HBase replication behave?

    Replication ships WAL edits asynchronously, so the peer lags slightly.
  4. 4. Which tool copies a snapshot to another cluster at the file level?

    ExportSnapshot is a MapReduce job that copies the snapshot's HFiles and metadata to another filesystem.

Summary

  • Snapshots are cheap metadata-only, point-in-time table states; clone and restore build on them.
  • ExportSnapshot moves them to another cluster or storage; CopyTable/Export are heavier alternatives.
  • Replication is per-family, asynchronous and WAL-based; bootstrap peers with a snapshot.
  • Keep off-cluster copies and test restores.

Next: HBase with MapReduce, Spark and Hive