Monday, November 7, 2016

Restore deleted files in ext4 file system with the reference of file name in Redhat 6.x centos 6.x

Restore Ext4 deleted files with the reference of file name in Redhat 6.x centos 6.x by using below script

Pre-requisites - Below packages have to be installed at first place.
===================================================================

e2fsprogs.x86_64                       1.41.12-14.el6               @anaconda-RedHatEnterpriseLinux-201301301459.x86_64/6.4
e2fsprogs-devel.i686                   1.41.12-14.el6               @rhel-source
e2fsprogs-devel.x86_64                 1.41.12-14.el6               @rhel-source
e2fsprogs-libs.i686                    1.41.12-14.el6               @rhel-source
e2fsprogs-libs.x86_64                  1.41.12-14.el6               @anaconda-RedHatEnterpriseLinux-

Script:
======


#!/bin/sh

time=`date +%D-%M-%Y-%T`

echo "Time is now $time"

printf "Please Enter the full path of the disk EX: /dev/VGname/LVname.. or /dev/sdb1..etc:"
read name
printf "\n Please Enter the file name which got deleted (Case sensitive) :"
read filename

printf "\n Have you unmounted the file system before we recover your deleted file, If not, Please unmount first to avoid any demage to the files"

printf "\n Do want to continue, please say yes only if you have unmounted the file system (y/n):"

read de

case $de in
y)
break
;;
n)
exit 0
;;

*)

echo "Oops!!! Entered invalid option"
exit 0
 
esac

extundelete $name --restore-file $filename > /tmp/restore_output

cat /tmp/restore_output | grep -i Successfully restored file $filename  > /dev/null

if [ `echo $? == 0` ]
then
echo "Your file has successfully restored, Pls check the file under /RECOVERED_FILES"
else
   echo "Sorry something went wrong in the script!!! Pls look out for other options to recover the files"
fi

No comments:

Post a Comment