API or way to check sync status from commandline / Bash script?

Recommended Posts

I noticed today just by accident that one of my folders was stuck at 100% - sync was not completing for some reason. I had to enable debug mode and found a file that had a weird resource fork for whatever reason was causing the sync to hang. I deleted that file, restarted Sync on both ends and it was green again.

So the question is:  I would like to know if there is any way to get the sync status via command line / Terminal / bash? I would make a periodic script (cron, LaunchAgent on mac etc) to run and if the sync is not complete then maybe pop a notification, send an alert to Pushover etc. Bonus points if the command could output in an easy to parse format such as JSON.

maybe e.g.:

$ rslsync --status [foldername]
    "status": [
            "name": "folder1",
            "peer_count": 4,
            "sync_complete": false,
            "unsynced_files": 2,
            "file_count": 4124,
            "total_bytes": 104230636,
            "last_change": 1559231815
            "name": "folder2",
            "peer_count": 3,
            "sync_complete": true,
            "unsynced_files": 0,
            "file_count": 192,
            "total_bytes": 5263463,
            "last_change": 1559215804

(In the above example, last_change represents a timestamp in Unix epoch time)

I see there is (was?) an API but I am not sure if it's supported anymore and I checked the API docs and don't see any method there to query for sync status anyway.

This would be so useful... please

Link to comment
Share on other sites

  • 1 year later...

Coming back 1 year later to this idea 🙂

Today I again found that one of my folders was no longer syncing - it had a red Exclamation (!) mark and said Database error (link to KB article: https://helpfiles.resilio.com/dbaseerr)  I had to Disconnect, manually sync the folders on all peers using rsync, and then re-connect to clear this up.  RslSync version was 2.7.1 on all peers.

Apparently the sync had been broken for >1 week and I was not aware of it.

Some sort of API / alerts / commandline method to query status would have really helped here!  Is there any chance this could be coming in the future?


Link to comment
Share on other sites

a little more... 

After reading this page again, it seems like maybe there is an API but it is quite hidden and difficult to enable(?). Looks like possibly if the `api_key` value is configured in sync.conf then the API might be enabled. But, there is no sync.conf anymore, just bencoded settings.dat which is protected with salted hash. At this page, there is a link to Python2 script btsync_edit_settings_w4.py which can decode the encrypted settings.dat file—but how can this be turned back into a valid settings.dat?

Reading this page it looks like it may be possible to run Sync in configuration mode by placing a copy of sync.conf in the Storage Folder(?). But again, how to take a configured settings.dat and convert to plaintext sync.conf format?

I am not sure if this is the right path to take to enable the API?
Please Help @RomanZ
 or @Helen ! 🙂

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 year later...

Perhaps my respons is a bit late, but I agree it would have been nice if Resilio Sync had a status options. But... it is possible to get the overall sync status. 

In .config/resilio-sync/storage/ there's a file called 'sync.log', where among a lot of noise the sync status is kept. I say noise, because I have no interest is 99% of the file. 

With the following ugly command (I'm normally no fan of "grep|awk|tail|awk", but hey, it works) I get the latest status, to see if syncing is done and to decide if I can shutdown my raspbery pi dashcam 😎

grep -Pzo '.*'"`date --date="-2 min" "+%Y%m%d %H:%M"`"'(.*\n)*' /home/pi/.config/resilio-sync/storage/sync.log | awk '/ScheduledTask/&&!/ConnectMorePeers/&&!/ExpireFailedDownloads/'|  tail -n 1 |awk -F ":" '/UpdatePeersStat/{print $NF}'

My script runs every 2 minutes, so I'm only interested in status changes within the last 2 minutes. If the output is "FinishStateSync", syncing is finished. Anything else means it is still not 100% done. 


I hope this helps, even after all this time :)

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.