# syncthing restore .stversions scripts

**URL:** https://forum.syncthing.net/t/syncthing-restore-stversions-scripts/10188
**Category:** Support
**Created:** [July 18, 2017, 11:09pm UTC](https://forum.syncthing.net/t/syncthing-restore-stversions-scripts/10188 "2017-07-18T23:09:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![1000i100](https://forum.syncthing.net/user_avatar/forum.syncthing.net/1000i100/32/3832_2.png) [@1000i100](https://forum.syncthing.net/u/1000i100)
#### Post date: [July 18, 2017, 11:09pm UTC](https://forum.syncthing.net/t/syncthing-restore-stversions-scripts/10188/1 "2017-07-18T23:09:02Z")

</div>

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) :

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

```

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 :

- one is here : [Syncthing deleted 67000 files, how do I restore?](https://forum.syncthing.net/t/syncthing-deleted-67000-files-how-do-i-restore/9896/2)
- An other one here : forum syncthing net /t/script-for-restore-version-files/1842

Have a good restore time.

---

<div class="post-metadata">

### Author: ![calmh](https://forum.syncthing.net/user_avatar/forum.syncthing.net/calmh/32/15311_2.png) [@calmh](https://forum.syncthing.net/u/calmh)
#### Post date: [July 19, 2017, 7:41am UTC](https://forum.syncthing.net/t/syncthing-restore-stversions-scripts/10188/2 "2017-07-19T07:41:08Z")

</div>

> [@1000i100](#):
>
> 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.

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.

---

<div class="post-metadata">

### Author: ![system](https://forum-uploads.syncthingcdn.net/original/2X/0/0b50e0a202b22ae6a67190759e8c868805b8ed9f.png) [@system](https://forum.syncthing.net/u/system)
#### Post date: [August 18, 2017, 7:47am UTC](https://forum.syncthing.net/t/syncthing-restore-stversions-scripts/10188/3 "2017-08-18T07:47:09Z")

</div>

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