Backup Strategy: Snapshots, distcp and Protecting Metadata
Replication Is Not Backup
Common mistake: Three HDFS replicas protect against disk and node failure. They do not protect against accidental deletes, bad jobs that overwrite data, software bugs, ransomware or a whole-site disaster. You need real backups.
What to Back Up
| Item | Method | Frequency |
|---|---|---|
| Business data in HDFS | Snapshots plus distcp to another cluster or object storage | Daily incremental |
| NameNode metadata (fsimage) | hdfs dfsadmin -fetchImage off-host | Daily |
| Hive metastore database | pg_dump / mysqldump plus DB replication | Daily + binlog/WAL |
| Ranger policies and DB | Policy export (JSON) plus DB dump | Daily |
| KMS keys | Encrypted copy of keystore, offline copy of master key | On change |
| Configuration | Git repository and manager exports | On every change |
| HBase tables | Snapshots + ExportSnapshot / replication | Daily |
| Kafka topics | Replication (MirrorMaker 2) to another cluster | Continuous |
| Kerberos KDC database | kdb5_util dump | Daily |
Define RPO and RTO
| Term | Meaning | Example |
|---|---|---|
| RPO (Recovery Point Objective) | How much data you can lose | 24 hours for logs, 1 hour for transactions |
| RTO (Recovery Time Objective) | How long you can be down | 4 hours for reporting, 15 minutes for serving |
Ask data owners to classify data (gold, silver, bronze) so you do not back up scratch data at the same level as financial data.
Snapshot Schedule
bash
# cron on an admin host, using a keytab for hdfs
D=$(date +%Y%m%d)
for p in /data/finance /data/sales /warehouse/tablespace/external/hive; do
hdfs dfs -createSnapshot $p daily-$D
# keep 14 days
OLD=$(date -d "14 days ago" +%Y%m%d)
hdfs dfs -deleteSnapshot $p daily-$OLD 2>/dev/null
done
Backup to Another Cluster with distcp
DistCp copies data using a MapReduce job, in parallel, from many nodes.
bash
# full copy first time
hadoop distcp -update -p -m 50 -bandwidth 100 \
hdfs://prod/data/finance hdfs://backup/data/finance
# -update: copy only changed files -p: preserve ownership, permissions, replication...
# -m: number of mappers -bandwidth: MB/s per mapper
# -skipcrccheck if block sizes differ, -delete removes extra files on the target
Incremental distcp with Snapshot Diff
bash
# 1. first full copy from snapshot s1, then snapshot the target with the SAME name
hadoop distcp -update -p hdfs://prod/data/finance/.snapshot/s1 hdfs://backup/data/finance
hdfs dfs -createSnapshot hdfs://backup/data/finance s1
# 2. next day: create snapshot s2 on the source, copy only the differences
hdfs dfs -createSnapshot /data/finance s2
hadoop distcp -update -diff s1 s2 -p hdfs://prod/data/finance hdfs://backup/data/finance
hdfs dfs -createSnapshot hdfs://backup/data/finance s2
Why this is great:
-diff copies only files that changed between two snapshots (including renames and deletes), so the job runs in minutes instead of rescanning billions of files. The target must be unchanged since the matching snapshot.
Backup to Object Storage
bash
hadoop distcp -update -m 40 -bandwidth 50 hdfs://prod/data/finance s3a://corp-backup/prod/finance/
# credentials: use IAM roles or Hadoop credential providers, never access keys in commands
Verify Backups
- Compare counts and sizes:
hdfs dfs -count -von source snapshot and target - Compare checksums with
distcp(CRC check enabled by default) orhdfs dfs -checksum - Check the job's counters:
BYTESSKIPPED,FILES_FAILED - Alert if a backup does not finish or is older than the RPO
bash
hdfs dfs -count -v hdfs://prod/data/finance/.snapshot/s2 hdfs://backup/data/finance
hdfs dfs -checksum hdfs://prod/data/finance/.snapshot/s2/part-0001 ; hdfs dfs -checksum hdfs://backup/data/finance/part-0001
Restore Procedures
| Case | Restore |
|---|---|
| User deleted a file | Copy from .snapshot/<name> or .Trash |
| Directory overwritten | distcp from the snapshot back |
| Cluster lost | Build new cluster, restore metastore DB and configs, distcp data back from backup cluster |
| Metastore DB lost | Restore dump, point HMS to it, run MSCK REPAIR if needed |
| NameNode metadata lost | Use HA copy or the fetched fsimage, see the metadata lesson |
A backup that has never been restored is only a hope: Schedule a restore test every quarter: restore a sample dataset and the metastore into a test environment and check that queries work.
Protect the backup too: Use a different security domain and credentials, immutable snapshots or object lock, and restrict who can delete backups. Ransomware targets backups first.
Conclusion
Replication is not backup. Back up data, metadata, databases, keys and configs, use snapshots with incremental distcp, define RPO and RTO, verify, and test restores regularly.
Quick Summary: snapshots + distcp -diff; fetchImage; DB dumps; test restores.

