Quick Script To Sort and Rename from EXIF Date

I wrote a quick bourne shell script to sort and rename the image files I recovered from my formatted memory stick. It requires the perl exifdump script that comes with the Image::Info module (not the python script by the same name). Since the last pre-format image I had was 8160, I started the recovered files at number 8161. The filenames will not be exactly right due to images that were deleted and retaken, but close enough.

The script was coded up quickly so there is no documentation or error checking.


TEMPLIST=`/usr/local/bin/mktemp /tmp/ds-rename.XXXXXX`
TEMPSORT=`/usr/local/bin/mktemp /tmp/ds-rename.XXXXXX`

for file in V*.[jJ][pP][gG]
echo "Processing ${file}..."
DATE=`/home/jlick/bin/exifdump ${file} 2> /dev/null | /bin/grep DateTimeOriginal | /bin/sed -e "s/.*DateTimeOriginal -> //"`
echo ${DATE} ${file} >> ${TEMPLIST}

echo "Sorting..."
/bin/sort ${TEMPLIST} > ${TEMPSORT}

for file in `/bin/sed -e "s/.* //" < ${TEMPSORT}`
echo "Renaming ${file} to ${PRE}${NUM}${EXT}..."
/bin/mv ${file} ${PRE}${NUM}${EXT}
NUM=`/bin/expr ${NUM} + 1`

/bin/rm -f ${TEMPLIST} ${TEMPSORT}

Recovering Digital Photos From A Formatted Memory Card

We won’t get into details. Let’s just say that somehow a memory stick in our camera got reformatted.

All the pictures are gone, right? Fortunately the answer is no. Most format processes only put a new filesystem on the memory card. The data for the photos is still there, there’s just no longer any information on where they are.

Fortunately image files are in standard, recognizable formats, so it is possible for a specialized program to search the raw data on the memory card and reconstruct most, if not all of the image files. The image files can then be copied onto your computer as good as new.

Things aren’t completely foolproof though. First and most important is to stop using the memory card immediately as soon as you realize you have mistakenly formatted the card or erased an important image. Since there is no longer any information on where the old pictures are stored, any new pictures taken will overwrite the old, deleted pictures. To be safe, take the memory card out of the camera, switch it to “read-only” if possible, then keep it in a safe place until you can use recovery software on it. If you have kept using the memory card, it’s still worth trying a recovery. You probably would get back less than if you stopped using it immediately though.

Second, in most cases you cannot get back the original filenames or creation dates if the card is formatted. (If on the other hand the file was deleted instead of formatted then you may be able to reconstruct the file names and creation dates too.) However image files usually have some embedded metadata in EXIF format in the file which contains further detail on the images. In my case I am able to see the date information, but the filename information is not there. So at least I will be able to name the files in order by the time the picture was taken.

Third, depending on how fragmented your memory card is, the recovery program may not be able to piece things together exactly, so it is possible you will not be able to get back 100% of your images automatically. Different software will have different results in how accurately they can reconstruct the files.

I tried a few different programs and found I had the most success with PhotoRescue. PhotoRescue comes in three different versions depending on if you need it to run completely automated, or whether you are more of an expert in reconstructing images. The automated method will usually work pretty well but it is not 100%.

I used PhotoRescue Advanced, which is their most sophisticated version, however it is also much more challenging to use. With this version you can get a few percent closer to 100% recovery of your images. When I tried a competing product, it found 530 images on my memory card. However after I looked closer I found that close to a hundred were recovered corrupt, truncated, or otherwise unusable.

In comparison, PhotoRescue Advanced found a more modest 482 images, however all but 8 of those were undamaged. If using an automated reconstruction, this is the extent of how much you could recover. However, using the advanced features of PhotoRescue Advanced, I was able to completely reconstruct all but one of the damaged images manually.

The next problem was that it recovered not only the images that were on the card when it was last formatted but also older images that I had already copied off onto the computer. I was able to use the thumbnails and EXIF date information to sort out the files I already had. At the end of it all I had 411 image files that otherwise would have been gone forever. This all had to be done manually though.

The remaining problem is that the files were recovered in the order they were found which is not exactly the same order as they were taken. As I mentioned previously, this information is stored in the EXIF data, however for 411 images it’s a bit too much to sort through by hand. Instead I will be writing a perl program to read in the EXIF data and sort the files by date and restore the file timestamps as well.

For now though, I at least have the satisfaction of having the 411 pictures back and safe.

UPDATE: Windows XP’s explorer has a column for ‘Date Picture Taken’ which can be added to the view when using ‘details’ view. This can help you sort if you want to do it manually.

UPDATE2: I wrote a quick script to sort and rename from EXIF date. PS: For those of you who don’t watch Law & Order SVU, this also means your naughty pictures are still there after being deleted or formatted.

Some More Random Solaris Notes

To enable Jumbo Frames for Intel Gigabit Ethernet cards, edit /kernel/drv/e1000g.conf and make the following change:


To share a zfs filesystem (e.g. /pool/user) over nfs:

zfs set sharenfs=on pool/user

Use “on” or “off” to toggle it on and off. If you want to set particular nfs share options you can use those options instead (on is equivalent to ‘rw’):

zfs set sharenfs=”rw=host.example.com” pool/user

Thanks For Donating

From Ron Paul:

On just one day, in honor of the 234th anniversary of the Boston Tea Party, the new American revolutionaries brought in $6.04 million, another one-day record. The average donation was $102; we had 58,407 individual contributors, of whom an astounding 24,915 were first-time donors. And it was an entirely voluntary, self-organized, decentralized, independent effort on the internet.

Boston Tea Party Ron Paul Donation Drive

From http://www.teaparty07.com/:

On December 16th, 1773, American colonists dumped tea into the Boston Harbor to protest an oppressive tax. This December 16th, American citizens will dump millions of dollars into the Ron Paul presidential campaign to protest the oppressive and unconstitutional inflation tax – which has enabled a flawed foreign policy, a costly war and the sacrificing of our liberties here at home.

Please join us this December 16th 2007 for the largest one-day political donation event in history. Our goal is to bring together 100,000 people to donate $100 each, creating a one day donation total of $10,000,000.

Make your pledge at http://www.teaparty07.com/ and donate on December 16 at https://www.ronpaul2008.com/donate/. (If you prefer to donate by mail, get your mail-in donation form at here.)

Also please remember that if you want to vote for Ron Paul in the primaries, you must be registered Republican in most states.

I have donated to Ron Paul, have changed my voter registration, and will vote for him in the California primary.

Enabling Samba on recent Solaris releases

I recently upgraded two of my Solaris boxes to the latest Solaris 10 release and had some problems getting Samba working correctly again. Originally Samba on Solaris was started via the /etc/init.d/samba script and depended on whether the /etc/sfw/smb.conf configuration file existed. Then when the service framework came into use it was converted to a service, and you enabled it by running ‘svcadm enable samba’. All pretty straightforward so far.

In current Solaris releases there is a subtle change that may not be immediately obvious. For most Samba configurations you have two daemon processes running, smbd and nmbd. smbd is what actually does the file serving. If you only have smbd running you can still access files but you need to manually enter the filesystem path to get there. nmbd provides the netbios/wins service which is what announces on the LAN that the computer is part of a workgroup and what its name is. This is the piece that allows you to go to “My Network Places” or “View Workgroup Computers” and have stuff just automatically appear.

The change in the current Solaris versions is that while both daemons were controlled together in the past, they are now controlled as separate services. So now if you just do ‘svcadm enable samba’ it turns on only smbd and you only get file sharing that you can manually access. If you go to “My Network Places” or “View Workgroup Computers” you won’t see anything from that server. To enable nmbd also you need to also run ‘svcadm enable wins’.

Why would they do things this way? In more advanced network configurations you may have a domain controller that performs the netbios/wins functions. In that environment, separately running nmbd on a standalone server could cause confusion. Others may not want to run it because they don’t want an intruder to be able to easily discover shared filesystems. In any case, for most simple LAN based file service implementations, such as a home or small office network, you would probably want to run both services.