LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-13-2013, 09:49 AM   #1
alvgarci
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Rep: Reputation: Disabled
Script that rebuilds folder structure of a accidentally deleted disk


Hi all:

After an imprudent execution of a Rsync script, I deleted 50k files of my hardisk. Fortunately, I could recover them (file names, attributes, etc), but I lost the folder structure.

This is what I have now:

List of the files that has been deleted with their full path:

"DISCO ROJO/recuperado/Video/mpg/file000160.mpg"
"DISCO ROJO/recuperado/Video/mpg/file000159.mpg"
..

In the other hand.. (thanks to diskdrill) I got all files on a flat folder structure using random directory names:

./temp68554
./temp68555
./temp68556
./temp68557

Each temp folder match with old folder structure... it means that I.E.. the content of "./temp68557" is the content of the old "DISCO ROJO/recuperado/Video/mpg/

I'm finding ways to identify temp folder name with the old one.. and do a mv / cp script for that.

Any ideas?

Thanks
 
Old 02-13-2013, 09:55 AM   #2
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
./temp68554
./temp68555
./temp68556
./temp68557

Each temp folder match with old folder structure... it means that I.E.. the content of "./temp68557" is the content of the old "DISCO ROJO/recuperado/Video/mpg/
Does the tempnnnnn directories or their contents have ANY indication of the previous directory structure?
 
Old 02-13-2013, 12:46 PM   #3
alvgarci
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thanks for your response. No, no correlation between tempnnnnn and old structure.

My best approach is:

1) create a matrix with all tempnnnn folder, and files inside. ( recursive ls of each tempnnnnn folder)
2) Create a second matrix with all original folders and files inside (I already extract old folders into a file.. so extract only filenames of the file for each old folder)
3) compare only directories with same number of files. (sort matrix entries based on the number of records for each folder)
4) Check that filenames are the same in both directories (loop until changes=0)
5) if #4 is ok, mark the source folder as "solved", > output the mv tempnnnn original structure command
6) if no jump to the next


Such a huge batch...

Looks horrible.
 
Old 02-13-2013, 03:15 PM   #4
alvgarci
LQ Newbie
 
Registered: Feb 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
I should say also that filenames are not unique.. therefore I must match all filenames on each folder to be sure that the folder is the same one.

There is another one better:

1) Extract all filenames and full path on each (old and new one). Finding the last / give us the way to do it.
2) Find for all tempnnnnn folders (all files on each).. files on the old structure that match their filename. For each match, one counter add +1 on each counter (1 counter per domain on which filename match).. I.E... file 1.MP4 match on folder A > Counter A=A+1. If there are more coincidences (1.MP4 is not unique) Counter B=B+1.. etc.. In any case.. one counter must match at the end the total number of files of the folder. Than counter shows the correspondence tempnnnnnn <=> folder A
3) rename tempnnnnn to folder A etc etc etc.

Any tip?

Thanks
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accidentally Deleted Home Folder [CentOS 5.5 32bit] deathschaos9 Linux - Newbie 1 10-30-2012 01:43 PM
Accidentally Deleted Public Folder/$Home warning jimwg Linux - Desktop 3 10-20-2012 08:02 AM
Accidentally Deleted 1 TB Drive Useing Startup Disk Creator 9876543210 Linux - Hardware 1 10-20-2010 02:18 AM
Home Jail Folder Structure like Gobolinux Directory Structure luispt Linux - General 3 07-26-2008 06:46 PM
I have deleted a folder accidentally? How do I recover it? srikanth_dhondi Linux - Software 2 02-19-2008 06:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration