My hardware:
The (re)naming convention assures unique file names for photos coming from my camera until I get to 10,000,000 photos. At my current rate of taking pictures, that would be several thousand years. It also allows me to easily manage my photos by year, month, or day (and eventually decade) as I choose.
I've written a script to automatically copy and rename my files from the CF card to an appropriate directory on the server when it is run.
I'll be adding code/comments as I improve this script.
- Canon Rebel XTi (uses Compact Flash (CF) memory)
- Inland USB multi-format SD/CF card reader ($12 at Micro Center)
- Dell PowerEdge 1800 running Fedora Core 11
run the script, and end up with the same files, transferred to the server and renamed like this:[CF Card]/dcim/102canon/img_9999.CR2 [CF Card]/dcim/102canon/img_9999.JPG [CF Card]/dcim/103canon/img_0000.cr2 [CF Card]/dcim/103canon/img_0000.jpg
Removal of files from CF card is performed manually by the Format function on the camera, once I'm sure all the files have survived the trip from CF to hard drive.[server photo repository]/2009/200902/20090215/img_1029999.cr2 [server photo repository]/2009/200902/20090215/img_1029999.jpg [server photo repository]/2009/200902/20090215/img_1030000.cr2 [server photo repository]/2009/200902/20090215/img_1030000.jpg
The (re)naming convention assures unique file names for photos coming from my camera until I get to 10,000,000 photos. At my current rate of taking pictures, that would be several thousand years. It also allows me to easily manage my photos by year, month, or day (and eventually decade) as I choose.
I've written a script to automatically copy and rename my files from the CF card to an appropriate directory on the server when it is run.
#!/bin/ksh
startdir=`pwd`
cfsourcedir="/mnt/usb"
# make sure to use your device name here, check output of 'dmesg' \
# on your server with card reader connected.
cfdeviceid="/dev/sdc1"
canondir="${cfsourcedir}/dcim"
datepath="/photos/raw/`/bin/date +%Y/%Y%m/%Y%m%d`"
sudo umount $cfsourcedir
sudo mount $cfdeviceid $cfsourcedir
result=$?;
if [ $result -eq 0 ];then
if [ -d $datepath ]; then
echo "Directory $datepath exists"
else
mkdir $datepath
fi
#echo "canondir: $canondir"
#echo "datepath: $datepath"
rsync -az $canondir/* $datepath --stats --progress | \
tee -a /tmp/loadfromcf.out
cd $datepath
for i in `find -type d |sed 's/^.\///g' |grep -v ^\.$`
do
cd $i
directorynumber=`echo $i | sed 's/CANON//g' |sed 's/canon//g'`
for j in `ls -1 *`
do
k=`echo $j |sed "s/img_/img_$directorynumber/g" |\
sed 's/IMG_/IMG_${directorynumber}/g' |sed 's/JPG/jpg/g' |sed 's/CR2/cr2/g'`
mv $j ../$k
chown speed:speed ../$k
chmod 0544 ../$k
done
cd ..
rmdir $i
done
fi
sudo umount /mnt/usb
if [[ $result = 0 ]];then
grep -i Number /tmp/loadfromcf.out | tail -2
pwd
fi
I've also contemplated modifying this script so it would automatically (cron) check for a CF card in the reader, then automatically start the copying process. If I make this modification, I'll post it here as well.I'll be adding code/comments as I improve this script.
Leave a comment