This script takes all the jpg pictures inside the PICSSOURCE folder and backs them up into the PICSDESTINATION folder. The script reads the creation date of the pictures and based on that it creates folders with the year  and month (ie. 2014-08) to where the pictures are stored. Pictures without date information are copied into the “No-date” folder.

Download script

#!/bin/bash

# Backup your pictures
# By Juan C. Riano

# This script backups your JPG or JPEG pictures organizing them into folders by year and month.
# Folders are created only if they do not already exist.

# Dependencies: grep, awk, exif.

# Destination folder.
PICSDESTINATION='/home/juan/Pictures/'

# Source Folder
PICSSOURCE=~/Dropbox/pics

for file in $( ls $PICSSOURCE/*.{jpg,JPG,JPEG,jpeg} )
do 
	echo "Backing up $file"
	WHOLESTR=$( exif $file | grep 'Date and Time' | grep 'Origi' )
	THEDATE=$( echo "$WHOLESTR" | awk '{split($0,arr,"|"); print arr[2]}' )
	THEYEAR=$( echo "$THEDATE" | awk '{split($0,arr,":"); print arr[1]}' )
	THEMONTH=$( echo "$THEDATE" | awk '{split($0,arr,":"); print arr[2]}' )

	if [[ "$THEYEAR" == "" ]]	# Is there exif info for this picture?
	then
		THEFOLDER="$PICSDESTINATION/no-date"	# Pictures with no exif info.
	else 
		THEFOLDER="$PICSDESTINATION/$THEYEAR-$THEMONTH"	# Folder in format yyyy-mm
	fi
	
	# Create folder, ignore if folder already exists.
	$( mkdir -p "$THEFOLDER")

	# Copy files, change for mv if you want to delete original files.
	cp "$file" "$THEFOLDER"
done
echo "Completed backing up pictures."

If you rather delete the pictures, just changed the “cp” command for “mv”.

Use Dropbox and This Script to Backup your Cellphone Pictures

You can configure Dropbox to automatically backup your cellphone pictures to a folder in your Dropbox, then run this script to backup your pictures organized by date from your computer to an external hard drive.