Skip to content
May 30, 2013 / doganay

HOW TO UNDELETE A DATAFILE

undelete_dbf.sh
---------------
#!/usr/bin/ksh
#Mustafa DOGANAY
#doganay.wordpress.com
#This script should be run in background
#It checks whether a  ".dbf " file is deleted every second
#Undeletes deleted dbf to /tmp/datafile_$(date +%Y%m%d%H%M%S).dbf
while [ 1 ]
do
 if [ $(ls -lrta /proc/*/fd/* 2>/dev/null | grep "(deleted)" | grep ".dbf" | grep -v grep | wc -l) -ne 0 ]
 then
  cd /proc/$(ps -ef | grep dbw | grep -v grep | tail -1 | awk '{print $2}')/fd
  cat $(ls -lrta * | grep ".dbf" | grep "(deleted)" | awk '{print $9}') > /tmp/datafile_$(date +%Y%m%d%H%M%S).dbf
  break
 else
  sleep 1
 fi
done

You should locate this code into a script and run it in background:

$ chmod 700 undelete.sh
$ ./undelete.sh &

Thanks to Jason Arneil:

http://jarneil.wordpress.com/

One Comment

Leave a Comment
  1. SutoCom / Jun 1 2013 9:37 am

Leave a comment