-
-
Save xman1980/3a28c29e78874178767472ba696fe243 to your computer and use it in GitHub Desktop.
backup hdfs fsimage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
####################### | |
# Backup the filesystem metadata for hadoop using namenode url | |
# Change the variables to match appropriate env and put this script in crontab | |
####################### | |
#Variables | |
TODAY=$(date +"%Y-%m-%d-%H%M") #date and time | |
BACKUP_PATH="/home/backup/hadoop/fsimage" #path to store metadata | |
RT_DAYS="4" #Rentention in days | |
#Logic | |
if [ -d ${BACKUP_PATH} ]; then | |
cd ${BACKUP_PATH} | |
else | |
mkdir -p ${BACKUP_PATH} && cd ${BACKUP_PATH} | |
fi | |
#download fsimage file | |
hdfs dfsadmin -fetchImage . | |
if [ $? -eq 0 ]; then | |
#compress the fsimage and edits file | |
tar -zcf namenode-prod2-${TODAY}.tar.gz fsimage_* | |
if [ $? -eq 0 ]; then | |
#delete all backup up to days specified in RT_DAYS | |
find -atime +${RT_DAYS} -name "namenode*" -exec rm {} \; | |
rm fsimage_* #remove downloaded fsimage | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment