Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

OK, brief background. I accidently rm -rf my usb external hard drive. Right now I am using Photorec to recover the files. (I accidently deleted 800GB. Its my personal files. Mostly it was media, but I also had other stuff such as pdf, xls, jpg, doc etc.)

So, I attached another external hard drive with 350 GB left to start recover since that is all I got. The files are being dumped right now and I know I will exhaust it soon.

I need some help with automating some of the recovery. The recovery process is dumping files in folders. Each one starts with recup_dir.x

Each of these folders has my files. Right now I want to do something along these lines in each folder; navigate to each folder and copy all the pdf,doc,xls,jpg files to my comp hd and delete them from the other external harddrive so I can go to sleep and hopefully it will at least recover most of the needed files. Can some one help :(

cp *.docx /home/me/Desktop/docx/ || cp *.doc /home/me/Desktop/docx/ || cp *.xls /home/me/Desktop/xls/ || cp *.pdf /home/me/Desktop/pdf/ || cp *.jpg /home/me/Desktop/jpg/ && rm  *.doc *.docx *.pdf *.jpg *.xls
share|improve this question
add comment

3 Answers

I would never, never, delete any files before I had verified that the file recover was successful. Especially not when writing a script, a typo in the script could delete everything.

Better to wipe the disk after the recovering is completed.


That said, I would look into using rsync, it should be a somewhat safe option. It has an option to --remove-source-files which probably is what you are looking for. man pages can be found here.

A problem you have to think about, however, is what would happen if rsync would start to copy a file while it is being recovered/copied to the disk. Again, I think the chance of errors are too high.

share|improve this answer
    
Disk will run out of space pretty soon. I dont know how photorec will react when it does. Right now I am able to retrieve the files to my desktop. –  user55490 Sep 28 '10 at 9:03
    
Can you please look at the copy mechanism and see what I need to change to copy multiple files to different folders based on file extension. I will not delete/remove untill I am sure, The one I am using is I know wrong... –  user55490 Sep 28 '10 at 9:06
    
Still sounds dangerous to me, if you care for your files I would get another temporary disk to backup files to. Also, the commands you provided could overwrite documents of the same name. –  Avada Kedavra Sep 28 '10 at 9:07
    
Added some thoughts about rsync –  Avada Kedavra Sep 28 '10 at 9:19
add comment

safer way

#!/bin/bash
rsync --progress -gioprtv <recoverydir>/*.doc* /home/me/Desktop/docx/ && \
rsync --progress -gioprtv <recoverydir>/*.xls /home/me/Desktop/xls/ && \
rsync --progress -gioprtv <recoverydir>/*.jpg /gome/me/Desktop/jpg/ && \
rsync --progress -gioprtv <recoverydir>/*.pdf /gome/me/Desktop/pdf/; \

rsync verifies the files end to end by hashing them, the above should give you an indication as to the process of an individual copy aswell so you're not sat there twiddling your thumbs.

The && ensures that it will only progress if the previous step has completed successfully, this allows you to go back and edit the script if anything goes wrong and repeat the process.

Put it in a file i.e. resovery.sh chmod+x and away you go

NEVER EVER delete the source files until you have had chance to review them.

share|improve this answer
    
Hey thanks for your response. I still have to try it, but I had a question, my recoverdir has a bunch of sub-directories under which the files are. Is there a way for me to act that kind of script across all sub folders? all the sub-folders are name sub-folder.x in serial increasing order? such as <recoverydir>/<sub-director>.*/*.doc* /Destination/ –  user55490 Sep 28 '10 at 9:21
    
the -gioprtv dictates the following, preserve gid,itemize, preserver oid, preserver permissions, recursive, preserver timestamp, be verbose, so it will resurse over all directories if you remove the/*.ext infavor of just specifying the path –  Oneiroi Sep 28 '10 at 10:25
add comment

Another thougth, you write that most of your stuff is media but you dont mention that you want to recover these files? If so, it makes more sense to me to reverse the logic and instead delete those files to create room for the files that you want to keep.

If so you could play around with something like this. NOTE THAT THIS CAN DELETE ALL YOUR AVI FILES IN CURRENT FOLDER AND ALL SUBFOLDERS!!

find . -name "*.avi"                      - verify 
find . -name "*.avi" -exec rm -f {} \;    - delete
share|improve this answer
    
That does make sense. Thanks for the suggestion. Right now I am trying to look around to see if I can get some thing like this builtbackwards.com/projects/photorec-sorter for linux. –  user55490 Sep 28 '10 at 10:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.