Advertisement
kevin25

Recover Centos

Dec 31st, 2014
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.75 KB | None | 0 0
  1. #!/bin/bash
  2. #######################################################################################################
  3. #######################################################################################################
  4. #######################################################################################################
  5. ######                                                                                          #######
  6. ######                                                                                          #######
  7. ######                 This script will help you to recover the accidentally                    #######
  8. ######                     deleted data from crashed linux file systems                         #######
  9. ######                                     Version-2                                            #######
  10. ######                          Script created by (Srijan Kishore)                              #######
  11. ######                                                                                          #######
  12. ######                                                                                          #######
  13. #######################################################################################################                                                                                      
  14. #######################################################################################################
  15. #######################################################################################################
  16.  
  17.  
  18. # User Check
  19.  
  20. if [ "$USER" = 'root' ]
  21.     then
  22.  
  23. whiptail --title "User check" --msgbox "User is root, you can execute the script successfully." 8 78
  24.              
  25.         echo "User is root, you can execute the script successfully"
  26.     else
  27. whiptail --title "User check" --msgbox "User is not Root. Please run the script as root user." 8 78
  28.  
  29.        
  30.         echo "User is not Root. Please run the script as root user."
  31.         exit 1
  32. fi
  33.  
  34.  
  35. # Check your operating system
  36.  
  37. cat /etc/redhat-release >> /dev/null
  38. if [ "$?" = 0 ]
  39.     then
  40.  
  41. whiptail --title "Your OS" --msgbox "You are using CentOS/Redhat/Fedora" 8 78
  42. echo "You are using CentOS/Redhat/Fedora"
  43.  
  44.     else
  45.  
  46. whiptail --title "Your OS" --msgbox "You are not using CentOS/Redhat/Fedora.You can download the TestDisk from this link http://www.cgsecurity.org/wiki/TestDisk_Download" 8 78
  47.  
  48.     echo "You are not using CentOS/Redhat/Fedora.You can download the TestDisk from this link http://www.cgsecurity.org/wiki/TestDisk_Download"
  49.     exit 1        
  50. fi
  51.  
  52. #adding repo
  53. ver=`cat /etc/redhat-release | cut -d " " -f3 | cut -d "." -f1`
  54. ls -l /etc/yum.repos.d/rpmforge*
  55.  
  56. if [ "$?" != 0 ]
  57.    
  58.     then
  59.     whiptail --title "Repository requirement" --msgbox "You need to add rpmforge repository to install testdisk" 8 78
  60.         if [[ `uname -i` = 'i386' && $ver = 6 ]]
  61.             then
  62.             echo "you are running i386 with 6 version"
  63.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
  64.         fi
  65.  
  66.         if [[ `uname -i` = 'x86_64' && $ver = 6 ]]
  67.             then
  68.             echo "you are running i386 with 6 version"
  69.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  70.         fi
  71.  
  72.         if [[ `uname -i` = 'i386' && $ver = 5 ]]
  73.             then
  74.             echo "you are running i386 with 5 version"
  75.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.i386.rpm
  76.         fi
  77.  
  78.         if [[ `uname -i` = 'x86_64' && $ver = 5 ]]
  79.             then
  80.             echo "you are running x86_64 with 5 version"
  81.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
  82.         fi
  83.  
  84.         if [[ `uname -i` = 'x86_64' && $ver = 4 ]]
  85.             then
  86.             echo "you are running i386 with 4 version"
  87.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el4.rf.i386.rpm
  88.         fi
  89.  
  90.         if [[ `uname -i` = 'x86_64' && $ver = 4 ]]
  91.             then
  92.             echo "you are running x86_64 with 4 version"
  93.             yum install -y http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el4.rf.x86_64.rpm
  94.         fi
  95. else
  96. whiptail --title "Repository requirement" --msgbox "You already have TestDisk repos configured" 8 78
  97. echo "You already have TestDisk repos configured"
  98. fi
  99.  
  100.  
  101. # TestDisk installation
  102. testdisk --version >> /dev/null
  103. if [ "$?" = 0 ]
  104.     then
  105.     whiptail --title "Info" --msgbox "Testdisk already installed" 8 78
  106.     echo "Testdisk already installed"
  107.     else
  108.     whiptail --title "Info" --msgbox "Testdisk not installed, installing Testdisk" 8 78
  109.         echo "Testdisk not installed, installing Testdisk"
  110.  
  111.     yum install -y testdisk
  112. fi
  113.    
  114.  
  115. #Recovery part of deleted files
  116.  
  117.  
  118. ls -l /root/result/lostfiles
  119. if [ $? != 0 ]
  120.     then
  121.     mkdir -p /root/result/lostfiles
  122.     whiptail --title "Data recovery" --msgbox "You are proceeding towards recovering the data from the lost drive. Please select the affected drive to get the data recovered" 8 78
  123.     photorec /d /root/result/lostfiles
  124.  
  125.     else        
  126.     whiptail --title "Folder Exists" --msgbox "There is already an existing folder viz /root/result/lostfiles, you are adviced to rename/remove the folder to allow the data recovery process" 8 78        
  127. exit 2
  128. fi
  129.  
  130. #File filtering
  131.  
  132. user=`ps aux | grep gnome-session | grep -v grep | head -1 | cut -d " " -f1`
  133. mkdir "/home/recovered_output"
  134. mkdir "/home/recovered_output/Debians"
  135. mkdir "/home/recovered_output/rpms"
  136. mkdir "/home/recovered_output/conf_files"
  137. mkdir "/home/recovered_output/exe"
  138. mkdir "/home/recovered_output/binaries"
  139. mkdir "/home/recovered_output/Docs"
  140. mkdir "/home/recovered_output/Pdfs"
  141. mkdir "/home/recovered_output/Mbox"
  142. mkdir "/home/recovered_output/Images"
  143. mkdir "/home/recovered_output/Videos"
  144. mkdir "/home/recovered_output/Sound"
  145. mkdir "/home/recovered_output/ISO"
  146. mkdir "/home/recovered_output/Excel"
  147. mkdir "/home/recovered_output/Presentation"
  148. mkdir "/home/recovered_output/Web_Files"
  149. mkdir "/home/recovered_output/Archives"
  150. mkdir "/home/recovered_output/Others"
  151.  
  152.  
  153. #Sorting the Recovered data
  154.  
  155.  
  156. find /root/result/ -name "*.doc"    -type f  -exec mv {} "/home/recovered_output/Docs/" \;
  157. find /root/result/ -name "*.docx"   -type f  -exec mv {} "/home/recovered_output/Docs/" \;
  158. find /root/result/ -name "*.odt"    -type f  -exec mv {} "/home/recovered_output/Docs/" \;
  159. find /root/result/ -name "*.pdf"    -type f  -exec mv {} "/home/recovered_output/Pdfs/" \;
  160. find /root/result/ -name "*.mbox"   -type f  -exec mv {} "/home/recovered_output/Mbox/"  \;
  161. find /root/result/ -name "*.png"    -type f  -exec mv {} "/home/recovered_output/Images/" \;
  162. find /root/result/ -name "*.jpg"    -type f  -exec mv {} "/home/recovered_output/Images/" \;
  163. find /root/result/ -name "*.jpeg"   -type f  -exec mv {} "/home/recovered_output/Images/" \;
  164. find /root/result/ -name "*.gif"    -type f  -exec mv {} "/home/recovered_output/Images/" \;
  165. find /root/result/ -name "*.avi"    -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  166. find /root/result/ -name "*.mpeg"   -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  167. find /root/result/ -name "*.mp4"    -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  168. find /root/result/ -name "*.mkv"    -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  169. find /root/result/ -name "*.webm"   -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  170. find /root/result/ -name "*.wmv"    -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  171. find /root/result/ -name "*.flv"    -type f  -exec mv {} "/home/recovered_output/Videos/" \;
  172. find /root/result/ -name "*.mp3"    -type f  -exec mv {} "/home/recovered_output/Sound/" \;
  173. find /root/result/ -name "*.wav"    -type f  -exec mv {} "/home/recovered_output/Sound/" \;
  174. find /root/result/ -name "*.deb"    -type f  -exec mv {} "/home/recovered_output/Debians/" \;
  175. find /root/result/ -name "*.bin"    -type f  -exec mv {} "/home/recovered_output/binaries/" \;
  176. find /root/result/ -name "*.exe"    -type f  -exec mv {} "/home/recovered_output/exe/" \;
  177. find /root/result/ -name "*.rpm"    -type f  -exec mv {} "/home/recovered_output/rpms/" \;
  178. find /root/result/ -name "*.conf"   -type f  -exec mv {} "/home/recovered_output/conf_files" \;
  179. find /root/result/ -name "*.iso"    -type f  -exec mv {} "/home/recovered_output/ISO/" \;
  180. find /root/result/ -name "*.xls"    -type f  -exec mv {} "/home/recovered_output/Excel/" \;
  181. find /root/result/ -name "*.xlsx"   -type f  -exec mv {} "/home/recovered_output/Excel/" \;
  182. find /root/result/ -name "*.csv"    -type f  -exec mv {} "/home/recovered_output/Excel/" \;
  183. find /root/result/ -name "*.ods"    -type f  -exec mv {} "/home/recovered_output/Excel/" \;
  184. find /root/result/ -name "*.ppt"    -type f  -exec mv {} "/home/recovered_output/Presentation/" \;
  185. find /root/result/ -name "*.pptx"   -type f  -exec mv {} "/home/recovered_output/Presentation/" \;
  186. find /root/result/ -name "*.odp"    -type f  -exec mv {} "/home/recovered_output/Presentation/" \;
  187. find /root/result/ -name "*.html"   -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  188. find /root/result/ -name "*.htm"    -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  189. find /root/result/ -name "*.jsp"    -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  190. find /root/result/ -name "*.xml"    -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  191. find /root/result/ -name "*.css"    -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  192. find /root/result/ -name "*.js"     -type f  -exec mv {} "/home/recovered_output/Web_Files/" \;
  193. find /root/result/ -name "*.zip"    -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  194. find /root/result/ -name "*.tar"    -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  195. find /root/result/ -name "*.rar"    -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  196. find /root/result/ -name "*.gzip"   -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  197. find /root/result/ -name "*.tar.gz" -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  198. find /root/result/ -name "*.7z"     -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  199. find /root/result/ -name "*.bz"     -type f  -exec mv {} "/home/recovered_output/Archives/" \;
  200. find /root/result/ -name "*.bz2"    -type f  -exec mv {} "/home/recovered_output/Archives" \;
  201. find /root/result/ -name "*.*"      -type f  -exec mv {} "/home/recovered_output/Others/" \;
  202.  
  203. #Finalization
  204. whiptail --title "Congratulations" --msgbox "You have successfully recovered your data in folder /home/recovered_output cheers :)" 8 78
  205. echo "You have successfully recovered your data in folder /home/recovered_output cheers :)"
  206. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement