. . .nr rst2man-indent-level 0 . \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .rstReportMargin pre:
. RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .rstReportMargin post:
.. . RE indent \\n[an-margin]
old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1 new: \\n[rst2man-indent\\n[rst2man-indent-level]]
..
1 Hour For the first hour, the oldest version in every 30-seconds interval is kept.
1 Day For the first day, the oldest version in every hour is kept.
30 Days For the first 30 days, the oldest version in every day is kept.
Until Maximum Age Until maximum age, the oldest version in every week is kept.
Maximum Age The maximum time to keep a version in days. For example, to keep replaced or deleted files in the “.stversions” folder for an entire year, use 365. If only for 10 days, use 10. Note: Set to 0 to keep versions forever. NINDENT This means that there is only one version in each interval and as files age they will be deleted unless when the interval they are entering is empty. By keeping the oldest versions this versioning scheme preserves the file if it is overwritten. For more info, check the \%unit test file <https://github.com/syncthing/syncthing/blob/main/lib/versioner/staggered_test.go#L32> that shows which versions are deleted for a specific run.
%FOLDER_PATH% Path to the folder
%FILE_PATH% Path to the file within the folder NINDENT Note that the former expands to the path of the actual Syncthing folder, and the latter to the path inside that folder. For instance, if you use the default Sync folder in Windows, and the full path to the file is C:\eUsers\eUser\eSync\eFamily photos\eIMG_2021-03-01.jpg, then the %FOLDER_PATH% will be C:\eUsers\eUser\eSync, and the %FILE_PATH% will be Family photos\eIMG_2021-03-01.jpg.
#!/bin/sh set -eu # Where I want my versions stored versionspath=~/.trashcan # 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"NINDENT NINDENT I must ensure that the script has execute permissions (chmod 755 onlylatest.sh), then configure Syncthing with command /Users/jb/bin/onlylatest.sh %FOLDER_PATH% %FILE_PATH% Let’s assume I have a folder “default” in ~/Sync, and that within that folder there is a file docs/letter.txt that is being replaced or deleted. The script will be called as if I ran this from the command line: NDENT 0.0 NDENT 3.5
$ /Users/jb/bin/onlylatest.sh /Users/jb/Sync docs/letter.txtNINDENT NINDENT The script will then move the file in question to ~/.trashcan/docs/letter.txt, replacing any previous version of that letter that may already have been there.
@echo off rem Enable UTF-8 encoding to deal with multilingual folder and file names chcp 65001 rem We need command extensions for md to create intermediate folders in one go setlocal EnableExtensions rem Where I want my versions stored set "VERSIONS_PATH=%USERPROFILE%\e.trashcan" rem The parameters we get from Syncthing, \(aq~\(aq removes quotes if any set "FOLDER_PATH=%~1" set "FILE_PATH=%~2" rem First ensure the dir where we need to store the file exists for %%F in ("%VERSIONS_PATH%\e%FILE_PATH%") do set "OUTPUT_PATH=%%~dpF" if not exist "%OUTPUT_PATH%" md "%OUTPUT_PATH%" || exit /B rem Finally move the file, overwrite existing file if any move /Y "%FOLDER_PATH%\e%FILE_PATH%" "%VERSIONS_PATH%\e%FILE_PATH%"NINDENT NINDENT Finally, I set "C:\eUsers\emfrnd\eScripts\eonlylatest.bat" "%FOLDER_PATH%" "%FILE_PATH%" as the command name in Syncthing.
# PowerShell has no native method to recycle files, so we use Visual # Basic to perform the operation. If succeeded, we also include the # recycled file in the Syncthing\(aqs DEBUG output. Add-Type -AssemblyName Microsoft.VisualBasic [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqSendToRecycleBin\(aq) if ($?) { Write-Output ("Recycled " + $args + ".") }NINDENT NINDENT Alternatively, the script can be expanded to send only deleted files to the Recycle Bin, and permanently delete modified ones, which makes it more consistent with how the Explorer works. NDENT 0.0 NDENT 3.5
# PowerShell has no native method to recycle files, so we use Visual # Basic to perform the operation. Add-Type -AssemblyName Microsoft.VisualBasic # We need to test if a Syncthing .tmp file exists. If it does, we assume # a modification and delete the existing file. If if does not, we assume # a deletion and recycle the current file. If succeeded, we also include # the deleted/recycled file in the Syncthing\(aqs DEBUG output. if (Test-Path -LiteralPath ((Split-Path -Path $args) + "\e~syncthing~" + (Split-Path -Path $args -Leaf) + ".tmp")) { [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqDeletePermanently\(aq) if ($?) { Write-Output ("Deleted " + $args + ".") } } else { [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aqOnlyErrorDialogs\(aq,\(aqSendToRecycleBin\(aq) if ($?) { Write-Output ("Recycled " + $args + ".") } }NINDENT NINDENT Finally, we set the command name in Syncthing to powershell.exe -ExecutionPolicy Bypass -File "C:\eUsers\eUser\eScripts\eSendToRecycleBin.ps1" "%FOLDER_PATH%\e%FILE_PATH%". The only caveat that you should be aware of is that if your Syncthing folder is located on a portable storage, such as a USB stick, or if you have the Recycle Bin disabled, then the script will end up deleting all files permanently.
.