bthoven Posted November 28, 2022 Share Posted November 28, 2022 (edited) Objective: to automatically perform indexing, every hour, for new photos in my PhotoPrism original folder, without using an import folder or WebDAV in PhotoPrism. I already have a shared folder on my Unraid, name 'Google Photos', which allows SMB share. I'm using a FolderSync app on my Android phone to sync, one way, photos on my phone every hour to 'Google Photos' folder on my Unraid. I also have another phone which also runs Foldersync app which also syncs, one way, to the same 'Google Photos' folder on my Unraid. So basically, my 'Google Photos' contains all photos originated from my mobile phones. After I started using PhotoPrism by specifying 'Google Photos' as its original folder (or 'Storage Path' on Unraid docker webui), I had a 'complete Rescan' once to index all the existing photos/videos. Since then, I've been struggling to find a way to automate a scheduled rescan for only changes in my 'Google Photos' folder. As PhotoPrism only supports such feature with WebDAV sharing folder only, and Unraid does not support WebDAV share, I can only do it manually on it webui (Libraray sidebar --> Index tab --> Start button). So I need to find another way. The solution is to run 'photoprism index' command in the PhotoStream container and scheduling its run with a cron job. The command is basically the same as when you manually rescan the folder with PhotoPrism webui (Libraray sidebar --> Index tab --> Start button) If you don't have a 'User Scripts', you have to install it first from Unraid APPs repositories, and we will have a webui to create a bash script and a new schedule. It's just a webui for easy bash script and cron job creation. Pls see the attached screenshots For my PhotoPrism container, the bash script will be: #bin/sh cd /mnt/user/Google\ Photos docker exec -t PhotoPrism photoprism index where '/mnt/user/Google\ Photos' is my 'Google Photos' shared folder containing all photos/videos (need back slash behind 'Google' because I have a space in my folder name 'Google Photos'. I should rename it to 'Google_Photos') 'PhotoPrism' is my PhotoPrism container name (what you input as 'Name:' when you define the docker via Unraid Webui, see the attached screenshot) 'photoprism index' is a PhotoPrism known command to perform the indexing again. Or what the bash script does is performing indexing of photos/videos inside /mnt/user/Google Photos/ folder, by looking for only the changes in the folder. Note: your PhotoPrism docker must be running/started for this to work. If you have only a few new photos added to 'Google Photos' folder, it took only less than a minute to sync/index. Hope this helps. Screenshot: Docker parameter User Scripts 'PhotoPrismSync' How it works behind the scene: Edited November 29, 2022 by bthoven make some clarification 3 Quote Link to comment
DannoUK Posted March 28, 2023 Share Posted March 28, 2023 Massive thanks for this post!! Worked a treat! Quote Link to comment
DanielPT Posted December 5, 2023 Share Posted December 5, 2023 Wow that is nice! But alot of work for a simple thing? I tryed this but it is not working. https://docs.photoprism.app/user-guide/users/cli/ Quote Link to comment
DanielPT Posted December 6, 2023 Share Posted December 6, 2023 Okay my command above does not work So i tryed youre script. But i dont understand why it is not removing the 3 files i deleted though SMB in my "test" path Quote Link to comment
JDBaron25 Posted December 16, 2023 Share Posted December 16, 2023 Thanks for this!!! Worked great! 1 Quote Link to comment
rob_robot Posted February 9 Share Posted February 9 On 12/6/2023 at 7:46 PM, DanielPT said: So i tryed youre script. But i dont understand why it is not removing the 3 files i deleted though SMB in my "test" path For this you would need to use the --cleanup option as cleanup and index are separate operations. i.e. #!/bin/bash docker exec PhotoPrism photoprism index docker exec PhotoPrism photoprism index --cleanup Quote Link to comment
rob_robot Posted February 9 Share Posted February 9 Below a variant of the shell script creating a lock file, so you can increase the frequency of the cron job (i.e. every 10min) while ensuring at the same time that there won't be overlapping cron jobs in parallel: The script is checking for stale lock files after a threshold of 18 hours. #!/bin/bash # Define a lock file to track the process lock_file="/mnt/user/appdata/photoprism/photoprism_index.lock" # Check if the lock file exists if [ -f "$lock_file" ]; then # Get the timestamp of the lock file lock_timestamp=$(date -r "$lock_file" +%s) current_timestamp=$(date +%s) max_duration=$((1080 * 60)) # Maximum duration in seconds (18 hours) # Calculate the time difference between now and the lock file creation duration=$((current_timestamp - lock_timestamp)) # Check if the process is still running (based on duration) if [ "$duration" -lt "$max_duration" ]; then echo "$(date '+%Y-%m-%d %H:%M:%S') Photoprism index is still running. Skipping." exit 0 else echo "$(date '+%Y-%m-%d %H:%M:%S') Stale lock file found. Proceeding." fi fi # Create the lock file to indicate the process has started touch "$lock_file" # Function to remove the lock file on script exit remove_lock_file() { rm -f "$lock_file" } trap remove_lock_file EXIT docker exec PhotoPrism photoprism index docker exec PhotoPrism photoprism index --cleanup Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.