Skip to content

Instantly share code, notes, and snippets.

@xman1980
Created May 20, 2015 11:00
Show Gist options
  • Save xman1980/eeadaf46201c04df46ef to your computer and use it in GitHub Desktop.
Save xman1980/eeadaf46201c04df46ef to your computer and use it in GitHub Desktop.
backup hadoop namenode fsimage
#!/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