Skip to content

Instantly share code, notes, and snippets.

@toodooleedoo
Last active January 6, 2016 13:48
Show Gist options
  • Save toodooleedoo/1995ee11655165a0bc95 to your computer and use it in GitHub Desktop.
Save toodooleedoo/1995ee11655165a0bc95 to your computer and use it in GitHub Desktop.

#Photo Organizer and backup utility

##Description Integrates photos taken from me and my wifes Androids to my Google Drive using some 3rd party tools. This allows me to integrate photos into my personal workflow which includes utter paranoia of losing my pictures :)

  • Snap Picture on an Android
  • Bittorrent sync places it on my linux box in ~/BTS/Androids/
  • Script does a find to look for any new photos via cron using linux find
  • If new photo is found sortphotos is triggered which examines EXIF data and moves to my master photo collection
  • Bittorrent Sync has my master photo collection spread out between some internal PC's (its a folder sync program)
  • Rclone pushes those files to my Google Drive to serve as my remote backup.
  • LFTP transfers these files to an FTP server running in my LAN

Within a minute I can find an Android photo from my wifes phone in my Google Photos (have Google Photos show pics from Google Drive). I still do the Google free photo storage on my Android devices using there free storage quality.

##Requires these utilities setup.

You will most likely need to change paths in the script but it's an easy read.

#!/bin/bash
LOCKFILE=/tmp/sort-sync-ftp-to-shield-and-backup-to-googledrive.sh.lock
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "`date` - already running"
exit
fi
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
echo $$ > ${LOCKFILE}
echo "STARTED: `date`";
Y=`date '+%Y'`
PHOTODIR="/mnt/Jeepers/Media/SharedPictures"
BTSDIR="/mnt/Jeepers/BTS/Androids"
BACKUPDIR="/mnt/Cheezits/Backups/"
STARTCOUNT="`find /mnt/Jeepers/Media/SharedPictures/${Y} -type f |wc -l`"
python /usr/local/bin/sortphotos.py -c -r ${BTSDIR} ${PHOTODIR} > /dev/null 2>&1
ENDCOUNT="`find /mnt/Jeepers/Media/SharedPictures/${Y} -type f |wc -l`"
echo "${STARTREMOTECOUNT}"
if [ "${STARTCOUNT}" != "${ENDCOUNT}" ]; then
STARTREMOTECOUNT="`/usr/sbin/rclone size remote:SharedPictures/${Y} |tail -n2 |head -n1 |sed -e 's/.*: //g;'`" > /dev/null 2>&1
/usr/sbin/rclone sync ${PHOTODIR}/${Y} remote:SharedPictures/${Y} > /dev/null 2>&1
ENDREMOTECOUNT="`/usr/sbin/rclone size remote:SharedPictures/${Y} |tail -n2 |head -n1 |sed -e 's/.*: //g;'`" > /dev/null 2>&1
#lftp -e "mirror -R /mnt/Jeepers/Media/SharedPictures Pictures/;exit" ftp://shield:2221 -u user,pass
rsync -a ${PHOTODIR} ${BACKUPDIR}
#rsync -a --delete ${PHOTODIR}/ /mnt/Jeepers/SharedPictures
echo "Start Count: ${STARTCOUNT}";
echo "End Count: ${ENDCOUNT}"
echo "Remote Start Count: ${STARTREMOTECOUNT}"
echo "Remote End Count: ${ENDREMOTECOUNT}"
echo "Copied to Google Drive, Nvidia Shield, and rsynced to backups and staging dir";
else
echo "Found ${STARTCOUNT}. No New Pictures Added Exiting Now";
fi
echo "FINISHED: `date`";
rm -f ${LOCKFILE};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment