A simple container for automatic daily Photoprism backups to a Restic backend.
Go to file
2024-07-25 14:12:59 +01:00
.gitignore added gitignore [CI SKIP] 2024-07-25 14:12:59 +01:00
.woodpecker.yml general updates 2024-07-24 20:48:58 +01:00
backup.sh general updates 2024-07-24 20:48:58 +01:00
Dockerfile initial commit 2022-09-20 12:21:56 +01:00
entry.sh initial commit 2022-09-20 12:21:56 +01:00
README.md updated READMEs [CI SKIP] 2024-07-25 14:12:36 +01:00

Photoprism Backup

A simple script for backing up a Photoprism instance periodically and securely using Restic.

This script backs-up to any Restic backend that you can configure using environment variables (e.g. an S3-compatible bucket). It backs up once per day.

The following are backed-up:

  • The MariaDB database (via a dump)
  • The originals directory (depending on where you mount the backup volume)

Note: only backing-up the originals directory may not be sufficient. However, in my use-case, this backup system serves as a last resort, and I know I can re-generate other required files from the original data.

Motiviation

Whilst Photoprism provides its own backup facility, I wanted something that I could easily run/manage using a separate container.

Usage

Simply write a docker-compose.yml along the following lines:

services:
  photosbackup:
    image: wilw/photoprism-backup
    restart: always
    volumes:
      - /path/to/originals:/photoprism/originals # Mount a parent directory instead to backup more than just the originals
    environment:
      - PHOTOPRISM_DATABASE_SERVER=mariadbUri
      - PHOTOPRISM_DATABASE_NAME=photoprism
      - PHOTOPRISM_DATABASE_USER=photoprism
      - PHOTOPRISM_DATABASE_PASSWORD=<password>
      
      # ... Restic configuration. E.g.:
      - AWS_ACCESS_KEY_ID=accesskey
      - AWS_SECRET_ACCESS_KEY=secretaccesskey
      - RESTIC_REPOSITORY=s3:endpoint/bucket
      - RESTIC_PASSWORD=complexstring
      - RESTIC_HOSTNAME=hostname

Before bringing the container up, please read the following:

Please remember to change the variables in the environment block:

  • PHOTOPRISM_DATABASE_*: Connection details to your Photoprism MariaDB server. This is easier if you include the photosbackup service in the same docker-compose.yml as your other Photoprism components.
  • RESTIC_REPOSITORY: The repository name. For a Linode Object Storage bucket you can use s3:eu-central-1.linodeobjects.com/bucket-name. See below for other examples.
  • RESTIC_PASSWORD: The string used to encrypt/protect your data. Use a long complex string, and don't lose it (or you'll lose your backups)
  • RESTIC_HOSTNAME: Set this to an identifier for the machine. If you don't, the Docker container ID will be used, which changes on each startup, which isn't ideal.

And also to add the variables required for your chosen Restic backend. For example, for S3.

You can now bring up the container: docker compose up -d.

Important

After the container is launched for the first time, if you haven't already, you'll need to initialize the repository. You only need to do this once for each repository. To do so, run something along the lines of the following:

docker compose exec -it photosbackup /usr/bin/restic init

Defaults

The image wilw/photoprism-backup (which you can use as described above) does the following:

  • Backs-up originals and the SQL dump daily
  • Keeps 7 daily, 4 weekly, and 6 monthly backups, and prunes the rest

To change this behaviour, just edit the backup.sh file and rebuild the image.

RESTIC_REPOSITORY syntax

Many providers offer S3-compatible storage. Below are a few examples for help with setting the RESTIC_REPOSITORY variable:

  • Linode: s3:eu-central-1.linodeobjects.com/bucket-name
  • Amazon S3: s3:s3.amazonaws.com/bucket-name
  • Minio: s3:http://localhost:9000/repo-name
  • Wasabi: s3:https://serviceURL/bucket-name

Refer to the documentation for more information.

For some services, such as Backblaze B2, other environment variables are needed, such as B2_ACCOUNT_ID and B2_ACCOUNT_KEY.

More

To learn more about Restic, restoring backups, management, and more, please refer to the official documentation.