How to enable "Revert Local Changes" to run automatically

I have a scenario with 3 servers, where servers A and B are configured as “Send & Receive” for the /homefiles folder, and on server C the /homefiles folder is set as “Receive Only.”

Suppose a person or an application modifies, deletes, or adds a folder or file in the /homefiles folder on server C. I would like this action to be reverted immediately, without needing to open the Syncthing GUI and click the “Revert Local Changes” button — essentially, an automatic “Revert Local Changes” action.

Is it possible to configure it this way?

This isn’t possible within Syncthing itself. You would to trigger the API to have this done somewhat automatically (see https://docs.syncthing.net/dev/rest).

And you can script this to run at intervals.

Using the APIs:

curl -k -X POST -H “X-API-Key: ${API_KEY}” “https://127.0.0.1:8384/rest/db/scan?folder=${FOLDER_ID}”

curl -k -X POST -H “X-API-Key: ${API_KEY}” “https://127.0.0.1:8384/rest/db/revert?folder=${FOLDER_ID}”

I was successful in reverting changes, deletions, or creations in the ROOT folder (/var/www/html), but if the change is made in subfolders within the root folder (/var/www/html/teste/testefolder), even forcing a scan does not revert the changes.

Even when running it through the GUI, it’s not reverting.

Here’s a suggestion: We use SyncThing to synchronize folders and files of front-end web applications on clustered servers, as well as back-end servers. We have difficulties reverting changes.

  • Segue um script:
vi /usr/local/bin/syncthing-SPA-teste-autorevert.sh

#!/bin/bash

WATCHDIR="/var/www/html"
API_KEY="JrF2UmGYeDA34rspAwcDHM2vvTPnNnbE"
FOLDER_ID="SPA-teste"

inotifywait -m -r -e create -e delete -e modify --format '%w%f %e' "$WATCHDIR" |
while read FILE EVENT; do
  sleep 5
  curl -k -X POST -H "X-API-Key: ${API_KEY}" \
    "https://127.0.0.1:8384/rest/db/scan?folder=${FOLDER_ID}" >/dev/null 2>&1
  curl -k -X POST -H "X-API-Key: ${API_KEY}" \
    "https://127.0.0.1:8384/rest/db/revert?folder=${FOLDER_ID}" >/dev/null 2>&1
  echo "$(date ‘+%F %T’) Detectado: $EVENT em $FILE"
done
  • Service for automated execution:
vi /etc/systemd/system/syncthing-SPA-teste-autorevert.service

[Unit]
Description=Syncthing Auto Revert for Receive-Only Folder
After=network.target syncthing.service
Wants=syncthing.service

[Service]
Type=simple
ExecStart=/usr/local/bin/syncthing-SPA-teste-autorevert.sh
Restart=always
RestartSec=3
User=root

[Install]
WantedBy=multi-user.target

  • To activate and run the service:
systemctl daemon-reload
systemctl enable syncthing-SPA-teste-autorevert.service
systemctl restart syncthing-SPA-teste-autorevert.service
watch systemctl status syncthing-SPA-teste-autorevert.service

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