0
0
Hadoopdata~5 mins

Backup and disaster recovery in Hadoop

Choose your learning style9 modes available
Introduction

Backup and disaster recovery help keep your data safe. They make sure you can get your data back if something goes wrong.

You want to save a copy of your important data regularly.
You need to protect data from accidental deletion or hardware failure.
You want to recover data quickly after a system crash or disaster.
You want to keep your data safe from ransomware or cyber attacks.
You want to meet company rules about data safety and storage.
Syntax
Hadoop
hdfs dfs -cp /source/path /backup/path
hdfs dfs -get /backup/path local_backup_folder
hdfs dfsadmin -safemode enter
hdfs dfsadmin -safemode leave

Use hdfs dfs -cp to copy data inside HDFS for backup.

Use hdfs dfs -get to download backup data to local storage.

Examples
This copies the data folder to a backup folder inside HDFS.
Hadoop
hdfs dfs -cp /user/data /user/backup/data_backup
This downloads the backup from HDFS to your local machine.
Hadoop
hdfs dfs -get /user/backup/data_backup /local/backup
This puts HDFS into safe mode to prevent changes during backup.
Hadoop
hdfs dfsadmin -safemode enter
This exits safe mode after backup is done.
Hadoop
hdfs dfsadmin -safemode leave
Sample Program

This code shows how to safely backup data in Hadoop. It first locks the file system to avoid changes, copies the data, unlocks the system, and then downloads the backup to local storage.

Hadoop
# Step 1: Enter safe mode to protect data
!hdfs dfsadmin -safemode enter

# Step 2: Copy data folder to backup folder
!hdfs dfs -cp /user/hadoop/data /user/hadoop/backup/data_backup

# Step 3: Exit safe mode
!hdfs dfsadmin -safemode leave

# Step 4: Download backup to local machine
!hdfs dfs -get /user/hadoop/backup/data_backup ./local_backup

print('Backup completed successfully')
OutputSuccess
Important Notes

Always enter safe mode before backup to avoid data changes.

Regular backups reduce data loss risk.

Test your recovery process to make sure backups work.

Summary

Backup saves copies of data to protect against loss.

Disaster recovery helps restore data after problems.

Use Hadoop commands to copy and download backups safely.