Created
May 20, 2015 11:00
-
-
Save xman1980/eeadaf46201c04df46ef to your computer and use it in GitHub Desktop.
backup hadoop namenode 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 | |
#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-dev2-${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