Backing up Google Photos with Docker

In this article I'll be using the rclone Docker container and a cron job to back up my Google Photos to my NAS every night.

Rclone ("rsync for cloud storage") is a command-line program to sync files and directories to and from different cloud storage providers.

Creating a config file

First we'll have to create a config file for the docker container. To do this we'll start an rclone docker container and use the interactive menu.

Start the container with the command below and run. Make sure to edit the path of the config folder. This will be the place where the config is generated.

docker run -ti --rm \
	--volume=/path/to/your/local/config:/config/rclone \
	--entrypoint=/bin/sh \
	rclone/rclone

Then follow this guide to give rclone access to your Google Photos account.

Setting up the automatic back up

Now all we have to do is run a sync command every night. For this, add the following command to your cron jobs:

0 2 * * * docker run --rm --name=rclone-google-photos --user 1000 --volume=/data/config/rclone:/config/rclone --volume=/tank/Backups:/data rclone/rclone sync GooglePhotos: /data/GooglePhotos --tpslimit 30 --log-file=GooglePhotos/logs/`date +\%Y\%m\%d_\%H\%M\%S`.txt --log-level INFO
  • 0 2 * * *: cron schedule
  • --user 1000: Pass the id of your local user as user id to the container. You can get yours by running id.
  • --volume=/data/config/rclone:/config/rclone: Pass the config folder as a volume. This is the same we did when creating the config.
  • --volume=/backups:/data: Mount the folder where you want your backup.
  • sync GooglePhotos: /data/GooglePhotos: rclone command. This will sync the GooglePhotos volume you just configured to /data/GooglePhotos. Since I mounted /data to /backups in the parameter above. So my photos will appear in /backups/GooglePhotos on my host machine.
  • --tpslimit 30: Limit the HTTP transactions to 30/s. This will prevent you from reaching the maximum limit on the Google Photos api.
  • --log-file=GooglePhotos/logs/`date +\%Y\%m\%d_\%H\%M\%S`.txt (optional)
  • --log-level INFO: (optional)

Note on the folder structure

Below you can see the folder structure the download from Google Photos will create. Same same photo will be in multiple folders.

For example: all folders under media/ will contain the same pictures, just in different folder structures.

.
├── album
│   ├── ...
├── feature
│   └── favorites
├── media
│   ├── all
│   ├── by-day
│   ├── by-month
│   └── by-year
└── shared-album
    ├── ...

91 directories, 18 files

Depending on the way you want to back up your photos, you can just synchronize the folder you want by appending it to the GooglePhotos: part in the Docker command.

Example that only syncs the /media/by-month folder:

docker run --rm \
    --name=rclone-google-photos \
    --user 1000 \
    --volume=/data/config/rclone:/config/rclone \
    --volume=/tank/Backups:/data \
    rclone/rclone \
    sync GooglePhotos:/media/by-month /data/GooglePhotos \
    --tpslimit 30 \
    --log-file=GooglePhotos/logs/`date +\%Y\%m\%d_\%H\%M\%S`.txt \
    --log-level INFO