Recent Changes - Search:


Code:


Social:


My journals will take the place of a blog. If you go to the Journal page there is an RSS feed to subscribe with.

« July 2017 
SunMonTueWedThuFriSat
      1
2345678
9101112131415
16171819202122
23242526272829
3031     

Sites I take responsibility for

West Volusia, Florida

Documents

Technical

General

Me

Living

Places I frequent

Hobbies

Humor

Items for sale:


Clipboard

edit SideBar

How to copy photos from iOS devices such as iPhone and iPad to a Linux server

Include our styles below Infobox - invoke as >>infobox<< ... >><<

Codebox: - invoke as >>codebox<< ... >><<

warnbox: - invoke as >>codebox<< ... >><<

editingbox: - invoke as >>codebox<< ... >><<

noticebox: - invoke as >>codebox<< ... >><<

Page bread crumbs: Welcome to ke3vin.org! - My Public Technical Notes - Software And Operating Systems - Software - file Management Replication Archiving Backup And Recovery - rsync - recipes - How To Copy Photos From IOS Devices Such As I Phone And I Pad To A Linux Server

Pages by tags: (:listtags:)
Subscribe to this wiki: RSS Feed RSS or subscribe to this page for changes: RSS Feed RSS
496 articles have been published so far. Recent changes
Share

2016-03-22: This site is being moved to my main site at https://kevininscoe.com/wiki as part of a consolidation to one domain.


Most of the solutions I present here are free or have a completely free alternative.

Synopsis: I wanted a solution by which I did not have to use iTunes to sync with iPad (iPad: Generation 3, wi-fi only 64GB, iPhones: Gen 4, 8GB). As part of that goal I wanted pictures taken from these devices (mine, work, my iPad and my wife's iPhone) all to be stored to a particular directory on one of Linux servers that has a web server running on it.

The reason for this is depending on if the pictures are public or private I use either Gallery, Picasa or some custom Perl and PHP code to display my picture albums.

The ingredients you will need to complete this recipe:

  1. A Dropbox account.
  2. Either the iOS Dropbox app (Appstore link) on your iOS device (free) or I use CameraSync ($2.99 US) (Appstore link) simply because it names my pictures in date-stamp naming order which is important for me. I either case you will need the Dropbox app to upload to Dropbox file storage.
  3. rsync software (free) and Dropbox software (free) on your web enabled Linux server or desktop.

Steps to complete this recipe:

  1. Install Dropbox software on your web enabled Linux server or desktop. I won't go into how to do that that in this recipe but have a look at https://www.dropbox.com/install?os=lnx or http://www.dropboxwiki.com/tips-and-tricks/linux
  2. Install rsync software on your web enabled Linux server or desktop. I won't go into how to do that that in this recipe but have a look at http://www.linuxfromscratch.org/blfs/view/svn/basicnet/rsync.html
  3. Create a directory on your Linux host that will store the pictures. In my vase make sure this location is web or possibly network share enabled such as CIFS (SMB or Samba) or possibly NFS.
  4. Install Dropbox iOS app on your iOS device. Configure it with your login and create a directory in which to store your pictures from this iOS device. If you use Camera Upload you can get some extra free space in your account. See https://www.dropbox.com/help/287/en
  5. (Optional) Install CameraSync and configure it to use Dropbox and select the folder in which to sync pictures to. If you do this be sure to turn off Camera Upload in Dropbox or you will get duplicate differently names files.
  6. Ok so now perform a sync from CameraSync or upload your pictures using Camera Upload from the Dropbox app while connected to a wi-fi source. I don't recommend doing this from cellular unless you have very few pictures as it will be slow and it will eat up your available data plan. Hint: There is no such thing as "unlimited" in the 3G or 4G world.
  7. Now on your Linux host with Dropbox running in the background shortly these pictures should appear on your Linux host using the same folder name you choose before syncing.
  8. Because additional storage in Dropbox is expensive (the first 2GB + whatever Camera Uploads gives you is free) and you have this Linux host sitting here with likely terabytes of disk storage all for free why not leverage that for your picture management and archives? Ok we will need a simple script to get our pictures off of Dropbox and into a management archive on the Linux host. This is where rsync comes in.
  9. I use this simple script to rsync my pictures from the Dropbox folder and add them into my picture management system for further processing. The script then will erase the synced photos from the Dropbox folder allowing for more photos to be copied there and avoiding storage upgrade charges.

Here are the scripts I use from cron twice daily.

migrate_photos_from_dropbox_to_shares.sh:

#!/bin/csh -f

set DBDIR="`echo $HOME`/Dropbox"
set PHOTOS=/shares/sarah/from_ipads_and_iphones

foreach pdir ( "Kevin Inscoe Personal iPhone" "Kevin Inscoe’s HMH iPhone"
"Photos" "iPad Uploads" "Sarahs Photo" )

        set src="`echo $DBDIR`/`echo $pdir`"
        echo "Processing Dropbox folder $src ...."
        ls -ld "`echo $src`"
# add -b and --suffix=".dup" to avoid removing duplicate file names
        rsync -avb --suffix=".dup" --exclude=".dropbox" "`echo $src`/" "`echo
$PHOTOS`"
# Now remove the pictures we found on the Dropbox
        echo "Cleaning up Dropbox folder $src ...."
        ls -l "$src" | wc -l
        find "$src" -type f -exec rm {} \;
        ls -l "$src" | wc -l
# Now cleanup any duplicates with a new unique name ending in "dup" before the
file type
        find $PHOTOS -type f -name '*.dup' -ls -exec
$HOME/bin/migrate_photos_from_dropbox_to_shares_rename.sh {} \;
        echo "   "
        echo "   "
end

migrate_photos_from_dropbox_to_shares_rename.sh:

#!/bin/csh -f

if ($#argv < 1 ) then
        echo "Usage: $0 filename.dup"
        echo "Renames a duplicate file after using rsync -b --suffix=".dup".
Intended to be run from migrate_photos_from_dropbox_to_shares.sh for more info."
        exit 1
endif

set myfile="$1"

# Check if myfile exists
if (! -f "$myfile") then
        echo "$myfile does not exist"
        exit 1
endif

set tempa="/tmp/migrate_photos_from_dropbox_to_shares_renamea.tmp"
set tempb="/tmp/migrate_photos_from_dropbox_to_shares_renameb.tmp"

if ( -e $tempa ) rm -f $tempa
if ( -e $tempb ) rm -f $tempb

# We must be good then proceed...

# What are we going to call this file then?
set newfiledir="`dirname $myfile`"
echo "newfiledir=$newfiledir"

set newfiletmpa="`basename $myfile`"
echo "newfiletmpa=$newfiletmpa"
set newfiletmp="`echo $newfiletmpa | sed -e 's/\.dup//g'`"
echo "newfiletmp=$newfiletmp"

# Now I need just the filename and the file type (to the right of the ".") from
variable newfiletmp

# Grab the file type from the filename
echo $newfiletmp > $tempa 
gawk -F. '{if (NF>1) {print $NF}}' $tempa > $tempb
set newfiletyp="`head -n 1 $tempb`"
echo "newfiletyp=$newfiletyp"

# Now I need just the file name by itself
echo $newfiletmp > $tempa 
# I am making a big assumption here that all files will only have one dot "." in
the name
# but that would be true in image files taken from a camera (.png or .jpg)
otherwise I
# have a lot morecode here to grab only the last dot from the file name. Ahh
thank you MS-DOS
gawk -F. '{print $1}' $tempa > $tempb
set newfilename="`head -n 1 $tempb`"
echo "newfilename=$newfilename"


set newfile="`echo $newfiledir`/`echo $newfilename`_dup.`echo $newfiletyp`"

echo "Renaming file $myfile to $newfile..."

#mv -v "$$myfile" "$newfile"

if ( -e $tempa ) rm -f $tempa
if ( -e $tempb ) rm -f $tempb

Here is some sample Perl code I wrote to rename JPEG's (with Exif data embedded) to date stamp format from legacy cameras that name files in the format IMG_0057.JPG.

rename_jpegs_to_datestamp.pl:

#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use Image::Magick;
use List::Util 'first';  

my $dir = $ENV{'PWD'};
#my $view = $ENV{'VIEW'};
my $image;
my
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks);
my $dsize;
my $a;
my @exif;
my $match;
my ($exdate, $extime);
my $newfile;

chomp(my @files = `ls $dir`);

print "$0: Starting at " . `date` ."\n";

foreach my $file (@files) {
  if ($file =~ /\.(jpg|jpeg|JPG|JPEG)/) {
#      
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
= stat($file);
#       print "file=$file\n";
# Get Exif data
        $image = Image::Magick->new();
        $image->Read($file);
        $a = $image->Get('format', '%[EXIF:*]'); # two arguments
        @exif = split(/[\r\n]/, $a);
#       print join("\n", @exif);
# Locate the DateTime EXIF field
        $match = first { /exif:DateTime=/ } @exif;
#       if ( $match ne "" ) {
        if ( length $match ) {
                $match =~ s/exif:DateTime=//;
#               print "\n\nExif DateTime: $match\n";

# Now rename the file to the format 2012-12-23 at 07.29.02.jpg
# $match now yields 2012:12:23 19:17:33
                ($exdate, $extime) = split(/ /,$match);
                $exdate =~ s/:/-/g;
                $extime =~ s/:/./g;
#               print "exdate=$exdate, extime=$extime\n";
                $newfile = $exdate . " at " . $extime . ".jpg";
                if ( $file ne $newfile ) {
                        rename $file, $newfile || die ( "Error in renaming
$file!!\n" );
                        print "\nFile $file has been renamed to $newfile\n";
#                       `ls "$newfile"`;
                }
        } else {
#               print "No Exif data!\n";
        }
#       print "\n--------------------\n";
  }
}

print "$0: Ended at " . `date` ."\n";

Notes:

The reason I use CameraSync to synchronize my photos to Dropbox rather than the Dropbox app itself is because I have greater flexibility in the CameraSync application. For instance Dropbox only seems to allow (as of this writing) uploads to the folder "Camera Uploads" and since I share multiple devices with the same Dropbox account I wanted to keep them separate for file collision purposes. Also CameraSync seems to do a better job of file naming based on time stamp and syncing only what's new to the Photo Roll. But as I say above you can certainly perform this task using just the free Dropbox app.


Kevin's Public Wiki maintained and created by Kevin P. Inscoe is licensed under a
Creative Commons Attribution 3.0 United States License.

Back to my web site - http://kevininscoe.com

Edit - History - Print - Recent Changes - Search
Page last modified on July 20, 2013, at 08:58 AM EST