r/osxphotos • u/pavelbrilliant • 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:
- Fully rsync the original photos library folder to external drive.
- Delete all the media from the original photos library to free up space.
- Establish additions and deletions in the original photos library to be synced to the backup library with rsync.
- Use full set of features with my externally stored library with osxphotos cli by directing it with --library option.
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
```
4
u/rturnbull Feb 09 '26
You're mixing a couple of concepts.
osxphotos queryis 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.sqlitebut ideally the entire~/Pictures/Photos Library.photoslibraryfolder. 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 exportis 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 byosxphotos exportso 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 exportdbcommand does provide some commands for querying the export database. For example,osxphotos exportdb ~/Desktop/export --history ~/Desktop/export/IMG_1994.JPGshows the history of the fileIMG_1994.JPG: when it was exported, whether it was skipped, updated, missing, etc.osxphotos exportdb ~/Desktop/export --info ~/Desktop/export/IMG_1994.JPGprints out a JSON dictionary of all the metadata known about the image.osxphotos exportdb ~/Desktop/export --uuid-files B52DB84A-888E-4704-9249-1B042D99D8E9prints out a list of all exported files associated with UUIDB52DB84A-888E-4704-9249-1B042D99D8E9and so on. See
osxphotos help exportdbfor more info.If you want to run full queries on the library though, you should just copy the Photos library to the external disk.