syncthing restore .stversions scripts

I just had a sync issue (missing folder) and when i create it back and touch an new .stfolder, syncthing choose to delete all data in other synced device and not to copy them to the eroneous one.

That sayed, thanks to simple versioning, i get everything back with this home made script (i dont found the other in the forum before).

Here is mine (you need nodejs and fs-extra dependancy to use it) :

const fse = require('/usr/lib/node_modules/fs-extra');
async function main(folder){
	let fileList = await fse.readdir(folder);
		let actualFile = folder+'/'+fileList.pop();
		if(fse.lstatSync(actualFile).isDirectory()) main(actualFile);
		let dated = actualFile.match(/^(.*)~[0-9]{8}-[0-9]{6}(.*)$/);
			const cannonical = dated[1]+dated[2];
			if(await fse.exists(cannonical)) await fse.remove(actualFile);
			else await fse.move(actualFile, cannonical);

after you copy back your .stversions in your synced folder, if you run my script in your sync folder it will rename and remove old copy to only keep the latest for each file, recursively for all subdirectory.

and i found (but not tested) other similar script when time to share my work have come :

Have a good restore time.


Just to clarify for any other viewers, what happened here was that you recreated a missing, and created the .stfolder marker, thus telling Syncthing that the folder is fine and is now intentionally empty. It knows you had a bunch of files in it before, and they are no longer there, so you must have deleted them.

1 Like

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