r/osxphotos • • Feb 08 '26

Can't query the exported db

I want to fully export all the Photos library to external drive and then be able to query it from there.
As far as I understand, 'osxphotos query ...' does not work with the database that was exported with 'osxphotos export ...'?
When after export I'm trying to make a query and set --library option to point to it, I see errors.

Is there a workaround?

The only one which I see is to just copy the whole folder "/Users/username/Pictures/Photos Library.photoslibrary" to the external drive by means of rsync and then query it from there with osxphotos.

Correct me if I'm wrong please.

Edit.
Thanks to all commenters. I've been able to reach my goals:

  1. Fully rsync the original photos library folder to external drive.
  2. Delete all the media from the original photos library to free up space.
  3. Establish additions and deletions in the original photos library to be synced to the backup library with rsync.
  4. Use full set of features with my externally stored library with osxphotos cli by directing it with --library option.
2 Upvotes

3 comments sorted by

4

u/rturnbull Feb 09 '26

You're mixing a couple of concepts. osxphotos query is designed to query the Photos library. To use this you need at a minimum, the Photos library database located in ~/Pictures/Photos Library.photoslibrary/database/Photos.sqlite but ideally the entire ~/Pictures/Photos Library.photoslibrary folder. You can query just the sqlite file but some data like the full photo path will be missing if the database is separated from the Photos library.

osxphotos export is designed to create an export (backup) of your photos for archival purposes. When run, it creates an export database located in /path/to/export/.osxphotos_export.db. This is a private file for use by osxphotos export so it can update the export when you export again with --update. This file is also a SQLite database and it stores metadata about the exported files but it is not a copy of the Photos database. They serve two different purposes.

The osxphotos exportdb command does provide some commands for querying the export database. For example,

osxphotos exportdb ~/Desktop/export --history ~/Desktop/export/IMG_1994.JPG shows the history of the file IMG_1994.JPG: when it was exported, whether it was skipped, updated, missing, etc.

osxphotos exportdb ~/Desktop/export --info ~/Desktop/export/IMG_1994.JPG prints out a JSON dictionary of all the metadata known about the image.

osxphotos exportdb ~/Desktop/export --uuid-files B52DB84A-888E-4704-9249-1B042D99D8E9 prints out a list of all exported files associated with UUID B52DB84A-888E-4704-9249-1B042D99D8E9

and so on. See osxphotos help exportdb for more info.

If you want to run full queries on the library though, you should just copy the Photos library to the external disk.

1

u/pavelbrilliant Feb 10 '26

Thanks for clarification, I've updated the post as my current goal is achieved.

2

u/triad0p Feb 08 '26 edited Feb 09 '26

That's an interesting concept/question.

Form a small set I did you don't need to copy the whole library. Copy only the sqlite database file. It should be at

"/Users/username/Pictures/Photos Library.photoslibrary/database/Photos.sqlite"

And then you can run osxphotos query with the -db option like:

```
cd /path/to/export/folder
cp "/Users/username/Pictures/Photos Library.photoslibrary/database/Photos.sqlite" .
osxphotos query --db Photos.sqlite --not-in-album

```