Skip to content

CLI: Backup command fails when a custom filename is specified #5088

Description

@tvangemert

1. What is not working as documented?

The documentation specifies that you can supply a custom file name to the photoprism backup command. But, this works only if there exists a default, date-coded (e.g., 2025-07-01.sql) database dump file. If not, the backup command with custom filename fails, reporting "found no database backup files" or "[filename] already exists".

The reported errors are not correct and I think the expected behavior is that a database dump would be created with a custom filename, even if there are no existing files.

2. How can we reproduce it?

Steps to reproduce the behavior — in a terminal where PhotoPrism is running, run the following commands:

# Remove all existing dump files
rm [PATH TO STORAGE DIR]/storage/backup/mysql/*.sql
# Run the backup command with a custom filename.
docker compose exec photoprism photoprism backup -i photoprism_db_dump.sql

INFO[2025-07-03T08:27:33Z] Become a member today, support our mission and enjoy our member benefits! 💎
INFO[2025-07-03T08:27:33Z] Visit https://www.photoprism.app/membership to learn more.
ERRO[2025-07-03T08:27:33Z] failed to create database backup: photoprism_db_dump.sql already exists
# Try again, but force overwrite with -f
docker compose exec photoprism photoprism backup -i -f photoprism_db_dump.sql

INFO[2025-07-03T08:27:44Z] Become a member today, support our mission and enjoy our member benefits! 💎
INFO[2025-07-03T08:27:44Z] Visit https://www.photoprism.app/membership to learn more.
INFO[2025-07-03T08:27:44Z] backup: server supports zero-configuration ssl
INFO[2025-07-03T08:27:44Z] backup: replacing database backup file photoprism_db_dump.sql
ERRO[2025-07-03T08:27:44Z] failed to create database backup: found no database backup files in /photoprism/storage/backup/mysql
# Create a dump file with default options
docker compose exec photoprism photoprism backup -i

INFO[2025-07-03T08:27:53Z] Become a member today, support our mission and enjoy our member benefits! 💎
INFO[2025-07-03T08:27:53Z] Visit https://www.photoprism.app/membership to learn more.
INFO[2025-07-03T08:27:53Z] backup: server supports zero-configuration ssl
INFO[2025-07-03T08:27:53Z] backup: creating database backup file 2025-07-03.sql
INFO[2025-07-03T08:27:53Z] completed in 261.225716ms
# Now the command with a custom file name works as expected.

docker compose exec photoprism photoprism backup -i -f photoprism_db_dump.sql

INFO[2025-07-03T08:27:59Z] Become a member today, support our mission and enjoy our member benefits! 💎
INFO[2025-07-03T08:27:59Z] Visit https://www.photoprism.app/membership to learn more.
INFO[2025-07-03T08:27:59Z] backup: server supports zero-configuration ssl
INFO[2025-07-03T08:27:59Z] backup: replacing database backup file photoprism_db_dump.sql
INFO[2025-07-03T08:27:59Z] completed in 277.577403ms

3. What behavior do you expect?

  1. The first error "failed to create database backup: photoprism_db_dump.sql already exists" appears to be incorrect: there are no files in the /photoprism/storage/backups/mysql/ directory at all, so the file does not exist. I would expect this error to not occur.
  2. The second error "failed to create database backup: found no database backup files in /photoprism/storage/backup/mysql" is correct, but this should not cause the backup to fail. If there are no existing files, the database dump should proceed and effectively ignore the -f option since it is irrelevant.
  3. When the custom file name backup succeeds, the INFO message is incorrect: "backup: replacing database backup file photoprism_db_dump.sql". There is no existing file, so it cannot have been replaced.

Expected behavior: a valid database dump file is created with the specified file name. The default, date-coded database dumps work as expected (confirmed with multiple backup/restore tests).

4. What could be the cause of your problem?

I am really not sure. Perhaps the fact that the retain backups option tries to check (non-existing) files, which may be handled gracefully for the standard date format but not custom file names?

5. Can you provide us with example files for testing, error logs, or screenshots?

The reproduction steps above are my terminal input/output copied verbatim. I hope that suffices, otherwise let me know what would help.

6. Which software versions do you use?

(a) PhotoPrism Architecture & Build Number: Build 250426-27ec7a128-Linux-AMD64-Plus

(b) Database Type & Version: MariaDB 11

(c) Operating System Types & Versions: Linux (Ubuntu 24.04 64-bit), PhotoPrism is running in Docker version 28.3.0, build 38b7060.

(d) Browser Types & Versions: Firefox

(e) Ad Blockers, Browser Plugins, and/or Firewall Software? Sure, but doesn't seem relevant to this issue.

7. On what kind of device is PhotoPrism installed?

This is especially important if you are reporting a performance, import, or indexing issue. You can skip this if you're reporting a problem you found in our public demo, or if it's a completely unrelated issue, such as incorrect page layout.

(a) Device / Processor Type: AMD Ryzen 7 5800X (LXC container with 4 cores assigned)

(b) Physical Memory & Swap Space in GB: 4GB & 2GB

(c) Storage Type: ZFS with HDDs for originals, import, and storage + SSD for cache/ dir.

(d) Anything else that might be helpful to know?

The PhotoPrism instance is running in Docker Compose using the file provided by your documentation with minor adjustments.

8. Do you use a Reverse Proxy, Firewall, VPN, or CDN?

Sure, but I think that is unrelated.

Metadata

Metadata

Assignees

Labels

cliCommand-Line Interface (CLI)databaseDatabase Abstraction, Backup and OptimizationreleasedAvailable in a stable releasetestedChanges have been tested successfully

Type

Fields

No fields configured for Bug.

Projects

Status
Release 🌈

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions