Tuesday, February 12, 2013

Recovering deleted JPGs and NEFs

Probably due to my own error, about 40 photos both JPGs and Nikon NEFs got deleted by accident from the CF card on my D300.

After trying a few "free" applications, which firstly did not recover everything and secondly cost $90 or more to recover NEFs, I came across the application "Photorec" which comes as part of a data recovery programme called "Testdisk". Its available for most major platforms, I chose to run on Ubuntu 12.04.


First install either through Synaptic or the command line:


    sudo apt-get install testdisk

after it installs, run as root


    sudo photorec

From here its pretty much wizard driven. Quick start is here.

On my 16GB card it took about 45 minutes to copy everything. A couple of things to note:


  1. The process will find ALL files deleted or not, and put the into a series of folders. The dates and times of each photo will be roughly correct (see below) so you can take a first pass at what you are looking for.
  2. The files and the folder will be owned by root, so you'll need to fix up the permissions to do anything else with them.
  3. The files will be recovered with generic non-sequential names.
To fix #2 I sorted through the photos, and copied the ones I had lost to a new folder. This keeps the "originals" safe while you fix them up.

To fix #3 I used EXIFTool to rename the files with their EXIF date / time creation:


    exiftool "-FileName<CreateDate" -d "%Y%m%d_%H%M%S.%%e" file.nef

on occasion the file system modification time is wrong, which you can fix with:


    exiftool '-DateTimeOriginal>FileModifyDate' file.nef

You can then match up JPG and NEF from their dates and times, and reconstruct the filenames.

No comments: