How to save keepass database's copy whenever syncthing notices it is changed

I am using Syncthing for syncing my keepass database between my pc and android. A lot of time I edit file on both devices when syncthing is not connected (I use sync only when USB tethering). This lead to a sync conflict. Last edited database get synced and earlier when gets corrupted.

To prevent this I want syncthing to automatically copy a version of database when it notices it is edited and then do whatever it wants. So that I can recover data from earliar version.

I thought versioning will serve similar function but it only save a copy when it is deleted or created there (I am using simple versioning).

So how to configure Syncthing to serve my purpose.

Thanks in advance.

I don’t think you can solve this problem without having the devices connected all the time.

You can disable conflicts altogether by setting to 0, which will make Syncthing always use the last edited version of the file, but this way you will also lose all changes done on the other device.

Given the unusual workflow, if the goal is to end up with a single KeePass database file, have you considered using the mass storage mode when USB tethering?

Then use the import/export option – or database merge, if available – to combine edits made on the PC and Android devices.

Yeah, so just as an FYI, I also sync my KeePass databases across lots of devices and it does happen to me as well that I get a conflict, because some device wasn’t up to date at some point.

When that happens, it’s no biggie though: KeePass has an inbuild database synchronization mechanism (File → Synchronize → Synchronize with file, then select the sync-conflict file) that gets both versions merged - there’s no “corruption” or anything like that, and you won’t loose any changes to your DBs. Afterwards you can simply delete the sync-conflict. So there’s no need for any complicated logic here, just let KeePass do the magic.