Skip to main content

Syncing Hadoop Clusters Safely Using Modern DistCp and Retention Workflows

This updated guide shows how to synchronize data between Hadoop clusters using modern DistCp practices, HA NameNode paths, correct retention handling, and safe permissions. It modernizes a legacy 2011 workflow into a reliable daily rebase pattern for development and staging clusters without overloading production systems.

When developing new pipelines, it is often necessary to rebase a development or staging Hadoop environment with data from production. Historically this was done with simple DistCp scripts. Today, DistCp v2, YARN scheduling, and improved HDFS tooling allow for safer, more performant cluster synchronization while avoiding operational pitfalls.

Below is an updated version of a classic rebase workflow: copying the previous day's log data from a production cluster to a development cluster and applying retention by removing older datasets.

1. Variables and runtime setup

COPYDATE=$(date -d '-1 day' +"%Y-%m-%d")
DELDATE=$(date -d '-3 day' +"%Y-%m-%d")

SRC_NN="hdfs://prod-nn-ha"
TGT_NN="hdfs://dev-nn-ha"
PATH="/user/flume/logs"

LOG="/var/log/jobs/distcp-sync.log"

# Logging redirection
exec >> "$LOG" 2>&1

echo -e "\n------- sync $COPYDATE -------\n"

A modern best practice is to reference HA nameservices (e.g., hdfs://prod-nn-ha) instead of single hostnames. This supports automatic failover and avoids outages during DistCp operations.

2. Modern DistCp execution

Legacy DistCp used -i and -m <maps>. DistCp v2 adds a number of new controls:

  • -update – copy only changed files
  • -delete – remove files on the target that no longer exist on the source
  • -bandwidth – throttle bandwidth to avoid saturating production
  • -strategy dynamic – improved load balancing for large file trees
hadoop distcp \
  -update \
  -bandwidth 100 \
  -strategy dynamic \
  ${SRC_NN}${PATH}/${COPYDATE} \
  ${TGT_NN}${PATH}/${COPYDATE}/

Adjust -bandwidth based on your production cluster's capacity. In busy environments, using the YARN queue configuration to limit DistCp resource usage is strongly recommended.

3. Retention: remove datasets older than 3 days

In the original workflow, logs older than 3 days were deleted. Modern HDFS commands replace deprecated flags:

echo -e "\n------- delete $DELDATE -------\n"

hdfs dfs -rm -r -skipTrash ${PATH}/${DELDATE}
hdfs dfs -rm -r -skipTrash ${PATH}/_distcp_logs*

If you run DistCp frequently, consider storing DistCp logs elsewhere or cleaning them through automated retention to avoid clutter.

4. Permissions handling (modernized)

The legacy script used chmod -R 777 to accommodate missing users in the dev cluster. This is unsafe and not recommended.

Modern alternatives:

  • Create the correct user or group in the target cluster (flume in this case)
  • Use setfacl to grant dev teams access without breaking security
  • Set directory ownership appropriately:
hdfs dfs -chown -R flume:hadoop ${PATH}/

This keeps both clusters consistent and avoids privilege escalation.

5. Scheduling & execution time

The original workflow ran daily via cron at 02:00 PM and processed ~1 TB in about an hour. Today's clusters often run DistCp using YARN queues and resource limits:

  • Assign DistCp to a low-impact queue (e.g., utility or offpeak)
  • Throttle bandwidth using the -bandwidth flag
  • Use snapshots to create consistent sources for large directories

Example snapshot-based DistCp (production-safe):

hdfs dfs -createSnapshot /user/flume/logs snapshot_${COPYDATE}

hadoop distcp \
  -update \
  ${SRC_NN}/user/flume/logs/.snapshot/snapshot_${COPYDATE} \
  ${TGT_NN}/user/flume/logs/${COPYDATE}

Snapshots ensure dataset consistency even while ingestion continues.

6. Hybrid cloud & object storage notes

In modern environments, clusters often sync to or from S3, GCS, ADLS or MinIO. DistCp supports these paths directly through s3a://, gs://, and abfs:// URLs. For very large directory trees, S3DistCp (AWS EMR) or DistCp on Kubernetes with scalable containers may be used.

Conclusion

DistCp remains the canonical tool for moving large datasets between Hadoop clusters. By combining modern DistCp features, HA name services, safe retention policies, snapshots, strict permissions, and YARN queue isolation, you can maintain a reliable daily rebase workflow that does not interfere with production operations.

Reference

Official DistCp documentation: https://hadoop.apache.org/docs/stable/hadoop-distcp/DistCp.html

If you need help with distributed systems, backend engineering, or data platforms, check my Services.

Most read articles

Why Is Customer Obsession Disappearing?

Many companies trade real customer-obsession for automated, low-empathy support. Through examples from Coinbase, PayPal, GO Telecommunications and AT&T, this article shows how reliance on AI chatbots, outsourced call centers, and KPI-driven workflows erodes trust, NPS and customer retention. It argues that human-centric support—treating support as strategic investment instead of cost—is still a core growth engine in competitive markets. It's wild that even with all the cool tech we've got these days, like AI solving complex equations and doing business across time zones in a flash, so many companies are still struggling with the basics: taking care of their customers. The drama around Coinbase's customer support is a prime example of even tech giants messing up. And it's not just Coinbase — it's a big-picture issue for the whole industry. At some point, the idea of "customer obsession" got replaced with "customer automation," and no...

What are the performance implications of cross-platform execution within Wayang?

Apache Wayang ® enables cross-platform execution across multiple data processing platforms such as Spark, Flink, Java Streams, PostgreSQL or GraphChi. This capability fundamentally changes the performance behavior of distributed data pipelines. Wayang reduces manual data movement by selecting where each operator should run, but crossing platform boundaries still introduces serialization cost, shifts in locality, different memory strategies and new tuning constraints. Understanding these dynamics is essential before adopting Wayang for multi-platform pipelines at scale. Apache Wayang is a cross-platform data processing framework that lets developers run a single logical pipeline across engines such as Apache Spark, Apache Flink or a native Java backend. It provides an abstraction layer and a cost-based optimizer that selects the execution platform for each operator. This flexibility introduces new performance variables that do not exist in single-engine systems. Engine boundaries ...

What the Heck is Superposition and Entanglement?

This post is about superposition and interference in simple, intuitive terms. It describes how quantum states combine, how probability amplitudes add, and why interference patterns appear in systems such as electrons, photons and waves. The goal is to give a clear, non mathematical understanding of how quantum behavior emerges from the rules of wave functions and measurement. If you’ve ever heard the words superposition or entanglement thrown around in conversations about quantum physics, you may have nodded politely while your brain quietly filed them away in the "too confusing to deal with" folder.  These aren't just theoretical quirks; they're the foundation of mind-bending tech like Google's latest quantum chip, the Willow with its 105 qubits. Superposition challenges our understanding of reality, suggesting that particles don't have definite states until observed. This principle is crucial in quantum technologies, enabling phenomena like quantum comp...