nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

how to recover deleted files using script

This is a discussion on how to recover deleted files using script within the Shell scripting forums, part of the Development/Scripting category; Hi, I need a script to undelete the removed files....


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 06-22-2005, 05:15 PM
soma
Guest
 
Posts: n/a
Default how to recover deleted files using script

Hi,

I need a script to undelete the removed files.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-22-2005, 07:12 PM
Guest
 
Posts: n/a
Default

Have a look at http://e2undel.sourceforge.net/recovery-howto.html
http://www.stud.tu-ilmenau.de/~mojo/undelete.html

Writing script is not difficult but first see those pages!
Reply With Quote
  #3 (permalink)  
Old 06-22-2005, 08:18 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

You can use grep command, for example if you want to undelete a text file with 100 lines starting with "top secret " which was stored on /dev/hdc2 you can try:

Code:
grep -a -B2 -A100 "top secret" /dev/hdc2 > /tmp/recovered.txt
Where
-a : Process a binary file as if it were text
-B N: Print N lines of leading context before matching lines
-A N: Print N lines aka recover 100 lines of trailing context after matching lines

You can use above grep command in script make sure you run it as root user, /dev/hdc2 unmounted, and /tmp is not mounted on /dev/hdc2

You can also try one of the above tools http://e2undel.sourceforge.net/recovery-howto.html

Also if you are using a journalled filesystem like ext3 it is difficult to do undelete please have look at below:

Quoting the Ext3 FAQ, http://batleth.sapienti-sat.org/proj...ext3-faq.html:
Code:
"Q: How can I recover (undelete) deleted files from my ext3 partition?

A: Actually, you can't! This is what one of the developers, Andreas Dilger, said about it:

In order to ensure that ext3 can safely resume an unlink after a crash, it actually zeros out the block pointers in the inode, whereas ext2 just marks these blocks as unused in the block bitmaps and marks he inode as 'deleted' and leaves the block pointers alone. Your only hope is to 'grep' for parts of your files that have been deleted and hope for the best."
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
i need a script to delete one folder with files on my ftp silver_ch Shell scripting 1 03-27-2007 11:15 AM
Script to extract some part of files: satish1482 Shell scripting 0 03-13-2007 06:30 PM
Shell script for automatic conversion of files in tar files kasimani Shell scripting 2 02-08-2007 04:45 PM
script for uploading files to a FTP server marinm Shell scripting 7 01-02-2006 08:35 PM
Script to remove executable files sweta Shell scripting 4 03-12-2005 02:21 PM


All times are GMT +5.5. The time now is 02:27 AM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36