Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1158
  • Last Modified:

Recovering Deleted Directory Structure in Ubuntu Linux

Hi folks!

Got an Ubuntu 12.04.3 LTS server that is acting as a file server for our network using Samba. Had a bunch of files and folders that got accidentally deleted.

I was able to use the Foremost tool to recover a bunch of the files, but it seems to recover them by file type and sort the recovered files that way (e.g. I now have one folder for all the recovered JPG files, one for all the XML files, etc.) with no indication of what directories they came from. That's a particular big deal on this machine, since there are tons of different small directories that originally housed these files.

So... do I have any hope here? Any way for me to get these files back to their original directories rather than just having a big pile of files to work from?

Thanks,
Ithizar
0
Ithizar
Asked:
Ithizar
1 Solution
 
ThomasMcA2Commented:
Perhaps TestDisk would do a better job. See here for step-by-step instructions.
0
 
serialbandCommented:
If you aren't backing up your file server, you should start doing that now.  That would save you much aggravation.  You should also be testing your backups periodically.  Many companies run backup solutions but never test them, so they don't ever know if the backups actually worked.
0
 
tfewsterCommented:
I typed a long answer, but my browser crashed and it's late, so here's the short version for now...

A directory is just a type of file (containing a list of inodes it contains and the associated filenames) so theoretically Foremost could recover directory file types as well.
http://www.howtoforge.com/recover-deleted-files-with-foremost - "You can tweak /etc/foremost.conf to add support for more file types"

That would give you a "flat" set of directory files, with the names being the original inode numbers

Before starting the reorganisation, make a copy of the complete ~/output directory as a working set.

Starting at the level that wasn't deleted, e.g. /data/shared, examine that directory with `strings` or a hex editor to find the inode numbers and filenames it should contain; Move and rename the recovered directories into that directory, then examine each subdirectory for inode numbers/names and repeat until finished.

Do the same for the recovered jpgs etc.

Hard links can also be recreated, with some further detective work.

Hopefully Foremost has recovered the owner:group and permissions, which should help.

As well as backups, you probably want to prevent file deletions in future; Samba or the directory "sticky bit" may help with that.

Hope that helps...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now