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/

Advertisements

One Comment

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: