Jump to content

PhotoPrism - How I use a simple User Script to automate scheduled sync (without webdav)

Recommended Posts

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:


cd /mnt/user/Google\ Photos

docker exec -t PhotoPrism photoprism index


'/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.




Docker parameter



User Scripts 'PhotoPrismSync'





How it works behind the scene:


Edited by bthoven
make some clarification
  • Like 3
Link to comment
  • 3 months later...
  • 8 months later...
  • 2 weeks later...
  • 1 month later...
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. 



docker exec PhotoPrism photoprism index
docker exec PhotoPrism photoprism index --cleanup


Link to comment

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. 



# Define a lock file to track the  process

# 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
            echo "$(date '+%Y-%m-%d %H:%M:%S') Stale lock file found. Proceeding."

    # 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






Link to comment

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.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...