Advertisement
Guest User

undelete

a guest
Jul 11th, 2010
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.55 KB | None | 0 0
  1. #!/bin/bash
  2. # It is a wrapper for ntfsundelete utility. It may be useful if you want to
  3. # restore only specified filetypes (zip, 7z and Logic Audio Song in my case) but
  4. # names of accidentally deleted files are lost
  5.  
  6. # Globals ======================================================================
  7. DEVICE=/dev/sdb1        # device
  8. DEST=/media/recover     # destination
  9. TMP=/dev/shm            # temp directory
  10. HEAD_ZIP="504b0304"     # 4 bytes in HEX
  11. HEAD_LSO="1347c0ab"     # 4 bytes in HEX
  12. HEAD_7Z="377abcaf"      # 4 bytes in HEX
  13.  
  14.  
  15. # Script =======================================================================
  16. cd $TMP
  17. # Get inodes of potentially restorable files
  18. ntfsundelete $DEVICE -p 100 -S 512-100m | grep -o -e ^[0-9]* > inodes.txt
  19.  
  20. # Define format file for hexdump
  21. echo "16/1 \"%02x\"" > printformat
  22.  
  23. # get whole number of inodes
  24. num_inodes=$(wc -l inodes.txt | grep -o -e ^[0-9]*)
  25.  
  26. # Cycle through all inodes
  27. for (( i=1; i<=$num_inodes; i++ ))
  28. do
  29. # Get current inode by it's number
  30.     inode=$(sed -n "$i p" inodes.txt)
  31.  
  32. # Undelete file
  33.     ntfsundelete $DEVICE -u -i $inode > /dev/null
  34.  
  35. # Check filetype and make decision
  36.     HEAD4="$(hexdump -f printformat -n 4 unknown)"
  37.     if   [ $HEAD4 = $HEAD_ZIP ]; then
  38.         echo "$HEAD4 ZIP found"
  39.         mv unknown $DEST/$inode.zip
  40.         chmod 666 $DEST/$inode.zip
  41.     elif [ $HEAD4 = $HEAD_LSO ]; then
  42.         echo "$HEAD4 LSO found"
  43.         mv unknown $DEST/$inode.lso
  44.         chmod 666 $DEST/$inode.lso
  45.     elif [ $HEAD4 = $HEAD_7Z ]; then
  46.         echo "$HEAD4 7-Zip found"
  47.         mv unknown $DEST/$inode.7z
  48.         chmod 666 $DEST/$inode.7z
  49.     else
  50.         rm unknown
  51.     fi
  52. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement