Safely Backup Google Photos

With a smart phones in their pocket, most people don’t bother carrying a traditional camera anymore. For most, the single, double or even triple cameras on modern phones are great for making memories. Many Android and some iOS users have chosen to store their photos in the free or paid Google Photos service.

In the past phones were commonly connected to a PC to transfer data, music and photos. These days, cellphone users typically rely on WiFi or their carrier connection to backup photos and videos to ‘the cloud’, and rarely connect it to a computer for backups. Indeed many cellphone users have never physically connected their device to a PC.

Wouldn’t it also be handy to have a local backup of your treasured pictures? Perhaps to put on a photo frame, or to do some offline editing, or share with non-smartphone members of the family. There’s also the worry that the Google Photos service might one day go away, and so might your pictures.

gphoto-sync to the rescue!

gphoto-sync is an open source command-line tool written in Python. It’s purpose is to backup Google Photos and Albums using the Google Photos Library API. Once setup, it can be run on a regular basis, to ensure all the pictures stored in the cloud are also stored locally on your own storage.

Installing gphotos-sync

gphotos-sync is published in the Snap Store, so can be installed on a wide range of systems running popular Linux distributions. If your distribution lacks snap support, that can be added by following the simple directions at https://snapcraft.io/docs/installing-snapd

Installing gphotos-sync is as simple as snap install gphotos-sync. Don’t run the snap yet though, as it requires configuration to work correctly.

Configuration

Once installed there’s some configuration to do, which can be a little overwhelming initially, but only needs doing once.

The Snap Store page lists the steps required to setup gphotos-sync. Specifically:

  • Create a project on Google Developer Console – https://developers.google.com/console/ , following the Creating a project procedure – https://cloud.google.com/resource-manager/docs/creating-managing-projects
  • Authorize it to use the ‘Photos Library API’, following the Activating and deactivating APIs procedure – https://cloud.google.com/apis/docs/enable-disable-apis
  • Create a Client ID by following the setting up oauth 2.0 procedure with application type set to Other – https://support.google.com/cloud/answer/6158849
  • Once the client ID is created, download it as client_secret.json and save it under the application configuration directory ~/snap/gphotos-sync/current/.config/gphotos-sync – this directory won’t exist initially, so will need to be created by the user

Syncing photos

Decide on a folder into which you’d like the photos synced and make it. I use /home/alan/Photos. Create the folder then run gphotos-sync and point it to that folder.

$ mkdir /home/alan/Photos
$ gphotos-sync /home/alan/Photos

The application will start, and then request you click a URL. Take the URL and paste it into your browser where you should login under the Google account you wish to sync photos from. Once signed in, and permission granted to your photo collection, you’ll be presented with a response token. Copy and paste that back into the terminal running gphotos-sync.

03-03 13:16:01 WARNING  gphotos-sync 2.14.0 2020-03-03 13:16:01.333350 
Please go here and authorize, https://accounts.google.com/o/oauth2/….
Paste the response token here:

If successfully authorised, it will proceed to sync your photos. If not, you may need to do the above step again, taking care to login with the correct Google account, and copy the response token carefully.

03-03 13:16:04 WARNING  Downloading Photos … 

This may take a long time the first time you sync, especially if you have a large photo collection, or a slow connection to the Internet.

Monitoring the sync

gphotos-sync will keep a log of activity in the same folder your photos are synced to, called gphotos.log. The log is appended to while gphotos-sync runs, so is a good way to keep track of how the process is running.

$ tail /home/alan/Photos/gphotos.log
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23992 photos/2012/02/Img_287.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23993 photos/2012/02/Image463.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23994 photos/2012/02/Img_289.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23995 photos/2012/02/Picture0026.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23996 photos/2012/02/Image473.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23997 photos/2012/02/Img_293.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23998 photos/2012/02/0408141901189789_17ca85c0.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 23999 photos/2012/02/Image034.jpg
03-03 13:25:07 gphotos.GooglePhotosIndex INFO Indexed 24000 photos/2012/02/Image096.jpg
03-03 13:25:07 gphotos.LocalData INFO Saving Database …

Once complete you’ll get a short summary similar to:

03-03 13:26:08 WARNING  Downloaded 0 Items, Failed 2, Already Downloaded 37681
03-03 13:26:09 WARNING Done.

Periodic sync

A simple cron job can be created to regularly sync the photos. Set the interval to whatever is most appropriate based on your Internet connection speed and how often you take photos. For example to sync photos daily at 3AM, use.

0 3 * * * /snap/bin/gphotos-sync /home/(username)/Photos/

An hourly job might look like this:

0 * * * * /snap/bin/gphotos-sync /home/(username)/Photos/

Replacing (username) with your own username.

That’s it!

Once setup, you should be confident that your photos are now synced down to whichever computer you’re running gphotos-sync.

Posted in: