2020-06-22 04:15:24 +00:00
. \" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\ $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]
. .
.de1 INDENT
. \" .rstReportMargin pre:
. RS \\ $1
. nr rst2man-indent\\n[rst2man-indent-level] \\ n[an-margin]
. nr rst2man-indent-level +1
. \" .rstReportMargin post:
. .
.de UNINDENT
. 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]]
.in \\ n[rst2man-indent\\n[rst2man-indent-level]]u
. .
2024-09-09 03:45:15 +00:00
.TH "SYNCTHING-VERSIONING" "7" "Sep 04, 2024" "v1.27.11" "Syncthing"
2021-04-28 05:45:43 +00:00
.SH NAME
syncthing-versioning \- Keep automatic backups of deleted files by other nodes
2020-06-22 04:15:24 +00:00
.sp
Syncthing supports archiving the old version of a file when it is deleted or
replaced with a newer version from the cluster. This is called “file
versioning” and uses one of the available \fI versioning strategies\fP described
below. File versioning is configured per folder, on a per\- device basis, and
defaults to “no file versioning”, i.e. no old copies of files are kept.
.sp
\fB NOTE:\fP
.INDENT 0 .0
.INDENT 3 .5
Versioning applies to changes received \fI from other devices\fP \& . That is, if
Alice has versioning turned on and Bob changes a file, the old version
will be archived on Alice’ s computer when that change is synced from
Bob. If Alice changes a file locally on her own computer Syncthing will
not and can not archive the old version.
.UNINDENT
.UNINDENT
2023-08-14 03:45:48 +00:00
.sp
The applicable configuration options for each versioning strategy are described
below. For most of them it’ s possible to specify where the versions are stored,
with the default being the \fB \& .stversions\fP folder inside the shared folder path.
If you set a custom version path, please ensure that it’ s on the same partition
or filesystem as the regular folder path, as moving files there may otherwise
fail.
2020-06-22 04:15:24 +00:00
.SH TRASH CAN FILE VERSIONING
.sp
This versioning strategy emulates the common “trash can” approach. When a file
2021-02-17 06:45:43 +00:00
is deleted or replaced due to a change on a remote device, it is moved to
2020-06-22 04:15:24 +00:00
the trash can in the \fB \& .stversions\fP folder. If a file with the same name was
already in the trash can it is replaced.
.sp
2023-08-14 03:45:48 +00:00
A \fI \% configuration option\fP is
available to clean the trash can from files older than a specified number of
days. If this is set to a positive number of days, files will be removed when
they have been in the trash can that long. Setting this to zero prevents any
files from being removed from the trash can automatically.
2020-06-22 04:15:24 +00:00
.SH SIMPLE FILE VERSIONING
.sp
2023-08-14 03:45:48 +00:00
With “Simple File Versioning” files are moved to the \fB \& .stversions\fP folder when
replaced or deleted on a remote device. In addition to the
\fI \% cleanoutDays\fP option, this strategy also takes a
value in an input titled “Keep Versions” which tells Syncthing how many old
versions of the file it should \fI \% keep\fP \& . For
example, if you set this value to 5, if a file is replaced 5 times on a remote
device, you will see 5 time\- stamped versions on that file in the \fB \& .stversions\fP
folder on the other devices sharing the same folder.
2020-06-22 04:15:24 +00:00
.SH STAGGERED FILE VERSIONING
.sp
2023-08-14 03:45:48 +00:00
With “Staggered File Versioning” files are also moved to the \fB \& .stversions\fP
folder when replaced or deleted on a remote device (just like “Simple File
Versioning”), however, versions are automatically deleted if they are older than
the maximum age or exceed the number of files allowed in an interval.
2020-06-22 04:15:24 +00:00
.sp
The following intervals are used and they each have a maximum number of files
that will be kept for each.
.INDENT 0 .0
.TP
.B 1 Hour
2021-05-19 05:45:35 +00:00
For the first hour, the oldest version in every 30\- seconds interval is
kept.
2020-06-22 04:15:24 +00:00
.TP
.B 1 Day
2021-05-19 05:45:35 +00:00
For the first day, the oldest version in every hour is kept.
2020-06-22 04:15:24 +00:00
.TP
.B 30 Days
2021-05-19 05:45:35 +00:00
For the first 30 days, the oldest version in every day is kept.
2020-06-22 04:15:24 +00:00
.TP
.B Until Maximum Age
2021-05-19 05:45:35 +00:00
Until maximum age, the oldest version in every week is kept.
2020-06-22 04:15:24 +00:00
.TP
.B Maximum Age
The maximum time to keep a version in days. For example, to keep replaced or
2023-08-14 03:45:48 +00:00
deleted files in the \fB \& .stversions\fP folder for an entire year, use 365. If
only for 10 days, use 10. Corresponds to the
\fI \% maxAge\fP option.
2020-06-22 04:15:24 +00:00
\fB Note: Set to 0 to keep versions forever.\fP
.UNINDENT
2021-05-19 05:45:35 +00:00
.sp
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.
.sp
2024-05-13 03:45:18 +00:00
For more info, check the \X 'tty: link https://github.com/syncthing/syncthing/blob/main/lib/versioner/staggered_test.go#L32'\fI \% unit test file\fP <\fB https://github.com/syncthing/syncthing/blob/main/lib/versioner/staggered_test.go#L32\fP >\X 'tty: link'
2021-05-19 05:45:35 +00:00
that shows which versions are deleted for a specific run.
2020-06-22 04:15:24 +00:00
.SH EXTERNAL FILE VERSIONING
.sp
2023-08-14 03:45:48 +00:00
This versioning strategy delegates the decision on what to do to an
\fI \% external command\fP (e.g. a program or a
command line script). Just prior to a file being replaced, the command will be
executed. The file needs to be removed from the folder in the process, or
otherwise Syncthing will report an error. The command can use the following
templated arguments:
2020-06-22 04:15:24 +00:00
.INDENT 0 .0
.TP
.B %FOLDER_PATH%
Path to the folder
.TP
.B %FILE_PATH%
Path to the file within the folder
.UNINDENT
2021-03-10 06:45:45 +00:00
.sp
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 \fB Sync\fP folder in Windows, and the full path to the file is
\fB C:\e Users\e User\e Sync\e Family photos\e IMG_2021\- 03\- 01.jpg\fP , then the
\fB %FOLDER_PATH%\fP will be \fB C:\e Users\e User\e Sync\fP , and the
\fB %FILE_PATH%\fP will be \fB Family photos\e IMG_2021\- 03\- 01.jpg\fP \& .
2020-06-22 04:15:24 +00:00
.SS Example for Unixes
.sp
2021-03-10 06:45:45 +00:00
Let’ s say I want to keep the latest version of each file as they are replaced
2020-06-22 04:15:24 +00:00
or removed; essentially I want a “trash can”\- like behavior. For this, I create
the following script and store it as \fB /Users/jb/bin/onlylatest.sh\fP (i.e. the
\fB bin\fP directory in my home directory):
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2020-06-22 04:15:24 +00:00
#!/bin/sh
set \- eu
# Where I want my versions stored
versionspath=~/.trashcan
# The parameters we get from Syncthing
2023-09-18 03:45:31 +00:00
folderpath=\(dq $1\(dq
filepath=\(dq $2\(dq
2020-06-22 04:15:24 +00:00
# First ensure the dir where we need to store the file exists
2023-09-18 03:45:31 +00:00
outpath=$(dirname \(dq $versionspath/$filepath\(dq )
mkdir \- p \(dq $outpath\(dq
2020-06-22 04:15:24 +00:00
# Then move the file there
2023-09-18 03:45:31 +00:00
mv \- f \(dq $folderpath/$filepath\(dq \(dq $versionspath/$filepath\(dq
2024-05-13 03:45:18 +00:00
.EE
2020-06-22 04:15:24 +00:00
.UNINDENT
.UNINDENT
.sp
I must ensure that the script has execute permissions (\fB chmod 755
onlylatest.sh\fP ), then configure Syncthing with command \fB /Users/jb/bin/onlylatest.sh %FOLDER_PATH% %FILE_PATH%\fP
.sp
2021-03-10 06:45:45 +00:00
Let’ s assume I have a folder “default” in ~/Sync, and that within that folder
2020-06-22 04:15:24 +00:00
there is a file \fB docs/letter.txt\fP that is being replaced or deleted. The
script will be called as if I ran this from the command line:
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2020-06-22 04:15:24 +00:00
$ /Users/jb/bin/onlylatest.sh /Users/jb/Sync docs/letter.txt
2024-05-13 03:45:18 +00:00
.EE
2020-06-22 04:15:24 +00:00
.UNINDENT
.UNINDENT
.sp
The script will then move the file in question to
\fB ~/.trashcan/docs/letter.txt\fP , replacing any previous version of that letter
that may already have been there.
2021-03-17 06:45:40 +00:00
.SS Examples for Windows
.SS Move to a given folder using the command prompt (CMD)
2020-06-22 04:15:24 +00:00
.sp
On Windows we can use a batch script to perform the same “trash can”\- like
behavior as mentioned above. I created the following script and saved it as
\fB C:\e Users\e mfrnd\e Scripts\e onlylatest.bat\fP \& .
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2020-06-22 04:15:24 +00:00
@echo off
2021-02-17 06:45:43 +00:00
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
2022-01-24 03:45:54 +00:00
setlocal enableextensions
2020-06-22 04:15:24 +00:00
2021-02-17 06:45:43 +00:00
rem Where I want my versions stored
2023-09-18 03:45:31 +00:00
set \(dq versions_path=%USERPROFILE%\e .trashcan\(dq
2020-06-22 04:15:24 +00:00
2021-02-17 06:45:43 +00:00
rem The parameters we get from Syncthing, \(aq ~\(aq removes quotes if any
2023-09-18 03:45:31 +00:00
set \(dq folder_path=%~1\(dq
set \(dq file_path=%~2\(dq
2020-06-22 04:15:24 +00:00
2021-02-17 06:45:43 +00:00
rem First ensure the dir where we need to store the file exists
2023-09-18 03:45:31 +00:00
for %%f in (\(dq %versions_path%\e %file_path%\(dq ) do set \(dq output_path=%%~dpf\(dq
if not exist \(dq %output_path%\(dq md \(dq %output_path%\(dq || exit /b
2020-06-22 04:15:24 +00:00
2021-02-17 06:45:43 +00:00
rem Finally move the file, overwrite existing file if any
2023-09-18 03:45:31 +00:00
move /y \(dq %folder_path%\e %file_path%\(dq \(dq %versions_path%\e %file_path%\(dq
2024-05-13 03:45:18 +00:00
.EE
2020-06-22 04:15:24 +00:00
.UNINDENT
.UNINDENT
.sp
2023-09-18 03:45:31 +00:00
Finally, I set \fB \(dq C:\e Users\e mfrnd\e Scripts\e onlylatest.bat\(dq \(dq %FOLDER_PATH%\(dq
\(dq %FILE_PATH%\(dq \fP as the command name in Syncthing.
2021-03-17 06:45:40 +00:00
.SS Move to the Recycle Bin using PowerShell
.sp
We can use PowerShell to send files directly to the Recycle Bin, which
mimics the behaviour of deleting them using the Windows Explorer.
Firstly, create the following script and save it in your preferred
location, e.g. \fB C:\e Users\e User\e Scripts\e SendToRecycleBin.ps1\fP \& .
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2021-03-17 06:45:40 +00:00
# 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\(aq s DEBUG output.
Add\- Type \- AssemblyName Microsoft.VisualBasic
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aq OnlyErrorDialogs\(aq ,\(aq SendToRecycleBin\(aq )
if ($?) {
2023-09-18 03:45:31 +00:00
Write\- Output (\(dq Recycled \(dq + $args + \(dq .\(dq )
2021-03-17 06:45:40 +00:00
}
2024-05-13 03:45:18 +00:00
.EE
2021-03-17 06:45:40 +00:00
.UNINDENT
.UNINDENT
.sp
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.
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2021-03-17 06:45:40 +00:00
# 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\(aq s DEBUG output.
2023-09-18 03:45:31 +00:00
if (Test\- Path \- LiteralPath ((Split\- Path \- Path $args) + \(dq \e ~syncthing~\(dq + (Split\- Path \- Path $args \- Leaf) + \(dq .tmp\(dq )) {
2021-03-17 06:45:40 +00:00
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aq OnlyErrorDialogs\(aq ,\(aq DeletePermanently\(aq )
if ($?) {
2023-09-18 03:45:31 +00:00
Write\- Output (\(dq Deleted \(dq + $args + \(dq .\(dq )
2021-03-17 06:45:40 +00:00
}
} else {
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile($args,\(aq OnlyErrorDialogs\(aq ,\(aq SendToRecycleBin\(aq )
if ($?) {
2023-09-18 03:45:31 +00:00
Write\- Output (\(dq Recycled \(dq + $args + \(dq .\(dq )
2021-03-17 06:45:40 +00:00
}
}
2024-05-13 03:45:18 +00:00
.EE
2021-03-17 06:45:40 +00:00
.UNINDENT
.UNINDENT
.sp
Finally, we set the command name in Syncthing to \fB powershell.exe
2023-09-18 03:45:31 +00:00
\- ExecutionPolicy Bypass \- File \(dq C:\e Users\e User\e Scripts\e SendToRecycleBin.ps1\(dq
\(dq %FOLDER_PATH%\e %FILE_PATH%\(dq \fP \& .
2021-03-17 06:45:40 +00:00
.sp
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.
2023-08-14 03:45:48 +00:00
.SH CONFIGURATION PARAMETER REFERENCE
.sp
The versioning settings are grouped into their own section of each folder in the
2024-07-22 03:45:28 +00:00
\fI \% configuration file\fP \& . The following shows an
2023-08-14 03:45:48 +00:00
example of such a section in the XML:
.INDENT 0 .0
.INDENT 3 .5
.sp
2024-05-13 03:45:18 +00:00
.EX
2023-09-18 03:45:31 +00:00
<folder id=\(dq ...\(dq >
<versioning type=\(dq simple\(dq >
2023-08-14 03:45:48 +00:00
<cleanupIntervalS>3600</cleanupIntervalS>
<fsPath></fsPath>
<fsType>basic</fsType>
2023-09-18 03:45:31 +00:00
<param key=\(dq cleanoutDays\(dq val=\(dq 0\(dq ></param>
<param key=\(dq keep\(dq val=\(dq 5\(dq ></param>
2023-08-14 03:45:48 +00:00
</versioning>
</folder>
2024-05-13 03:45:18 +00:00
.EE
2023-08-14 03:45:48 +00:00
.UNINDENT
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.type
Selects one of the versioning strategies: \fB trashcan\fP , \fB simple\fP ,
\fB staggered\fP , \fB external\fP or leave empty to disable versioning completely.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.fsPath
Overrides the path where old versions of files are stored and defaults to
\fB \& .stversions\fP if left empty. An absolute or relative path can be
specified. The latter is interpreted relative to the shared folder path, if
the \fI \% fsType\fP is configured as \fB basic\fP \& . Ignored
for the \fB external\fP versioning strategy.
.sp
This option used to be stored under the keys \fB fsPath\fP or \fB versionsPath\fP
in the \fI \% params\fP element.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.fsType
The internal file system implementation used to access this versions folder.
Only applies if \fI \% fsPath\fP is also set non\- empty,
2024-07-22 03:45:28 +00:00
otherwise the \fI \% filesystemType\fP from the folder element is used
2023-08-14 03:45:48 +00:00
instead. Refer to that option description for possible values. Ignored for
the \fB external\fP versioning strategy.
.sp
This option used to be stored under the key \fB fsType\fP in the
\fI \% params\fP element.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.cleanupIntervalS
The interval, in seconds, for running cleanup in the versions folder. Zero
to disable periodic cleaning. Limited to one year (31536000 seconds).
Ignored for the \fB external\fP versioning strategy.
.sp
This option used to be stored under the key \fB cleanInterval\fP in the
\fI \% params\fP element.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.params
Each versioning strategy can have configuration parameters specific to its
implementation under this element.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.params.cleanoutDays
The number of days to keep files in the versions folder. Zero means to keep
forever. Older elements encountered during cleanup are removed.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.params.keep
The number of old versions to keep, per file.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.params.maxAge
The maximum time to keep a version, in seconds. Zero means to keep forever.
.UNINDENT
.INDENT 0 .0
.TP
.B versioning.params.command
External command to execute for storing a file version about to be replaced
or deleted. If the path to the application contains spaces, it should be
quoted.
.UNINDENT
2020-06-22 04:15:24 +00:00
.SH AUTHOR
The Syncthing Authors
.SH COPYRIGHT
2014-2019, The Syncthing Authors
. \" Generated by docutils manpage writer.
.