Accidentally "rm -r ~/", can a running syncthing instance "export" its config file?

Title says all; I meant to rely on tab completion but missed the key and just ran rm -r on the root of my home folder. Syncthing is still running nicely, but once it stops I assume it will act like a new install since the config.xml is missing. So just wondering if syncthing can export the config.xml file or am I fubar?

If you can open the GUI, you can make an innocuous config change and it will be saved. However, keys, certificates and the database are still gone so it won’t be super useful. It might also crash due to the lack of database when you try…

If you know the API key, you can get the config in JSON format: GET /rest/system/config — Syncthing v1 documentation

This can then be posted into a new Syncthing instance at a later date, or converted to XML form.


I don’t want to risk trying making a config change and having syncthing crash. So I followed your instructions and read the docs but mistakenly ran “POST” instead of “GET”

curl -k -X POST -H “X-API-Key: api-key” https://ip:8384/rest/config

receiving “unexpected end of JSON input”

I assume that syncthing sanitates input and didn’t overwrite its config with my blank data and prevented something hairy…

Fixed the command, running

curl -k -X GET -H “X-API-Key: api-key” https://ip:8384/rest/config >> ~/config-export

which did the trick.

1 Like

What a nightmare couple of hours. But at least syncthing is OK thanks to @calmh’s guidance…

Another few things I noted after config re-pushing:

  • .pem files regenerated; giving syncthing new device ID. All other settings incl. API key remain intact
  • old syncthing device showed up as peer in new syncthing device list so I removed it
  • right out the box old syncthing will not be able to connect to any previously connected devices, they all remain as disconnected
  • on the other end, the other devices will refuse to connect (as they should) because the certificates do not match, showing an error about “connection refused/unexpected device id” under the old syncthing device. So I removed the old syncthing device everywhere.
  • all folders showing 0/0/0KB global state. Local state and locally changed items equal, being the size of the folder, and “revert changes” button which presumably will clear out the folder to 0KB to match the global state (don’t press this, let syncthing work its magic)
  • new syncthing will in a matter of time show up as wanting to connect on remote syncthing instances
  • after connection new syncthing will show up as wanting to share all previously shared folders

A few anxiety-filled hours of watching out of sync items gradually count down to zero, slowly. Everything is back to normal. Except two months of work in my home folder…

If anyone is interested here is what I did:

to export the config

curl -k -X GET -H “X-API-Key: api-key” https://ip:8384/rest/config >> ~/config-export.json

to push the config to syncthing

curl -k -s -H X-API-Key:api-key -X POST --data-binary @config-export.json https://ip:8384/rest/config

note: mkdir -p ~/.config/syncthing if it doesn’t already otherwise syncthing will complain about missing folders

to restart syncthing

curl -k -H X-API-Key:api-key -X POST https://ip:8384/rest/system/restart

Lessons learned:

  1. Have backups in the future
  2. Don’t delete everything in your home folder
  3. Syncthing is very powerful… I may lose sleep over data loss but I’ll never lose sleep over syncthing…


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