How to check from a script if files are all synced

Browsing the forum I found related questions:


I want a (python) script on Machine A to read and process files in a folder that is shared with other machines. At the start of the script, I want to check, maybe even block, if there are changes on the other machines that are not yet copied to Machine A.

One of the above questions mentions GET /rest/db/completion. I tried that (through the python API) by deleting a large number of files on one of the other machines, Machine B, and calling /rest/db/completion on Machine A’s syncthing instance with the folder ID and the machine id of both Machine A and Machine B. With the ID of Machine B it always returned 100, with the ID of Machine A it always returned 0. In the web GUI for Machine A I could see the status updating as it synchronized the file changes from Machine B. Something obviously isn’t working.

I tried /rest/db/status and it does show the state has changed form idle to syncing, so maybe that’s enough The completion percentage would be nice for user feedback though, and less output to deal with.

Is there a better way to do this? I’m not a REST expert and the discussion of the rest/events/ API in the above two threads didn’t quite make sense to me, but is that the way I should be going?

Yes, you should probably be using events, which uses long polling.

Right…so how? The example in the python API docs didn’t work. I’m cool with putting some curl calls in my script if needed, but I’m not a web developer so this REST stuff isn’t quite clear to me (sorry!). Do I do a GET /rest/events/StateChanged over and over in a loop? Do I just do it once and it won’t send me a response until an actual state change takes place?

Check chrome developer tools how web ui does it.

I’m realizing there isn’t really a concept of “sync done” with syncthing because it is continuously synchronizing files. It’s not rsync.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.