Trying to recover from a bad RAID rebuild
May 24, 2012 6:42 AM   Subscribe

I have a NAS appliance that crashed last weekend. The IT guys apparently / maybe didn't recover it in the right way? There's about 50,000 directories in a "lost+found" directory each with a numeric name like "#4289756". It looks as if all the missing files are within these directories, each with the original date and owner information (Linux). I need to organize them so they are findable to the staff.

My goal is to copy / move these files into a structure so that each employee has their own folder with their own files, and each folder is further divided by month.

The appliance itself is running a Busybox, a stripped down Linux version that only supports a subset of the typical Bash commands. I thought I could use a script with the "find" command to sort them by owner and date and then pipe that to "-exec cp" to the appropriate place, but it looks like Busybox doesn't have that ability.

I have:
1. A network of Windows machines
2. A working knowledge of Bash scripting (no expert, mind you)
3. The ability to install a Linux VM on one of the Windows machines
4. Cygwin already installed on one of them

I get the concept of what needs to be done, but the devil is in the details, and I could sure use some help. Anyone?
posted by nedpwolf to Technology (6 answers total)
Looks like the crash (or memory errors before the crash) led to filesystem corruption. The filesystem check that ran on bootup has attempted to recover as much data as possible, and all the files and directories it found during that process have been put in the lost+found directory, because it didn't have any information about where they should go.

This is not the fault of your IT people in other words.

Hacky, partially tested commandline follows:

cd /lost+found ; for i in *; do USER=`ls -l $i | awk '{print $3}'`; mkdir -p /home/$USER/recovered ; cp -a $i /home/$USER/recovered/$i ; done

If you run that on the NAS, it should recursively copy everything owned by each user in lost+found into a 'recovered' directory in their home directory on the NAS. You may need to change /home to wherever the NAS is storing all the home directories.
posted by pharm at 7:29 AM on May 24, 2012 [3 favorites]

NB If you don't have room for the copy, you'll have to replace the cp with a mv. This will obviously not preserve the original data!

Oh, and the lost+found directory might not be in / . It will located wherever that particular volume is grafted onto the directory tree.
posted by pharm at 7:32 AM on May 24, 2012

NB. I'm assuming that the directories in lost+found have the correct uids. If not, you'll have to edit the script appropriately.
posted by pharm at 7:34 AM on May 24, 2012

Thanks for the response, pharm!
Giving it a whirl.
posted by nedpwolf at 8:47 AM on May 24, 2012

Did it work?
posted by pharm at 6:24 AM on May 29, 2012

NB. Just noticed that the one-liner I gave you won't cope with spaces in filenames. You might want to check for any such files & do some fixing up if necessary. I should have quoted the arguments to cp & mkdir.
posted by pharm at 6:26 AM on May 29, 2012

« Older Detroit vs. Cleveland   |   Are these things related? Newer »
This thread is closed to new comments.