Automatic iPhone Photo Backup Without iCloud
Requirements
Backing up photos from iPhone to an external hard drive is not as easy as it should be. It's easy if you want to use iCloud, but if you're reading this you're probably looking for an iCloud alternative. The iOS Shortcut described here aims to make the Camera Roll backup process easy if not trivial.
The following criteria was used as a guide while developing this script,
- Backup must occur daily without user intervention
- Three copies of photos must be generated; one on each of two media types, plus one offsite copy per the 3-2-1 backup strategy
- Live photos must be saved as their two component files; an .mp4 video and a .jpeg still.
- Utilize a chronological file naming convention
- Alert the user to the success or failure of each backup operation
- Play nice with all operating systems; Live photos, disk formatting, etc.
Implementation
The purpose of this script is to serve the personal photo backup needs of a common household. It assumes the user has an always-on computer to serve as the host of an external hard drive where photos are to be archived.
Hardware
In this implementation a Mac Mini serves as the family computer that is connected to a hard drive enclosure where local copies of the photos are stored. The hard drive enclosure used is an ORICO 2 Bay USB 3.0 to SATA enclosure. I opted for the model without RAID because for this application I prefer a simple, reliable architecture over blazing fast write speeds. Also because RAID is not a backup!
The drives used are two Seagate IronWolf 2TB NAS 3.5 inch SATA 5900 RPM disks. This choice was made as a balance between volume, price, and reliability. One disk will serve as the primary backup location and the secondary disk is an exact copy of the primary. Duplicating the primary disk reduces the risk of data loss due to disk failure, but it does not satisfy the "two different media" requirement of the 3-2-1 backup strategy.
In photography there is a saying that "the best camera is the one you're carrying." For most of us that camera also happens to be our phone. I happen to carry an iPhone 13 and my wife carries an iPhone 11. As much as I like iPhone hardware I don't love the idea of iCloud as photo backup platform. My daily driver PC is a Dell XPS 13 running Ubuntu so this backup solution needs to play nice with the family Mac Mini as well as my Ubuntu and Windows machines.
Software
I'm a fan of the iOS Shortcuts app as it allows me to script simple actions without having to dive into Swift and Xcode. -saving that for another day. One of the iOS Shortcuts actions is SSH. It allows you to SSH into another machine and execute commands. Importantly for this application it is capable of taking in blobs as arguments. This allows for blobs to be copied from an iPhone to another machine via SSH. That is the basis of how this backup script works; find recent photos in the device's Camera Roll, copy them to a remote machine in a loop via SSH.
Create dictionary of global variables
Get current WiFi SSID
If on home WiFi, proceed; else, skip to notification
List all files in storage location, count lines - used to count how many files are written to storage location
List all files in storage location in descending order, puts most recent file at top, strip off the most recent file, return 'date' in YYYY-mm-ddTHH:MM:SSz format
Find all photos in Camera Roll since 'date'
For each photo in returned photos
Get photo type
If photo type is Live Photo
Copy video component to storage location
Copy photo component to storage location
Else
Copy photo to storage location
End loop
List all files in storage location, count lines
Calculate difference between files in storage location after backup and before backup - return number of files saved during session
Show notification about backup results
This script it triggered by a iOS Shortcuts "Automation". Whenever my phone is connected to a charger this script will run. Typically I only plug in my phone to charge at night before bed. When I do this script runs and my photos are backed up and I have a 👍 notification before I ever close my eyes.
/Primary/
- Husband/
- - Photos/
- - - Phone/
- - - Camera/
- - Documents/
- Wife/
- - Photos/
- - - Phone/
- - Documents/
.
.
.
/Secondary/
- Husband/
- - Photos/
- - - Phone/
- - - Camera/
- - Documents/
- Wife/
- - Photos/
- - - Phone/
- - Documents/
This same Shortcut is installed on my wife's phone so that her photos are backed up in the same way. The primary backup disk is separated into two directories. One for me and another for her. We store other important files there, but this script happens to write files to Photos/Phone/
depending on whose phone is running the script.
To Be Continued
As of now this implementation does not satisfy the 3-2-1 backup strategy requirement,
- One off-site copy
- Two media types
- Three total copies of data
As described here, this script only creates two copies of the photos. -one copy on each of two different pieces of media, but on the same media type and no off-site copy. There's also the copy of the data that walks around with me in my phone. Strictly speaking that copy -the original- is typically considered to be a third copy and second media type (solid state in this case), but I'm choosing to ignore the copy on my phone as that copy is quite volatile.
As for the second media type, changing the primary disk to an SSD would satisfy that requirement. The unused primary spinning disk could be used as a 'cold storage' copy written to once per month perhaps and stored in a fireproof safe when not being used. That'd make it less suceptable to natural disasters than the external hard drive enclosure sitting on my desk as well as completely unsuceptable to hard drive controller/enclosure failure which some Amazon reivews for the ORICO enclosure warn about. Keeping a cold copy of the data in a safe does require human intervention to keep it up to date which contradicts one of the requirements I set for this project, but given that that copy is unnecessary to satisfy the 3-2-1 strategy we'll go ahead and call it a win.
Off-site storage is quite inexpensive these days and there are numerous choices when looking for a place to park your bits. Though I have not yet tried their service, I like what Backblaze has to offer. Expect a separate post on how I implement a workflow that copies local files to Backblaze.