Syncthing has awesome docs - start there if you haven't read them already. This is just a recipe to show how I set it up to have a git-versioned backup on Raspberry Pi.
Once machines are talking to each other via Syncthing add the folder through GUI, share it with another device, switch to that device and accept the incoming folder.
Let's say that the folder is ~/org
.
On the 'backup' device in Syncthing GUI, go to Folder settings > File Versioning, choose "External File Versioning" and in Command input fill in: git-backup-org %FOLDER_PATH% %FILE_PATH%
.
On the 'backup' device create the backup folder and initialize a git repository:
mkdir ~/org-backup
cd ~/org-backup
git init
Create a git-backup-org
file somewhere in your path and make it executable (chmod +x git-backup-org
).
This is a slightly extended version of the script from External File Versioning.
#!/bin/sh
set -eu
# Where I want my versions stored
versionspath=~/org-backup
# The parameters we get from Syncthing
folderpath="$1"
filepath="$2"
# First ensure the dir where we need to store the file exists
outpath=`dirname "$versionspath/$filepath"`
mkdir -p "$outpath"
# Then move the file there
mv -f "$folderpath/$filepath" "$versionspath/$filepath"
cd "$versionspath"
git add .
git commit -m "`date +'%Y-%m-%d %H:%M:%S'` - $filepath"
And that's it!