Skip to main content

Syncing Hadoop Clusters Safely Using Modern DistCp and Retention Workflows

Struggling with delivery, architecture alignment, or platform stability?

I help teams fix systemic engineering issues: processes, architecture, and clarity.
→ See how I work with teams.


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

Building a Model-Agnostic Multi-Agent System with OpenClaw

Over one week we rebuilt our AI stack around OpenClaw’s multi-agent architecture to avoid provider lock-in and stop wasting premium tokens. By aligning models to tasks, diversifying fallbacks across providers, enforcing minimal tool access, and switching to memory-first workflows with ephemeral sessions, we reduced token usage per task by about 70% and cut our monthly bill by 77% while improving operational resilience. How We Achieved 77% Cost Reduction and Provider Independence Over the past week, we rebuilt our AI infrastructure around OpenClaw’s multi-agent architecture. The result was a 77% cost reduction , provider independence , and a delegation system that routes work to the most cost-effective model for each job. Below is the technical journey of optimizing a 7-agent squad with OpenClaw. The Challenge: Model Provider Lock-In We started with a simple problem: our entire squad defaulted to a single model provider. This created three issues: Cost inefficiency beca...

BacNet => MQTT in Production: The Real Cost of Bridging BACnet to MQTT at Scale

bacnet2mqtt looks simple in a README and expensive in production. Once BACnet polling, reconnection behavior, stale state, and MQTT publishing collide, teams discover they are not deploying a lightweight adapter but operating infrastructure. This article breaks down where bacnet2mqtt works, where it becomes a bottleneck, and which production patterns reduce the operational damage before incidents, backlogs, and silent data loss turn a building integration into a long-running engineering problem. I inherited a building controls integration problem 18 months ago. Three office floors. 217 BACnet sensors covering temperature, occupancy, and HVAC actuators. The data was trapped inside the building automation network while the business wanted analytics, reporting, and compliance visibility in the data platform. The obvious answer looked easy enough: deploy bacnet2mqtt, bridge BACnet into MQTT, and push the stream into the lakehouse stack. The repository made it sound like a w...

Connect BACnet to the Cloud with bacnet-mqtt-gateway

The bacnet-mqtt-gateway project is an open source protocol bridge that translates BACnet building automation traffic into MQTT messages for cloud and IoT systems. It provides discovery, polling, bidirectional writes, APIs, security, and easy deployment via Docker. Many enterprises struggle to unify BACnet with modern data pipelines and cloud platforms because BACnet is local-network only and not cloud ready. This gateway provides a scalable, secure, production-ready adapter for MQTT ecosystems and smart building integrations. The Problem with BACnet Building automation runs on BACnet . HVAC controllers, lighting systems, metering equipment: they all speak ASHRAE 135 . The protocol handles local control loops well. It fails at cloud ingress. BACnet relies on UDP broadcasts. These do not route over the internet or into VPCs. Your chiller controller cannot talk to AWS IoT Core . Your VAV box cannot publish to an MQTT broker. The air gap between operational technology and modern cl...