Monday, February 25, 2013

Recover lost JPG files on an SD Card

I recently cut and pasted some family reunion files from an SD Card to my PC hard drive where I proceeded to do some editing. Yes, 'CUT & paste' rather than 'COPY & paste' was a rather stunning act of carelessness and inevitably Murphie's Law prevailed; I over-wrote a source image which I later needed and there was no easy way to recover it.

Fortunately, there had been no activity which had written to the SD Card since the deletion, so the original images were still intact and could be recovered. Unfortunately, there are no ready use tools in Windows 8 like "undelete" or recycle bin access for SD Cards.

A quick look on Google showed a range of third party tools capable of recovering lost images in cases like this, including recovering partial images where part of the data may have been lost. (More about that later).

I downloaded and tried two tools and was immediately frustrated and disappointed by the exercise. It was a timely reminder that in the Windows 8 environment the installation process for unknown and untrusted third party software can deliver crap that is either crippled (a demo version which required the user to purchase a key on line - no forewarning regarding price), or comes with other headaches such as changing the web browser environment.

Sometimes I wonder why I don't just stick to the Linux Ubuntu environment and be done with it. The Linux solution is just so easy.

I went back to Google, and after researching likely recovery tools for Linux, I selected 'recoverjpeg' as weapon of choice. It had a good review, is a mature product developed by a trusted source, has a dead simple command line interface and bugger all footprint.

Here's how the heck I did it:

I fired up Linux on my dual boot machine. In a terminal window, I downloaded and installed 'recoverjpeg' using the following command:

     sudo apt-get install recoverjpeg

Sudo as you may know is used to provided access and control when not logged in a 'root'. It will require the system password to be entered.

Instal a temporary directory on the desktop to hold the recovered images. The command sequences is:

     cd Desktop
     mkdir JPEGS
     cd JPEGS/

Do a quick check to confirm the device name for the SD Card presently sitting in a USB card reader. The command is:

     sudo fdisk -l

The output from fdisk indicated I had a 32 Gb card at /dev/sdk

Run recoverjpg from the destination or output directory with it pointing to the source directory. The command is:

     sudo recoverjpg /dev/dsk1

Note the file name 'recoverjpg' does not include the letter 'e' and in 'recoverjpeg'.

Voila! Success.....

It took about 30 minutes to run as my SD card was holding quite a lot. Eventually it recovered 1859 images, many of which were in the 16 Mb size range. I opened the destination folder in a separate file browser and could see things progressing quite nicely as each image was recovered.

I didn't persist with options to drill into the SD card sub-directories or go looking for particular files by date, time or file name. I just let it go to see what it would recover and with the simple command line, it recovered every JPG on the hard drive, regardless of whether or not it had been deleted or partially over-written.

It is worth mentioning that partial images were also recovered where some of the image data had been overwritten. The partial image may be useful if it can be cropped using an image editor. It is worth noting that if you catch it early enough, even if you have been writing to the SD Card, there is a chance an image you may want to recover may still be intact.

'recoverjpeg' gives each image recovered a new file name in the format "image00000.jpg" and it will jump to 6 digits when there are more than 100,000 images recovered in one session.

Because the returned files are not necessarily date time sorted, it may take a little while sifting through the thumbnail views to find the ones you want, but the results are well worth it.

I plan to put 'recoverjpeg' in my shoe box for later review. I would like to see if I can find a version of 'recoverjpeg' with a GUI interface or create a GUI wrapper that gives easy access to the options. In the meantime, now I have the lost files safely stored, I'm as happy as a dog with two tails and can now get back to processing some more irreplaceable family reunion images.