Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Syncthing git backup recipe

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.

set -eu

# Where I want my versions stored

# The parameters we get from Syncthing

# 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment