How to keep photos safe while on vacation.

This is a script I wrote to backup a friend‘s photos from his Compact Flash cards to both a USB drive and a remote server while he visiting Japan for the next month. This script also verifies data transfers by running md5deep on the source files (CF card) and then checks them against the files on the USB drive. I wrote this for an Ubuntu netbook he is taking along with him but the commands should work on any *nix based system including Mac OS X; a md5deep binary may be needed.

#!/bin/bash
echo "Creating variables"

# This is the compact flash card (The pure data as Chase Javis would say)
# If you have a Canon you'll recognize the folder structure
PHOTOdrv="/media/EOS_DIGITAL/DCIM/100CANON"

# USB Backup device, or perhaps a local folder on your laptop.
USBdrv="/media/My\ Passport"

# SSH Variables. The folder has to exist already on the remote host.
SSHuser=jesus
SSHhost=epijunkie.com
SSHdirectory=~/photos

# Unless you know what you are doing it's suggested not to edit anything below.
DATEcode=`date +%F%k%M`
MD5=$DATEcode".md5"
echo "Success"
echo ""
echo "Creating folder $DATEcode at $USBdrv"
mkdir $USBdrv/$DATEcode
echo "Success"
echo ""
echo "Copying images over"
cp -a $PHOTOdrv/*.CR2 $USBdrv/$DATEcode/
echo "Success"
echo ""
echo "Hashing files in $PHOTOdrv."
md5deep -b -e $PHOTOdrv/*.CR2 > $USBdrv/$MD5
echo "Success"
echo ""
echo "Hashing file from $USBdrv against hashes from $PHOTOdrv using hash file $MD5."
echo "If any files show up here they have become corrupt from the transfer from $PHOTOdrv"
md5deep -r -x $USBdrv/$MD5 $USBdrv/$DATEcode/*.CR2
echo "Done"
echo ""
echo "Copying photos to Remote Server"
scp -r "$USBdrv/$DATEcode/" $SSHuser@$SSHhost:$SSHdirectory
echo "Done"
echo ""
echo "Copying photos to Remote Server"
scp -r "$USBdrv/$MD5" $SSHuser@$SSHhost:$SSHdirectory/$DATEcode/
echo "Done"
echo ""
echo "Checking file integrity on remote server ($SSHhost in $SSHdirectory)"
ssh $SSHuser@$SSHhost 'md5deep -r -x $SSHdirectory/$DATEcode/$MD5 $SSHdirectory/$DATEcode/'
echo "Done"
echo ""
echo ""
echo "Tada!!"

Keep in mind this is a really basic, stupid, non-intuitive, poorly written script; which is also why is doesn’t contain a delete/remove command. The script assumes the cards are emptied after each one of these transfers (but does NOT delete the data itself.) It also prompts you for the password for the remote server three times so the password isn’t stored as plain text in the script.

This entry was posted in How To and tagged . Bookmark the permalink.

One Response to How to keep photos safe while on vacation.

  1. Kyle says:

    You can perform commands recursively without needing to invoke a separate binary.

    find * -type f | xargs openssl md5

Leave a Reply

Your email address will not be published. Required fields are marked *